/// /// // Type definitions for Phaser CE // Project: https://github.com/photonstorm/phaser-ce interface MediaTrackConstraints {} declare module "phaser-ce" { export = Phaser; } declare class Phaser { static VERSION: string; static DEV_VERSION: string; static GAMES: Phaser.Game[]; static AUTO: number; static CANVAS: number; static WEBGL: number; static HEADLESS: number; static WEBGL_MULTI: number; static BITMAPDATA: number; static BITMAPTEXT: number; static BUTTON: number; static CANVAS_FILTER: number; static CIRCLE: number; static ELLIPSE: number; static EMITTER: number; static GRAPHICS: number; static GROUP: number; static IMAGE: number; static LINE: number; static MATRIX: number; static POINT: number; static POINTER: number; static POLYGON: number; static RECTANGLE: number; static ROUNDEDRECTANGLE: number; static RENDERTEXTURE: number; static RETROFONT: number; static SPRITE: number; static SPRITEBATCH: number; static TEXT: number; static TILEMAP: number; static TILEMAPLAYER: number; static TILESPRITE: number; static WEBGL_FILTER: number; static ROPE: number; static CREATURE: number; static VIDEO: number; static NONE: number; static LEFT: number; static RIGHT: number; static UP: number; static DOWN: number; static HORIZONTAL: number; static VERTICAL: number; static LANDSCAPE: number; static PORTRAIT: number; static ANGLE_UP: number; static ANGLE_DOWN: number; static ANGLE_LEFT: number; static ANGLE_RIGHT: number; static ANGLE_NORTH_EAST: number; static ANGLE_NORTH_WEST: number; static ANGLE_SOUTH_EAST: number; static ANGLE_SOUTH_WEST: number; static TOP_LEFT: number; static TOP_CENTER: number; static TOP_RIGHT: number; static LEFT_TOP: number; static LEFT_CENTER: number; static LEFT_BOTTOM: number; static CENTER: number; static RIGHT_TOP: number; static RIGHT_CENTER: number; static RIGHT_BOTTOM: number; static BOTTOM_LEFT: number; static BOTTOM_CENTER: number; static BOTTOM_RIGHT: number; static EmptyRectangle: Phaser.Rectangle; } declare module Phaser { enum blendModes { NORMAL, ADD, MULTIPLY, SCREEN, OVERLAY, DARKEN, LIGHTEN, COLOR_DODGE, COLOR_BURN, HARD_LIGHT, SOFT_LIGHT, DIFFERENCE, EXCLUSION, HUE, SATURATION, COLOR, LUMINOSITY } export enum scaleModes { DEFAULT, LINEAR, NEAREST } /** * An Animation instance contains a single animation and the controls to play it. * * It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite. */ class Animation { /** * An Animation instance contains a single animation and the controls to play it. * * It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite. * * @param game A reference to the currently running game. * @param parent A reference to the owner of this Animation. * @param name The unique name for this animation, used in playback commands. * @param frameData The FrameData object that contains all frames used by this Animation. * @param frames An array of numbers or strings indicating which frames to play in which order. * @param frameRate The speed at which the animation should play. The speed is given in frames per second. - Default: 60 * @param loop Whether or not the animation is looped or just plays once. */ constructor(game: Phaser.Game, parent: Phaser.Sprite, name: string, frameData: Phaser.FrameData, frames: number[] | string[], frameRate?: number, loop?: boolean); /** * The currently displayed frame of the Animation. */ currentFrame: Phaser.Frame; /** * The delay in ms between each frame of the Animation, based on the given frameRate. */ delay: number; /** * Gets or sets if this animation will dispatch the onUpdate events upon changing frame. */ enableUpdate: boolean; /** * Gets or sets the current frame index and updates the Texture Cache for display. */ frame: number; /** * The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded. */ frameTotal: number; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The finished state of the Animation. Set to true once playback completes, false during playback. */ isFinished: boolean; /** * The paused state of the Animation. */ isPaused: boolean; /** * The playing state of the Animation. Set to false once playback completes, true during playback. */ isPlaying: boolean; /** * Should the parent of this Animation be killed when the animation completes? */ killOnComplete: boolean; /** * The loop state of the Animation. */ loop: boolean; /** * The number of times the animation has looped since it was last started. */ loopCount: number; /** * The user defined name given to this Animation. */ name: string; /** * This event is dispatched when this Animation completes playback. If the animation is set to loop this is never fired, listen for onLoop instead. */ onComplete: Phaser.Signal; /** * This event is dispatched when this Animation loops. */ onLoop: Phaser.Signal; /** * This event is dispatched when this Animation starts playback. */ onStart: Phaser.Signal; /** * This event is dispatched when the Animation changes frame. * By default this event is disabled due to its intensive nature. Enable it with: `Animation.enableUpdate = true`. * Note that the event is only dispatched with the current frame. In a low-FPS environment Animations * will automatically frame-skip to try and claw back time, so do not base your code on expecting to * receive a perfectly sequential set of frames from this event. */ onUpdate: Phaser.Signal; /** * Gets and sets the paused state of this Animation. */ paused: boolean; /** * Gets and sets the isReversed state of this Animation. */ reversed: boolean; /** * Gets or sets the current speed of the animation in frames per second. Changing this in a playing animation will take effect from the next frame. Value must be greater than 0. */ speed: number; /** * Called internally when the animation finishes playback. * Sets the isPlaying and isFinished states and dispatches the onAnimationComplete event if it exists on the parent and local onComplete event. */ complete(): void; /** * Cleans up this animation ready for deletion. Nulls all values and references. */ destroy(): void; /** * Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers. * For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large' * You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4); * * @param prefix The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'. * @param start The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the start is 1. * @param stop The number to count to. If your frames are named 'explosion_0001' to 'explosion_0034' the stop value is 34. * @param suffix The end of the filename. If the filename was 'explosion_0001-large' the suffix would be '-large'. - Default: '' * @param zeroPad The number of zeros to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4. * @return An array of framenames. */ static generateFrameNames(prefix: string, start: number, stop: number, suffix?: string, zeroPad?: number): string[]; /** * Advances by the given number of frames in the Animation, taking the loop value into consideration. * * @param quantity The number of frames to advance. - Default: 1 */ next(quantity?: number): void; /** * Called when the Game enters a paused state. */ onPause(): void; /** * Called when the Game resumes from a paused state. */ onResume(): void; /** * Plays this animation. * * If you need to jump to a specific frame of this animation, then call `play` and immediately after it, * set the frame you require (i.e. `animation.play(); animation.frame = 4`). * * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return - A reference to this Animation instance. */ play(frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Moves backwards the given number of frames in the Animation, taking the loop value into consideration. * * @param quantity The number of frames to move back. - Default: 1 */ previous(quantity?: number): void; /** * Sets this animation back to the first frame and restarts the animation. */ restart(): void; /** * Reverses the animation direction. * @return The animation instance. */ reverse(): Animation; /** * Reverses the animation direction for the current/next animation only * Once the onComplete event is called this method will be called again and revert * the reversed state. * @return The animation instance. */ reverseOnce(): Animation; /** * Sets this animations playback to a given frame with the given ID. * * @param frameId The identifier of the frame to set. Can be the name of the frame, the sprite index of the frame, or the animation-local frame index. * @param useLocalFrameIndex If you provide a number for frameId, should it use the numeric indexes of the frameData, or the 0-indexed frame index local to the animation. */ setFrame(frameId?: string | number, useLocalFrameIndex?: boolean): void; /** * Stops playback of this animation and set it to a finished state. If a resetFrame is provided it will stop playback and set frame to the first in the animation. * If `dispatchComplete` is true it will dispatch the complete events, otherwise they'll be ignored. * * @param resetFrame If true after the animation stops the currentFrame value will be set to the first frame in this animation. * @param dispatchComplete Dispatch the Animation.onComplete and parent.onAnimationComplete events? */ stop(resetFrame?: boolean, dispatchComplete?: boolean): void; /** * Updates this animation. Called automatically by the AnimationManager. */ update(): boolean; /** * Changes the currentFrame per the _frameIndex, updates the display state, * and triggers the update signal. * * Returns true if the current frame update was 'successful', false otherwise. * * @param signalUpdate If true the `Animation.onUpdate` signal will be dispatched. * @param fromPlay Was this call made from the playing of a new animation? * @return True if the current frame was updated, otherwise false. */ updateCurrentFrame(signalUpdate: boolean, fromPlay?: boolean): boolean; /** * Changes the FrameData object this Animation is using. * * @param frameData The FrameData object that contains all frames used by this Animation. */ updateFrameData(frameData: FrameData): void; } /** * The Animation Manager is used to add, play and update Phaser Animations. * Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance. */ class AnimationManager { /** * The Animation Manager is used to add, play and update Phaser Animations. * Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance. * * @param sprite A reference to the Game Object that owns this AnimationManager. */ constructor(sprite: Phaser.Sprite); /** * The currently displayed animation, if any. */ currentAnim: Phaser.Animation; /** * The currently displayed Frame of animation, if any. * This property is only set once an Animation starts playing. Until that point it remains set as `null`. */ currentFrame: Phaser.Frame; /** * Gets or sets the current frame index and updates the Texture Cache for display. */ frame: number; /** * The current animations FrameData. */ frameData: Phaser.FrameData; /** * Gets or sets the current frame name and updates the Texture Cache for display. */ frameName: string; /** * The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded. */ frameTotal: number; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Set to true once animation data has been loaded. */ isLoaded: boolean; /** * Gets the current animation name, if set. */ name: string; /** * Gets and sets the paused state of the current animation. */ paused: boolean; /** * A reference to the parent Sprite that owns this AnimationManager. */ sprite: Phaser.Sprite; /** * Update the animation data only while the the sprite is {@link Phaser.Sprite#visible}. Set to `false` to continue updating while the sprite is invisible. * Default: true */ updateIfVisible: boolean; /** * Adds a new animation under the given key. Optionally set the frames, frame rate and loop. * Animations added in this way are played back with the play function. * * @param name The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk". * @param frames An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used. * @param frameRate The speed at which the animation should play. The speed is given in frames per second. - Default: 60 * @param loop Whether or not the animation is looped or just plays once. * @param useNumericIndex Are the given frames using numeric indexes (default) or strings? - Default: true * @return The Animation object that was created. */ add(name: string, frames?: number[] | string[], frameRate?: number, loop?: boolean, useNumericIndex?: boolean): Phaser.Animation; /** * Loads FrameData into the internal temporary vars and resets the frame index to zero. * This is called automatically when a new Sprite is created. * * @param frameData The FrameData set to load. * @param frame The frame to default to. * @return Returns `true` if the frame data was loaded successfully, otherwise `false` */ copyFrameData(frameData: Phaser.FrameData, frame: string | number): boolean; /** * Destroys all references this AnimationManager contains. * Iterates through the list of animations stored in this manager and calls destroy on each of them. */ destroy(): void; /** * Returns an animation that was previously added by name. * * @param name The name of the animation to be returned, e.g. "fire". * @return The Animation instance, if found, otherwise null. */ getAnimation(name: string): Phaser.Animation; /** * Advances by the given number of frames in the current animation, taking the loop value into consideration. * * @param quantity The number of frames to advance. - Default: 1 */ next(quantity?: number): void; /** * Play an animation based on the given key. The animation should previously have been added via `animations.add` * * If the requested animation is already playing this request will be ignored. * If you need to reset an already running animation do so directly on the Animation object itself. * * If you need to jump to a specific frame of this animation, then call `play` and immediately after it, * set the frame you require (i.e. `animation.play(); animation.frame = 4`). * * @param name The name of the animation to be played, e.g. "fire", "walk", "jump". * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return A reference to playing Animation instance. */ play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Moves backwards the given number of frames in the current animation, taking the loop value into consideration. * * @param quantity The number of frames to move back. - Default: 1 */ previous(quantity?: number): void; /** * Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped. * The currentAnim property of the AnimationManager is automatically set to the animation given. * * @param name The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped. * @param resetFrame When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false) */ stop(name?: string, resetFrame?: boolean): void; /** * The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events. * @return True if a new animation frame has been set, otherwise false. */ update(): boolean; /** * Check whether the frames in the given array are valid and exist. * * @param frames An array of frames to be validated. * @param useNumericIndex Validate the frames based on their numeric index (true) or string index (false) - Default: true * @return True if all given Frames are valid, otherwise false. */ validateFrames(frames: Phaser.Frame[], useNumericIndex?: boolean): boolean; } /** * Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations. */ class AnimationParser { /** * Parse the JSON data and extract the animation frame data from it. * * @param game A reference to the currently running game. * @param json The JSON data from the Texture Atlas. Must be in Array format. * @return A FrameData object containing the parsed frames. */ static JSONData(game: Phaser.Game, json: any): Phaser.FrameData; /** * Parse the JSON data and extract the animation frame data from it. * * @param game A reference to the currently running game. * @param json The JSON data from the Texture Atlas. Must be in JSON Hash format. * @return A FrameData object containing the parsed frames. */ static JSONDataHash(game: Phaser.Game, json: any): Phaser.FrameData; /** * Parse the JSON data and extract the animation frame data from it. * * @param game A reference to the currently running game. * @param json The JSON data from the Texture Atlas. Must be in Pyxel JSON format. * @return A FrameData object containing the parsed frames. */ static JSONDataPyxel(game: Phaser.Game, json: any): Phaser.FrameData; /** * Parse a Sprite Sheet and extract the animation frame data from it. * * @param game A reference to the currently running game. * @param key The Game.Cache asset key of the Sprite Sheet image or an actual HTML Image element. * @param frameWidth The fixed width of each frame of the animation. * @param frameHeight The fixed height of each frame of the animation. * @param frameMax The total number of animation frames to extract from the Sprite Sheet. The default value of -1 means "extract all frames". - Default: -1 * @param margin If the frames have been drawn with a margin, specify the amount here. * @param spacing If the frames have been drawn with spacing between them, specify the amount here. * @param skipFrames Skip a number of frames. Useful when there are multiple sprite sheets in one image. * @return A FrameData object containing the parsed frames. */ static spriteSheet(game: Phaser.Game, key: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number, skipFrames?: number): Phaser.FrameData; /** * Parse the XML data and extract the animation frame data from it. * * @param game A reference to the currently running game. * @param xml The XML data from the Texture Atlas. Must be in Starling XML format. * @return A FrameData object containing the parsed frames. */ static XMLData(game: Phaser.Game, xml: any): Phaser.FrameData; } /** * 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 */ class AudioSprite { /** * 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 * * @param game Reference to the current game instance. * @param key Asset key for the sound. */ constructor(game: Phaser.Game, key: string); /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Asset key for the Audio Sprite. */ key: string; /** * JSON audio atlas object. */ config: any; /** * If a sound is set to auto play, this holds the marker key of it. */ autoplayKey: string; /** * Is a sound set to autoplay or not? */ autoplay: boolean; /** * An object containing the Phaser.Sound objects for the Audio Sprite. */ sounds: any; /** * Get a sound with the given name. * * @param marker The name of sound to get. * @return The sound instance. */ get(marker: string): Phaser.Sound; /** * Play a sound with the given name. * * @param marker The name of sound to play * @param volume Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified). - Default: 1 * @return This sound instance. */ play(marker: string, volume?: number): Phaser.Sound; /** * Stop a sound with the given name. * * @param marker The name of sound to stop. If none is given it will stop all sounds in the audio sprite. - Default: '' */ stop(marker: string): Phaser.Sound; } /** * ArraySet is a Set data structure (items must be unique within the set) that also maintains order. * This allows specific items to be easily added or removed from the Set. * * Item equality (and uniqueness) is determined by the behavior of `Array.indexOf`. * * This used primarily by the Input subsystem. */ class ArraySet { /** * ArraySet is a Set data structure (items must be unique within the set) that also maintains order. * This allows specific items to be easily added or removed from the Set. * * Item equality (and uniqueness) is determined by the behavior of `Array.indexOf`. * * This used primarily by the Input subsystem. * * @param list The backing array: if specified the items in the list _must_ be unique, per `Array.indexOf`, and the ownership of the array _should_ be relinquished to the ArraySet. - Default: (new array) */ constructor(list: any[]); /** * Current cursor position as established by `first` and `next`. */ position: number; /** * The backing array. */ list: any[]; /** * Number of items in the ArraySet. Same as `list.length`. */ total: number; /** * Returns the first item and resets the cursor to the start. */ first: any; /** * Returns the the next item (based on the cursor) and advances the cursor. */ next: any; /** * Adds a new element to the end of the list. * If the item already exists in the list it is not moved. * * @param item The element to add to this list. * @return The item that was added. */ add(item: any): any; /** * Gets an item from the set based on the property strictly equaling the value given. * Returns null if not found. * * @param property The property to check against the value. * @param value The value to check if the property strictly equals. * @return The item that was found, or null if nothing matched. */ getByKey(property: string, value: any): any; /** * Gets the index of the item in the list, or -1 if it isn't in the list. * * @param item The element to get the list index for. * @return The index of the item or -1 if not found. */ getIndex(item: any): number; /** * Checks for the item within this list. * * @param item The element to get the list index for. * @return True if the item is found in the list, otherwise false. */ exists(item: any): boolean; /** * Removes all the items. */ reset(): void; /** * Removes the given element from this list if it exists. * * @param item The item to be removed from the list. * @return item - The item that was removed. */ remove(item: any): any; /** * Removes every member from this ArraySet and optionally destroys it. * * @param destroy Call `destroy` on each member as it's removed from this set. */ removeAll(destoy?: boolean): void; /** * Sets the property `key` to the given value on all members of this list. * * @param key The property of the item to set. * @param value The value to set the property to. */ setAll(key: any, value: any): void; /** * Calls a function on all members of this list, using the member as the context for the callback. * * If the `key` property is present it must be a function. * The function is invoked using the item as the context. * * @param key The name of the property with the function to call. * @param args Additional parameters that will be passed to the callback. */ callAll(key: string, ...parameter: any[]): void; } /** * Utility functions for dealing with Arrays. */ class ArrayUtils { /** * Fetch a random entry from the given array. * * Will return null if there are no array items that fall within the specified range * or if there is no item for the randomly chosen index. * * @param objects An array of objects. * @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array. * @param length Optional restriction on the number of values you want to randomly select from. * @return The random object that was selected. */ static getRandomItem(objects: T[], startIndex?: number, length?: number): T; /** * Removes a random object from the given array and returns it. * * Will return null if there are no array items that fall within the specified range * or if there is no item for the randomly chosen index. * * @param objects An array of objects. * @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array. * @param length Optional restriction on the number of values you want to randomly select from. * @return The random object that was removed. */ static removeRandomItem(objects: T[], startIndex?: number, length?: number): T; /** * Remove one or more items at the given index and reorder the array. * * The new array length will be `array.length - count`. * * This is an alternative to `array.splice(startIndex, count)`. * * @param array * @param startIndex * @param count - Default: 1 * @return The modified array. */ static remove(array: T[], startIndex: number, count?: number): T; /** * A standard Fisher-Yates Array shuffle implementation which modifies the array in place. * * @param array The array to shuffle. * @return The original array, now shuffled. */ static shuffle(array: T[]): T[]; /** * Transposes the elements of the given matrix (array of arrays). * * @param array The matrix to transpose. * @return A new transposed matrix */ static transposeMatrix(array: T[]): T; /** * Rotates the given matrix (array of arrays). * * Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}. * * @param matrix The array to rotate; this matrix _may_ be altered. * @param direction The amount to rotate: the rotation in degrees (90, -90, 270, -270, 180) or a string command ('rotateLeft', 'rotateRight' or 'rotate180'). * @return The rotated matrix. The source matrix should be discarded for the returned matrix. */ static rotateMatrix(matrix: any, direction: number | string): any; /** * Snaps a value to the nearest value in a sorted numeric array. * The result will always be in the range `[first_value, last_value]`. * * @param value The search value * @param arr The input array which _must_ be sorted. * @return The nearest value found. */ static findClosest(value: number, arr: number[]): number; static rotate(array: any[]): any; /** * Moves the element from the start of the array to the end, shifting all items in the process. * The "rotation" happens to the left. * * Before: `[ A, B, C, D, E, F ]` * After: `[ B, C, D, E, F, A ]` * * See also Phaser.ArrayUtils.rotateRight * * @param array The array to rotate. The array is modified. * @return The rotated value. */ static rotateLeft(array: any[]): any; /** * Moves the element from the end of the array to the start, shifting all items in the process. * The "rotation" happens to the right. * * Before: `[ A, B, C, D, E, F ]` * After: `[ F, A, B, C, D, E ]` * * See also Phaser.ArrayUtils.rotateLeft. * * @param array The array to rotate. The array is modified. * @return The shifted value. */ static rotateRight(array: any[]): any; /** * Create an array representing the inclusive range of numbers (usually integers) in `[start, end]` (or `[0, start]`, if `end` is omitted). * This is equivalent to `numberArrayStep(start, 1 + end, 1)`. * * When exactly one argument is passed, it's used as `end` and 0 is used as `start`. The length of the result is (1 + end). * * ##### Examples * * ```javascript * numberArray(3); // -> [0, 1, 2, 3] * numberArray(0, 3); // -> [0, 1, 2, 3] * numberArray(1, 3); // -> [1, 2, 3] * ``` * * @param start The minimum value the array starts with. * @param end The maximum value the array contains. * @return The array of number values. */ static numberArray(start: number, end?: number): number[]; /** * Create an array of numbers (positive and/or negative) progressing from `start` * up to but not including `end` by advancing by `step`. * * If `start` is less than `end` a zero-length range is created unless a negative `step` is specified. * * Certain values for `start` and `end` (eg. NaN/undefined/null) are currently coerced to 0; * for forward compatibility make sure to pass in actual numbers. * * @param start The start of the range. * @param end The end of the range. * @param step The value to increment or decrement by. - Default: 1 * @return Returns the new array of numbers. */ static numberArrayStep(start: number, end?: number, step?: number): number[]; } interface BitmapFont { base: PIXI.BaseTexture; data: HTMLImageElement; font: Phaser.BMFont; url: string; } interface BMFont { chars: Phaser.BMFontChar[]; font: string; lineHeight: number; size: number; } interface BMFontChar { x: number; y: number; width: number; height: number; xOffset: number; yOffset: number; xAdvance: number; kerning: number[]; texture: PIXI.BaseTexture; } /** * A BitmapData object contains a Canvas element to which you can draw anything you like via normal Canvas context operations. * A single BitmapData can be used as the texture for one or many Images / Sprites. * So if you need to dynamically create a Sprite texture then they are a good choice. * * Important note: Every BitmapData creates its own Canvas element. Because BitmapData's are now Game Objects themselves, and don't * live on the display list, they are NOT automatically cleared when you change State. Therefore you _must_ call BitmapData.destroy * in your State's shutdown method if you wish to free-up the resources the BitmapData used, it will not happen for you. */ class BitmapData { /** * A BitmapData object contains a Canvas element to which you can draw anything you like via normal Canvas context operations. * A single BitmapData can be used as the texture for one or many Images / Sprites. * So if you need to dynamically create a Sprite texture then they are a good choice. * * Important note: Every BitmapData creates its own Canvas element. Because BitmapData's are now Game Objects themselves, and don't * live on the display list, they are NOT automatically cleared when you change State. Therefore you _must_ call BitmapData.destroy * in your State's shutdown method if you wish to free-up the resources the BitmapData used, it will not happen for you. * * @param game A reference to the currently running game. * @param key Internal Phaser reference key for the BitmapData. * @param width The width of the BitmapData in pixels. If undefined or zero it's set to a default value. - Default: 256 * @param height The height of the BitmapData in pixels. If undefined or zero it's set to a default value. - Default: 256 * @param skipPool When this BitmapData generates its internal canvas to use for rendering, it will get the canvas from the CanvasPool if false, or create its own if true. */ constructor(game: Phaser.Game, key: string, width?: number, height?: number, skipPool?: boolean); /** * The PIXI.BaseTexture. */ baseTexture: PIXI.BaseTexture; buffer: ArrayBuffer; /** * The canvas to which this BitmapData draws. */ canvas: HTMLCanvasElement; /** * The 2d context of the canvas. */ context: CanvasRenderingContext2D; /** * A reference to BitmapData.context. */ ctx: CanvasRenderingContext2D; /** * A Uint8ClampedArray view into BitmapData.buffer. * Note that this is unavailable in some browsers (such as Epic Browser due to its security restrictions) */ data: Uint8Array; /** * If dirty this BitmapData will be re-rendered. */ dirty: boolean; /** * If disableTextureUpload is true this BitmapData will never send its image data to the GPU when its dirty flag is true. */ disableTextureUpload: boolean; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The height of the BitmapData in pixels. */ height: number; /** * The context image data. * Please note that a call to BitmapData.draw() or BitmapData.copy() does not update immediately this property for performance reason. Use BitmapData.update() to do so. * This property is updated automatically after the first game loop, according to the dirty flag property. */ imageData: ImageData; /** * The key of the BitmapData in the Cache, if stored there. */ key: string; /** * A short-hand code to get or set the global composite operation of the BitmapDatas canvas. */ op: string; /** * An Uint32Array view into BitmapData.buffer. */ pixels: Uint32Array; /** * Gets or sets this BitmapData.contexts smoothing enabled value. */ smoothed: boolean; /** * The context property needed for smoothing this Canvas. */ smoothProperty: string; /** * The PIXI.Texture. */ texture: PIXI.Texture; /** * The Frame this BitmapData uses for rendering. */ textureFrame: Phaser.Frame; /** * The const type of this object. */ type: number; /** * The width of the BitmapData in pixels. */ width: number; /** * Gets a JavaScript object that has 6 properties set that are used by BitmapData in a transform. * * @param translateX The x translate value. * @param translateY The y translate value. * @param scaleX The scale x value. * @param scaleY The scale y value. * @param skewX The skew x value. * @param skewY The skew y value. * @return A JavaScript object containing all of the properties BitmapData needs for transforms. */ static getTransform(translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): any; /** * Updates the given objects so that they use this BitmapData as their texture. * This will replace any texture they will currently have set. * * @param object Either a single Sprite/Image or an Array of Sprites/Images. * @return This BitmapData object for method chaining. */ add(object: any): Phaser.BitmapData; /** * Creates a new Phaser.Image object, assigns this BitmapData to be its texture, adds it to the world then returns it. * * @param x The x coordinate to place the Image at. * @param y The y coordinate to place the Image at. * @param anchorX Set the x anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param anchorY Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param scaleX The horizontal scale factor of the Image. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @param scaleY The vertical scale factor of the Image. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @return The newly added Image object. */ addToWorld(x?: number, y?: number, anchorX?: number, anchorY?: number, scaleX?: number, scaleY?: number): Phaser.Image; /** * Draws the image onto this BitmapData using an image as an alpha mask. * * @param source The source to copy from. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself. * @param mask The object to be used as the mask. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself. If you don't provide a mask it will use this BitmapData as the mask. * @param sourceRect A Rectangle where x/y define the coordinates to draw the Source image to and width/height define the size. * @param maskRect A Rectangle where x/y define the coordinates to draw the Mask image to and width/height define the size. * @return This BitmapData object for method chaining. */ alphaMask(source: any, mask?: any, sourceRect?: Phaser.Rectangle, maskRect?: Phaser.Rectangle): Phaser.BitmapData; /** * Sets the blend mode to 'lighter' * @return This BitmapData object for method chaining. */ blendAdd(): Phaser.BitmapData; /** * Sets the blend mode to 'color' * @return This BitmapData object for method chaining. */ blendColor(): Phaser.BitmapData; /** * Sets the blend mode to 'color-burn' * @return This BitmapData object for method chaining. */ blendColorBurn(): Phaser.BitmapData; /** * Sets the blend mode to 'color-dodge' * @return This BitmapData object for method chaining. */ blendColorDodge(): Phaser.BitmapData; /** * Sets the blend mode to 'darken' * @return This BitmapData object for method chaining. */ blendDarken(): Phaser.BitmapData; /** * Sets the blend mode to 'destination-atop' * @return This BitmapData object for method chaining. */ blendDestinationAtop(): Phaser.BitmapData; /** * Sets the blend mode to 'destination-in' * @return This BitmapData object for method chaining. */ blendDestinationIn(): Phaser.BitmapData; /** * Sets the blend mode to 'destination-out' * @return This BitmapData object for method chaining. */ blendDestinationOut(): Phaser.BitmapData; /** * Sets the blend mode to 'destination-over' * @return This BitmapData object for method chaining. */ blendDestinationOver(): Phaser.BitmapData; /** * Sets the blend mode to 'difference' * @return This BitmapData object for method chaining. */ blendDifference(): Phaser.BitmapData; /** * Sets the blend mode to 'exclusion' * @return This BitmapData object for method chaining. */ blendExclusion(): Phaser.BitmapData; /** * Sets the blend mode to 'hard-light' * @return This BitmapData object for method chaining. */ blendHardLight(): Phaser.BitmapData; /** * Sets the blend mode to 'hue' * @return This BitmapData object for method chaining. */ blendHue(): Phaser.BitmapData; /** * Sets the blend mode to 'lighten' * @return This BitmapData object for method chaining. */ blendLighten(): Phaser.BitmapData; /** * Sets the blend mode to 'luminosity' * @return This BitmapData object for method chaining. */ blendLuminosity(): Phaser.BitmapData; /** * Sets the blend mode to 'multiply' * @return This BitmapData object for method chaining. */ blendMultiply(): Phaser.BitmapData; /** * Sets the blend mode to 'overlay' * @return This BitmapData object for method chaining. */ blendOverlay(): Phaser.BitmapData; /** * Resets the blend mode (effectively sets it to 'source-over') * @return This BitmapData object for method chaining. */ blendReset(): Phaser.BitmapData; /** * Sets the blend mode to 'saturation' * @return This BitmapData object for method chaining. */ blendSaturation(): Phaser.BitmapData; /** * Sets the blend mode to 'screen' * @return This BitmapData object for method chaining. */ blendScreen(): Phaser.BitmapData; /** * Sets the blend mode to 'soft-light' * @return This BitmapData object for method chaining. */ blendSoftLight(): Phaser.BitmapData; /** * Sets the blend mode to 'source-atop' * @return This BitmapData object for method chaining. */ blendSourceAtop(): Phaser.BitmapData; /** * Sets the blend mode to 'source-in' * @return This BitmapData object for method chaining. */ blendSourceIn(): Phaser.BitmapData; /** * Sets the blend mode to 'source-out' * @return This BitmapData object for method chaining. */ blendSourceOut(): Phaser.BitmapData; /** * Sets the blend mode to 'source-over' * @return This BitmapData object for method chaining. */ blendSourceOver(): Phaser.BitmapData; /** * Sets the blend mode to 'xor' * @return This BitmapData object for method chaining. */ blendXor(): Phaser.BitmapData; /** * Draws a filled Circle to the BitmapData at the given x, y coordinates and radius in size. * * @param x The x coordinate to draw the Circle at. This is the center of the circle. * @param y The y coordinate to draw the Circle at. This is the center of the circle. * @param radius The radius of the Circle in pixels. The radius is half the diameter. * @param fillStyle If set the context fillStyle will be set to this value before the circle is drawn. * @return This BitmapData object for method chaining. */ circle(x: number, y: number, radius: number, fillStyle?: string): Phaser.BitmapData; /** * Clears the BitmapData context using a clearRect. * * You can optionally define the area to clear. * If the arguments are left empty it will clear the entire canvas. * * You may need to call BitmapData.update after this in order to clear out the pixel data, * but Phaser will not do this automatically for you. * * @param x The x coordinate of the top-left of the area to clear. * @param y The y coordinate of the top-left of the area to clear. * @param width The width of the area to clear. If undefined it will use BitmapData.width. * @param height The height of the area to clear. If undefined it will use BitmapData.height. * @return This BitmapData object for method chaining. */ clear(x?: number, y?: number, width?: number, height?: number): Phaser.BitmapData; /** * Clears the BitmapData context using a clearRect. */ cls(): Phaser.BitmapData; /** * Copies a rectangular area from the source object to this BitmapData. If you give `null` as the source it will copy from itself. * * You can optionally resize, translate, rotate, scale, alpha or blend as it's drawn. * * All rotation, scaling and drawing takes place around the regions center point by default, but can be changed with the anchor parameters. * * Note that the source image can also be this BitmapData, which can create some interesting effects. * * This method has a lot of parameters for maximum control. * You can use the more friendly methods like `copyRect` and `draw` to avoid having to remember them all. * * You may prefer to use `copyTransform` if you're simply trying to draw a Sprite to this BitmapData, * and don't wish to translate, scale or rotate it from its original values. * * @param source The source to copy from. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself. * @param x The x coordinate representing the top-left of the region to copy from the source image. * @param y The y coordinate representing the top-left of the region to copy from the source image. * @param width The width of the region to copy from the source image. If not specified it will use the full source image width. * @param height The height of the region to copy from the source image. If not specified it will use the full source image height. * @param tx The x coordinate to translate to before drawing. If not specified it will default to the `x` parameter. If `null` and `source` is a Display Object, it will default to `source.x`. * @param ty The y coordinate to translate to before drawing. If not specified it will default to the `y` parameter. If `null` and `source` is a Display Object, it will default to `source.y`. * @param newWidth The new width of the block being copied. If not specified it will default to the `width` parameter. * @param newHeight The new height of the block being copied. If not specified it will default to the `height` parameter. * @param rotate The angle in radians to rotate the block to before drawing. Rotation takes place around the center by default, but can be changed with the `anchor` parameters. * @param anchorX The anchor point around which the block is rotated and scaled. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param anchorY The anchor point around which the block is rotated and scaled. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param scaleX The horizontal scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @param scaleY The vertical scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @param alpha The alpha that will be set on the context before drawing. A value between 0 (fully transparent) and 1, opaque. - Default: 1 * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ copy(source?: any, x?: number, y?: number, width?: number, height?: number, tx?: number, ty?: number, newWidth?: number, newHeight?: number, rotate?: number, anchorX?: number, anchorY?: number, scaleX?: number, scaleY?: number, alpha?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; copyPixels(source: any, area: Phaser.Rectangle, x: number, y: number, alpha?: number): void; /** * Copies the area defined by the Rectangle parameter from the source image to this BitmapData at the given location. * * @param source The Image to copy from. If you give a string it will try and find the Image in the Game.Cache. * @param area The Rectangle region to copy from the source image. * @param x The destination x coordinate to copy the image to. * @param y The destination y coordinate to copy the image to. * @param alpha The alpha that will be set on the context before drawing. A value between 0 (fully transparent) and 1, opaque. - Default: 1 * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ copyRect(source: any, area: Phaser.Rectangle, x?: number, y?: number, alpha?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Draws the given `source` Game Object to this BitmapData, using its `worldTransform` property to set the * position, scale and rotation of where it is drawn. This function is used internally by `drawGroup`. * It takes the objects tint and scale mode into consideration before drawing. * * You can optionally specify Blend Mode and Round Pixels arguments. * * @param source The Game Object to draw. * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ copyTransform(source: any, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Destroys this BitmapData and puts the canvas it was using back into the canvas pool for re-use. */ destroy(): void; /** * Draws the given Phaser.Sprite, Phaser.Image or Phaser.Text to this BitmapData at the coordinates specified. * You can use the optional width and height values to 'stretch' the sprite as it is drawn. This uses drawImage stretching, not scaling. * * The children will be drawn at their `x` and `y` world space coordinates. If this is outside the bounds of the BitmapData they won't be visible. * When drawing it will take into account the rotation, scale, scaleMode, alpha and tint values. * * Note: You should ensure that at least 1 full update has taken place before calling this, * otherwise the objects are likely to render incorrectly, if at all. * You can trigger an update yourself by calling `stage.updateTransform()` before calling `draw`. * * @param source The Sprite, Image or Text object to draw onto this BitmapData. * @param x The x coordinate to translate to before drawing. If not specified it will default to `source.x`. * @param y The y coordinate to translate to before drawing. If not specified it will default to `source.y`. * @param width The new width of the Sprite being copied. If not specified it will default to `source.width`. * @param height The new height of the Sprite being copied. If not specified it will default to `source.height`. * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ draw(source: any, x?: number, y?: number, width?: number, height?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Draws the Game Object or Group to this BitmapData and then recursively iterates through all of its children. * * If a child has an `exists` property then it (and its children) will be only be drawn if exists is `true`. * * The children will be drawn at their `x` and `y` world space coordinates. If this is outside the bounds of the BitmapData * they won't be drawn. Depending on your requirements you may need to resize the BitmapData in advance to match the * bounds of the top-level Game Object. * * When drawing it will take into account the child's world rotation, scale and alpha values. * * It's perfectly valid to pass in `game.world` as the parent object, and it will iterate through the entire display list. * * Note: If you are trying to grab your entire game at the start of a State then you should ensure that at least 1 full update * has taken place before doing so, otherwise all of the objects will render with incorrect positions and scales. You can * trigger an update yourself by calling `stage.updateTransform()` before calling `drawFull`. * * @param parent The Game Object to draw onto this BitmapData and then recursively draw all of its children. * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ drawFull(parent: any, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Draws the immediate children of a Phaser.Group to this BitmapData. * * It's perfectly valid to pass in `game.world` as the Group, and it will iterate through the entire display list. * * Children are drawn _only_ if they have their `exists` property set to `true`, and have image, or RenderTexture, based Textures. * * The children will be drawn at their `x` and `y` world space coordinates. If this is outside the bounds of the BitmapData they won't be visible. * When drawing it will take into account the rotation, scale, scaleMode, alpha and tint values. * * Note: You should ensure that at least 1 full update has taken place before calling this, * otherwise the objects are likely to render incorrectly, if at all. * You can trigger an update yourself by calling `stage.updateTransform()` before calling `drawGroup`. * * @param group The Group to draw onto this BitmapData. Can also be Phaser.World. * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return This BitmapData object for method chaining. */ drawGroup(group: Phaser.Group, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Scans this BitmapData for all pixels matching the given r,g,b values and then draws them into the given destination BitmapData. * The original BitmapData remains unchanged. * The destination BitmapData must be large enough to receive all of the pixels that are scanned unless the 'resize' parameter is true. * Although the destination BitmapData is returned from this method, it's actually modified directly in place, meaning this call is perfectly valid: * `picture.extract(mask, r, g, b)` * You can specify optional r2, g2, b2 color values. If given the pixel written to the destination bitmap will be of the r2, g2, b2 color. * If not given it will be written as the same color it was extracted. You can provide one or more alternative colors, allowing you to tint * the color during extraction. * * @param destination The BitmapData that the extracted pixels will be drawn to. * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 255 that the new pixel will be drawn at. - Default: 255 * @param resize Should the destination BitmapData be resized to match this one before the pixels are copied? * @param r2 An alternative red color component to be written to the destination, in the range 0 - 255. * @param g2 An alternative green color component to be written to the destination, in the range 0 - 255. * @param b2 An alternative blue color component to be written to the destination, in the range 0 - 255. * @return The BitmapData that the extract pixels were drawn on. */ extract(destination: Phaser.BitmapData, r: number, g: number, b: number, a?: number, resize?: boolean, r2?: number, g2?: number, b2?: number): Phaser.BitmapData; /** * Fills the BitmapData with the given color. * * @param r The red color value, between 0 and 0xFF (255). * @param g The green color value, between 0 and 0xFF (255). * @param b The blue color value, between 0 and 0xFF (255). * @param a The alpha color value, between 0 and 1. - Default: 1 * @return This BitmapData object for method chaining. */ fill(r: number, g: number, b: number, a?: number): Phaser.BitmapData; /** * Creates a new {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image Image} element by converting this BitmapDatas canvas into a dataURL. * * The image is then stored in the {@link Phaser.Cache image Cache} using the key given. * * Finally a {@link PIXI.Texture} is created based on the image and returned. * * You can apply the texture to a sprite or any other supporting object by using either the * key or the texture. First call `generateTexture`: * * ```javascript * var texture = bitmapdata.generateTexture('ball'); * ``` * * Then you can either apply the texture to a sprite: * * ```javascript * game.add.sprite(0, 0, texture); * ``` * * or by using the string based key: * * ```javascript * game.add.sprite(0, 0, 'ball'); * ``` * * Most browsers now load the image data asynchronously, so you should use a callback: * * ```javascript * bitmapdata.generateTexture('ball', function (texture) { * game.add.sprite(0, 0, texture); * // or * game.add.sprite(0, 0, 'ball'); * }); * ``` * * If this BitmapData is available during preload, you can use {@link Phaser.Loader#imageFromBitmapData} instead. * * @param key The key which will be used to store the image in the Cache. * @param callback A function to execute once the texture is generated. It will be passed the newly generated texture. * @param callbackContext The context in which to invoke the callback. * @return The newly generated texture, or `null` if a callback was passed and the texture isn't available yet. */ generateTexture(key: string, callback?: (texture: PIXI.Texture) => void, callbackContext?: any): PIXI.Texture; /** * Scans the BitmapData and calculates the bounds. This is a rectangle that defines the extent of all non-transparent pixels. * The rectangle returned will extend from the top-left of the image to the bottom-right, excluding transparent pixels. * * @param rect If provided this Rectangle object will be populated with the bounds, otherwise a new object will be created. * @return A Rectangle whose dimensions encompass the full extent of non-transparent pixels in this BitmapData. */ getBounds(rect?: Phaser.Rectangle): Phaser.Rectangle; /** * Scans the BitmapData, pixel by pixel, until it encounters a pixel that isn't transparent (i.e. has an alpha value > 0). * It then stops scanning and returns an object containing the color of the pixel in r, g and b properties and the location in the x and y properties. * * The direction parameter controls from which direction it should start the scan: * * 0 = top to bottom * 1 = bottom to top * 2 = left to right * 3 = right to left * * @param direction The direction in which to scan for the first pixel. 0 = top to bottom, 1 = bottom to top, 2 = left to right and 3 = right to left. * @return Returns an object containing the color of the pixel in the `r`, `g` and `b` properties and the location in the `x` and `y` properties. */ getFirstPixel(direction: number): { r: number; g: number; b: number; x: number; y: number; }; /** * Get the color of a specific pixel in the context into a color object. * If you have drawn anything to the BitmapData since it was created you must call BitmapData.update to refresh the array buffer, * otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist. * * @param x The x coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param out An object into which 4 properties will be created: r, g, b and a. If not provided a new object will be created. * @return An object with the red, green, blue and alpha values set in the r, g, b and a properties. */ getPixel(x: number, y: number, out?: any): any; /** * Get the color of a specific pixel including its alpha value as a color object containing r,g,b,a and rgba properties. * If you have drawn anything to the BitmapData since it was created you must call BitmapData.update to refresh the array buffer, * otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist. * * @param x The x coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param out An object into which 3 properties will be created: r, g and b. If not provided a new object will be created. * @param hsl Also convert the rgb values into hsl? * @param hsv Also convert the rgb values into hsv? * @return An object with the red, green and blue values set in the r, g and b properties. */ getPixelRGB(x: number, y: number, out?: any, hsl?: boolean, hsv?: boolean): any; /** * Get the color of a specific pixel including its alpha value. * If you have drawn anything to the BitmapData since it was created you must call BitmapData.update to refresh the array buffer, * otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist. * Note that on little-endian systems the format is 0xAABBGGRR and on big-endian the format is 0xRRGGBBAA. * * @param x The x coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @return A native color value integer (format: 0xAARRGGBB) */ getPixel32(x: number, y: number): number; /** * Gets all the pixels from the region specified by the given Rectangle object. * * @param rect The Rectangle region to get. * @return Returns a ImageData object containing a Uint8ClampedArray data property. */ getPixels(rect: Phaser.Rectangle): ImageData; /** * Gets a JavaScript object that has 6 properties set that are used by BitmapData in a transform. * * @param translateX The x translate value. * @param translateY The y translate value. * @param scaleX The scale x value. * @param scaleY The scale y value. * @param skewX The skew x value. * @param skewY The skew y value. * @return A JavaScript object containing all of the properties BitmapData needs for transforms. */ getTransform(translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): any; /** * Draws a line between the coordinates given in the color and thickness specified. * * @param x1 The x coordinate to start the line from. * @param y1 The y coordinate to start the line from. * @param x2 The x coordinate to draw the line to. * @param y2 The y coordinate to draw the line to. * @param color The stroke color that the line will be drawn in. - Default: '#fff' * @param width The line thickness. - Default: 1 * @return This BitmapData object for method chaining. */ line(x1: number, y1: number, x2: number, y2: number, color?: string, width?: number): Phaser.BitmapData; /** * Takes the given Game Object, resizes this BitmapData to match it and then draws it into this BitmapDatas canvas, ready for further processing. * The source game object is not modified by this operation. * If the source object uses a texture as part of a Texture Atlas or Sprite Sheet, only the current frame will be used for sizing. * If a string is given it will assume it's a cache key and look in Phaser.Cache for an image key matching the string. * * @param source The object that will be used to populate this BitmapData. If you give a string it will try and find the Image in the Game.Cache first. * @return This BitmapData object for method chaining. */ load(source: any): Phaser.BitmapData; /** * Shifts the contents of this BitmapData by the distances given. * * The image will wrap-around the edges on all sides if the wrap argument is true (the default). * * @param x The amount of pixels to horizontally shift the canvas by. Use a negative value to shift to the left, positive to the right. * @param y The amount of pixels to vertically shift the canvas by. Use a negative value to shift up, positive to shift down. * @param wrap Wrap the content of the BitmapData. - Default: true * @return This BitmapData object for method chaining. */ move(x: number, y: number, wrap?: boolean): Phaser.BitmapData; /** * Shifts the contents of this BitmapData horizontally. * * The image will wrap-around the sides if the wrap argument is true (the default). * * @param distance The amount of pixels to horizontally shift the canvas by. Use a negative value to shift to the left, positive to the right. * @param wrap Wrap the content of the BitmapData. - Default: true * @return This BitmapData object for method chaining. */ moveH(distance: number, wrap?: boolean): Phaser.BitmapData; /** * Shifts the contents of this BitmapData vertically. * * The image will wrap-around the sides if the wrap argument is true (the default). * * @param distance The amount of pixels to vertically shift the canvas by. Use a negative value to shift up, positive to shift down. * @param wrap Wrap the content of the BitmapData. - Default: true * @return This BitmapData object for method chaining. */ moveV(distance: number, wrap?: boolean): Phaser.BitmapData; /** * Draws a polygon. * * @param points An array of {@link Phaser.Point} or point-like objects. * @param fillStyle A color, gradient, or pattern. * @param lineWidth The line thickness. * @param strokeStyle The line color, gradient, or pattern (when `lineWidth` > 0). - Default: '#fff' * @return This BitmapData object for method chaining. */ polygon(points: any[], fillStyle?: string | CanvasGradient | CanvasPattern, lineWidth?: number, strokeStyle?: string | CanvasGradient | CanvasPattern): Phaser.BitmapData; /** * Scans through the area specified in this BitmapData and sends the color for every pixel to the given callback along with its x and y coordinates. * Whatever value the callback returns is set as the new color for that pixel, unless it returns the same color, in which case it's skipped. * Note that the format of the color received will be different depending on if the system is big or little endian. * It is expected that your callback will deal with endianess. If you'd rather Phaser did it then use processPixelRGB instead. * The callback will also be sent the pixels x and y coordinates respectively. * * @param callback The callback that will be sent each pixel color to be processed. * @param callbackContext The context under which the callback will be called. * @param x The x coordinate of the top-left of the region to process from. * @param y The y coordinate of the top-left of the region to process from. * @param width The width of the region to process. * @param height The height of the region to process. * @return This BitmapData object for method chaining. */ processPixel(callback: (color: number, x: number, y: number) => void, callbackContext?: any, x?: number, y?: Number, width?: number, height?: number): Phaser.BitmapData; /** * Scans through the area specified in this BitmapData and sends a color object for every pixel to the given callback. * The callback will be sent a color object with 6 properties: `{ r: number, g: number, b: number, a: number, color: number, rgba: string }`. * Where r, g, b and a are integers between 0 and 255 representing the color component values for red, green, blue and alpha. * The `color` property is an Int32 of the full color. Note the endianess of this will change per system. * The `rgba` property is a CSS style rgba() string which can be used with context.fillStyle calls, among others. * The callback will also be sent the pixels x and y coordinates respectively. * The callback must return either `false`, in which case no change will be made to the pixel, or a new color object. * If a new color object is returned the pixel will be set to the r, g, b and a color values given within it. * * @param callback The callback that will be sent each pixel color object to be processed. * @param callbackContext The context under which the callback will be called. * @param x The x coordinate of the top-left of the region to process from. * @param y The y coordinate of the top-left of the region to process from. * @param width The width of the region to process. * @param height The height of the region to process. * @return This BitmapData object for method chaining. */ processPixelRGB(callback: (color: ColorComponents, x: number, y: number) => void, callbackContext?: any, x?: number, y?: Number, width?: number, height?: number): Phaser.BitmapData; /** * Draws a filled Rectangle to the BitmapData at the given x, y coordinates and width / height in size. * * @param x The x coordinate of the top-left of the Rectangle. * @param y The y coordinate of the top-left of the Rectangle. * @param width The width of the Rectangle. * @param height The height of the Rectangle. * @param fillStyle If set the context fillStyle will be set to this value before the rect is drawn. * @return This BitmapData object for method chaining. */ rect(x: number, y: number, width: number, height: number, fillStyle?: string): Phaser.BitmapData; /** * If the game is running in WebGL this will push the texture up to the GPU if it's dirty. * This is called automatically if the BitmapData is being used by a Sprite, otherwise you need to remember to call it in your render function. * If you wish to suppress this functionality set BitmapData.disableTextureUpload to `true`. * @return This BitmapData object for method chaining. */ render(): Phaser.BitmapData; /** * Replaces all pixels matching one color with another. The color values are given as two sets of RGBA values. * An optional region parameter controls if the replacement happens in just a specific area of the BitmapData or the entire thing. * * @param r1 The red color value to be replaced. Between 0 and 255. * @param g1 The green color value to be replaced. Between 0 and 255. * @param b1 The blue color value to be replaced. Between 0 and 255. * @param a1 The alpha color value to be replaced. Between 0 and 255. * @param r2 The red color value that is the replacement color. Between 0 and 255. * @param g2 The green color value that is the replacement color. Between 0 and 255. * @param b2 The blue color value that is the replacement color. Between 0 and 255. * @param a2 The alpha color value that is the replacement color. Between 0 and 255. * @param region The area to perform the search over. If not given it will replace over the whole BitmapData. * @return This BitmapData object for method chaining. */ replaceRGB(r1: number, g1: number, b1: number, a1: number, r2: number, g2: number, b2: number, a2: number, region?: Phaser.Rectangle): Phaser.BitmapData; /** * Resizes the BitmapData. This changes the size of the underlying canvas and refreshes the buffer. * * @param width The new width of the BitmapData. * @param height The new height of the BitmapData. * @return This BitmapData object for method chaining. */ resize(width: number, height: number): Phaser.BitmapData; resizeFrame(parent: any, width: number, height: number): void; /** * Sets the hue, saturation and lightness values on every pixel in the given region, or the whole BitmapData if no region was specified. * * @param h The hue, in the range 0 - 1. * @param s The saturation, in the range 0 - 1. * @param l The lightness, in the range 0 - 1. * @param region The area to perform the operation on. If not given it will run over the whole BitmapData. * @return This BitmapData object for method chaining. */ setHSL(h?: number, s?: number, l?: number, region?: Phaser.Rectangle): Phaser.BitmapData; /** * Sets the color of the given pixel to the specified red, green and blue values. * * @param x The x coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param red The red color value, between 0 and 0xFF (255). * @param green The green color value, between 0 and 0xFF (255). * @param blue The blue color value, between 0 and 0xFF (255). * @param immediate If `true` the context.putImageData will be called and the dirty flag set. - Default: true * @return This BitmapData object for method chaining. */ setPixel(x: number, y: number, red: number, green: number, blue: number, immediate?: boolean): Phaser.BitmapData; /** * Sets the color of the given pixel to the specified red, green, blue and alpha values. * * @param x The x coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData and be an integer, not a float. * @param red The red color value, between 0 and 0xFF (255). * @param green The green color value, between 0 and 0xFF (255). * @param blue The blue color value, between 0 and 0xFF (255). * @param alpha The alpha color value, between 0 and 0xFF (255). * @param immediate If `true` the context.putImageData will be called and the dirty flag set. - Default: true * @return This BitmapData object for method chaining. */ setPixel32(x: number, y: number, red: number, green: number, blue: number, alpha: number, immediate?: boolean): Phaser.BitmapData; /** * Sets the shadow properties of this BitmapDatas context which will affect all draw operations made to it. * You can cancel an existing shadow by calling this method and passing no parameters. * Note: At the time of writing (October 2014) Chrome still doesn't support shadowBlur used with drawImage. * * @param color The color of the shadow, given in a CSS format, i.e. `#000000` or `rgba(0,0,0,1)`. If `null` or `undefined` the shadow will be reset. * @param blur The amount the shadow will be blurred by. Low values = a crisp shadow, high values = a softer shadow. - Default: 5 * @param x The horizontal offset of the shadow in pixels. - Default: 10 * @param y The vertical offset of the shadow in pixels. - Default: 10 * @return This BitmapData object for method chaining. */ shadow(color: string, blur?: number, x?: number, y?: number): Phaser.BitmapData; /** * Shifts any or all of the hue, saturation and lightness values on every pixel in the given region, or the whole BitmapData if no region was specified. * Shifting will add the given value onto the current h, s and l values, not replace them. * The hue is wrapped to keep it within the range 0 to 1. Saturation and lightness are clamped to not exceed 1. * * @param h The amount to shift the hue by. Within [-1, 1]. * @param s The amount to shift the saturation by. Within [-1, 1]. * @param l The amount to shift the lightness by. Within [-1, 1]. * @param region The area to perform the operation on. If not given it will run over the whole BitmapData. * @return This BitmapData object for method chaining. */ shiftHSL(h?: number, s?: number, l?: number, region?: Phaser.Rectangle): Phaser.BitmapData; /** * Draws text to the BitmapData in the given font and color. * The default font is 14px Courier, so useful for quickly drawing debug text. * If you need to do a lot of font work to this BitmapData we'd recommend implementing your own text draw method. * * @param text The text to write to the BitmapData. * @param x The x coordinate of the top-left of the text string. * @param y The y coordinate of the top-left of the text string. * @param font The font. This is passed directly to Context.font, so anything that can support, this can. - Default: '14px Courier' * @param color The color the text will be drawn in. - Default: 'rgb(255,255,255)' * @param shadow Draw a single pixel black shadow below the text (offset by text.x/y + 1) - Default: true * @return This BitmapData object for method chaining. */ text(text: string, x?: number, y?: number, font?: string, color?: string, shadow?: boolean): Phaser.BitmapData; /** * Takes the given Line object and image and renders it to this BitmapData as a repeating texture line. * * @param line A Phaser.Line object that will be used to plot the start and end of the line. * @param image The key of an image in the Phaser.Cache to use as the texture for this line, or an actual Image. * @param repeat The pattern repeat mode to use when drawing the line. Either `repeat`, `repeat-x` or `no-repeat`. - Default: 'repeat-x' * @return This BitmapData object for method chaining. */ textureLine(line: Phaser.Line, key: string, repeat?: string): Phaser.BitmapData; /** * This re-creates the BitmapData.imageData from the current context. * It then re-builds the ArrayBuffer, the data Uint8ClampedArray reference and the pixels Int32Array. * If not given the dimensions defaults to the full size of the context. * * Warning: This is a very expensive operation, so use it sparingly. * * @param x The x coordinate of the top-left of the image data area to grab from. * @param y The y coordinate of the top-left of the image data area to grab from. * @param width The width of the image data area. - Default: 1 * @param height The height of the image data area. - Default: 1 * @return This BitmapData object for method chaining. */ update(x?: number, y?: number, width?: number, height?: number): Phaser.BitmapData; /** * Updates a portion of the BitmapData from a source Bitmap. * This optimization is important if calling update() on a large Bitmap is causing performance issues. * Make sure you use getPixel32() instead of getPixel(). * This does not work with floating point numbers for x and y. * * @param source The BitmapData you wish to copy. * @param x The x coordinate of the top-left of the area to copy. * @param y The y coordinate of the top-left of the area to copy. * @return This BitmapData object for method chaining. */ copyBitmapData(source: Phaser.BitmapData, x: number, y: number): Phaser.BitmapData; } /** * BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure. * It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to * match the font structure. * * BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability * to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by * processing the font texture in an image editor, applying fills and any other effects required. * * To create multi-line text insert \r, \n or \r\n escape codes into the text string. * * If you are having performance issues due to the volume of sprites being rendered, and do not require the text to be constantly * updating, you can use BitmapText.generateTexture to create a static texture from this BitmapText. * * To create a BitmapText data files you can use: * * 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/ * * 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 * * If you were using an older version of Phaser (< 2.4) and using the DOMish parser hack, please remove this. It isn't required any longer. */ class BitmapText extends PIXI.DisplayObjectContainer { /** * BitmapText objects work by taking a texture file and an XML or JSON file that describes the font structure. * It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to * match the font structure. * * BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability * to use Web Fonts, however you trade this flexibility for rendering speed. You can also create visually compelling BitmapTexts by * processing the font texture in an image editor, applying fills and any other effects required. * * To create multi-line text insert \r, \n or \r\n escape codes into the text string. * * If you are having performance issues due to the volume of sprites being rendered, and do not require the text to be constantly * updating, you can use BitmapText.generateTexture to create a static texture from this BitmapText. * * To create a BitmapText data files you can use: * * 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/ * * 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 * * If you were using an older version of Phaser (< 2.4) and using the DOMish parser hack, please remove this. It isn't required any longer. * * @param game A reference to the currently running game. * @param x X coordinate to display the BitmapText object at. * @param y Y coordinate to display the BitmapText object at. * @param font The key of the BitmapText as stored in Phaser.Cache. * @param text The text that will be rendered. This can also be set later via BitmapText.text. - Default: '' * @param size The size the font will be rendered at in pixels. - Default: 32 * @param align The alignment of multi-line text. Has no effect if there is only one line of text. - Default: 'left' */ constructor(game: Phaser.Game, x: number, y: number, font: string, text?: string, size?: number, align?: string); /** * Alignment for multi-line text ('left', 'center' or 'right'), does not affect single lines of text. */ align: string; /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * The anchor value of this BitmapText. */ anchor: Phaser.Point; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated * properties and methods via it. * * By default Game Objects won't add themselves to any physics system and their `body` property will be `null`. * * To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object * and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`. * * You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group. * * Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5, * so the physics body is centered on the Game Object. * * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. */ body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * If this is set to `true` the Game Object checks if it is within the World bounds each frame. * * When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event. * * If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event. * * It also optionally kills the Game Object if `outOfBoundsKill` is `true`. * * When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ checkWorldBounds: boolean; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; /** * The dirty state of this object. */ dirty: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Game Object is processed by the core game loop. * If this Game Object has a physics body it also controls if its physics body is updated or not. * When `exists` is set to `false` it will remove its physics body from the physics world if it has one. * It also toggles the `visible` property to false as well. * * Setting `exists` to true will add its physics body back in to the physics world, if it has one. * It will also set the `visible` property to `true`. */ exists: boolean; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use. */ font: string; /** * The size of the font in pixels. */ fontSize: number; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; /** * Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds. */ inWorld: boolean; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The components this Game Object has installed. */ components: any; /** * The lifespan allows you to give a Game Object a lifespan in milliseconds. * * Once the Game Object is 'born' you can set this to a positive value. * * It is automatically decremented by `game.time.delta` each frame. * When it reaches zero it will call the `kill` method. * * Very handy for particles, bullets, collectibles, or any other short-lived entity. */ lifespan: number; /** * The maximum display width of this BitmapText in pixels. * * If BitmapText.text is longer than maxWidth then the lines will be automatically wrapped * based on the last whitespace character found in the line. * * If no whitespace was found then no wrapping will take place and consequently the maxWidth value will not be honored. * * Disable maxWidth by setting the value to 0. The maximum width of this BitmapText in pixels. */ maxWidth: number; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false. */ outOfBoundsKill: boolean; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The const physics body type of this object. */ physicsType: number; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The text to be displayed by this BitmapText object. */ text: string; /** * Enable or disable texture smoothing for this BitmapText. * * The smoothing is applied to the BaseTexture of this font, which all letters of the text reference. * * Smoothing is enabled by default. */ smoothed: boolean; /** * The width in pixels of the overall text area, taking into consideration multi-line text. */ textWidth: number; /** * The height in pixels of the overall text area, taking into consideration multi-line text. */ textHeight: number; /** * The tint applied to the BitmapText. This is a hex value. Set to white to disable (0xFFFFFF) */ tint: number; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The const type of this object. */ type: number; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The horizontal position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ x: number; /** * The vertical position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ y: number; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Destroy this DisplayObject. * * Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask. * * Also iteratively calls `destroy` on any children. */ destroy(destroyChildren?: boolean): void; /** * Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false. * * It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal. * * Note that killing a Game Object is a way for you to quickly recycle it in an object pool, * it doesn't destroy the object or free it up from memory. * * If you don't need this Game Object any more you should call `destroy` instead. * @return This instance. */ kill(): void; /** * Automatically called by World.preUpdate. */ postUpdate(): void; /** * Automatically called by World.preUpdate. * @return True if the BitmapText was rendered, otherwise false. */ preUpdate(): void; /** * If a BitmapText changes from having a large number of characters to having very few characters it will cause lots of * Sprites to be retained in the BitmapText._glyphs array. Although they are not attached to the display list they * still take up memory while sat in the glyphs pool waiting to be re-used in the future. * * If you know that the BitmapText will not grow any larger then you can purge out the excess glyphs from the pool * by calling this method. * * Calling this doesn't prevent you from increasing the length of the text again in the future. * @return The amount of glyphs removed from the pool. */ purgeGlyphs(): number; /** * Resets the Game Object. * * This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`, * `visible` and `renderable` to true. * * If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value. * * If this Game Object has a Physics Body it will reset the Body. * * @param x The x coordinate (in world space) to position the Game Object at. * @param y The y coordinate (in world space) to position the Game Object at. * @param health The health to give the Game Object if it has the Health component. - Default: 1 * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.BitmapText; /** * Brings a 'dead' Game Object back to life, optionally resetting its health value in the process. * * A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true. * * It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal. * * @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100 * @return This instance. */ revive(health?: number): Phaser.BitmapText; /** * Given the input text this will scan the characters until either a newline is encountered, * or the line exceeds maxWidth, taking into account kerning, character widths and scaling. * * @param data A reference to the font object in the Phaser.Cache. * @param scale The scale of the font in relation to the texture. * @param text The text to parse. * @return An object containing the parsed characters, total pixel width and x offsets. */ /** * The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set */ /** * The text to be displayed by this BitmapText object. */ scanLine(data: any, scale: number, text: string): { width: number; text: string; end: boolean; chars: string[] }; /** * The text to be displayed by this BitmapText object. * * It's faster to use `BitmapText.text = string`, but this is kept for backwards compatibility. * * @param text The text to be displayed by this BitmapText object. */ setText(text: string): void; /** * Override this method in your own custom objects to handle any update requirements. * It is called immediately after `preUpdate` and before `postUpdate`. * Remember if this Game Object has any children you should call update on those too. */ update(): void; /** * Renders text and updates it when needed. */ updateText(): void; /** * Updates the transform of this object. */ updateTransform(): void; } /** * Create a new `Bullet` object. Bullets are used by the `Phaser.Weapon` class, and are normal Sprites, * with a few extra properties in the data object to handle Weapon specific features. */ class Bullet extends Phaser.Sprite { /** * Create a new `Bullet` object. Bullets are used by the `Phaser.Weapon` class, and are normal Sprites, * with a few extra properties in the data object to handle Weapon specific features. * * @param game A reference to the currently running game. * @param x The x coordinate (in world space) to position the Particle at. * @param y The y coordinate (in world space) to position the Particle at. * @param key This is the image or texture used by the Particle during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If this Particle is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ constructor(game: Phaser.Game, x: number, y: number, key?: any, frame?: any); /** * Kills the Bullet, freeing it up for re-use by the Weapon bullet pool. * Also dispatches the `Weapon.onKill` signal. */ kill(): Phaser.Bullet; /** * Updates the Bullet, killing as required. */ update(): void; } /** * Create a new `Button` object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically. * * The four states a Button responds to are: * * * 'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'. * * 'Out' - when the Pointer that was previously over the Button moves out of it. * * 'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse. * * 'Up' - when the Pointer that was pressed down on the Button is released again. * * A different texture/frame and activation sound can be specified for any of the states. * * Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor. */ class Button extends Phaser.Image { /** * Create a new `Button` object. A Button is a special type of Sprite that is set-up to handle Pointer events automatically. * * The four states a Button responds to are: * * * 'Over' - when the Pointer moves over the Button. This is also commonly known as 'hover'. * * 'Out' - when the Pointer that was previously over the Button moves out of it. * * 'Down' - when the Pointer is pressed down on the Button. I.e. touched on a touch enabled device or clicked with the mouse. * * 'Up' - when the Pointer that was pressed down on the Button is released again. * * A different texture/frame and activation sound can be specified for any of the states. * * Frames can be specified as either an integer (the frame ID) or a string (the frame name); the same values that can be used with a Sprite constructor. * * @param game Current game instance. * @param x X position of the Button. * @param y Y position of the Button. * @param key The image key (in the Game.Cache) to use as the texture for this Button. * @param callback The function to call when this Button is pressed, receiving `this` (the Button), `pointer` (the Pointer causing the input), and `isOver` (whether the Pointer is still on the Button). See {@link Phaser.Events#onInputUp}. * @param callbackContext The context in which the callback will be called (usually 'this'). * @param overFrame The frame / frameName when the button is in the Over state. * @param outFrame The frame / frameName when the button is in the Out state. * @param downFrame The frame / frameName when the button is in the Down state. * @param upFrame The frame / frameName when the button is in the Up state. */ constructor(game: Phaser.Game, x?: number, y?: number, key?: string, callback?: Function, callbackContext?: any, overFrame?: string | number, outFrame?: string | number, downFrame?: string | number, upFrame?: string | number); /** * When the Button is touched / clicked and then released you can force it to enter a state of "out" instead of "up". * * This can also accept a {@link Phaser.PointerModer pointer mode bitmask} for more refined control. */ forceOut: boolean; /** * When true the the texture frame will not be automatically switched on up/down/over/out events. */ freezeFrames: boolean; /** * The Sound to be played when this Buttons Down state is activated. */ onDownSound: Phaser.Sound | Phaser.AudioSprite; /** * The Sound Marker used in conjunction with the onDownSound. */ onDownSoundMarker: string; /** * The Signal (or event) dispatched when this Button is in an Down state. */ onInputDown: Phaser.Signal; /** * The Signal (or event) dispatched when this Button is in an Out state. */ onInputOut: Phaser.Signal; /** * The Signal (or event) dispatched when this Button is in an Over state. */ onInputOver: Phaser.Signal; /** * The Signal (or event) dispatched when this Button is in an Up state. */ onInputUp: Phaser.Signal; /** * The Sound to be played when this Buttons Out state is activated. */ onOutSound: Phaser.Sound | Phaser.AudioSprite; /** * The Sound Marker used in conjunction with the onOutSound. */ onOutSoundMarker: string; /** * The Sound to be played when this Buttons Over state is activated. */ onOverSound: Phaser.Sound | Phaser.AudioSprite; /** * The Sound Marker used in conjunction with the onOverSound. */ onOverSoundMarker: string; /** * If true then onOver events (such as onOverSound) will only be triggered if the Pointer object causing them was the Mouse Pointer. * The frame will still be changed as applicable. * Default: true */ onOverMouseOnly: boolean; /** * The Sound to be played when this Buttons Up state is activated. */ onUpSound: Phaser.Sound | Phaser.AudioSprite; onUpSoundMaker: string; /** * The const physics body type of this object. */ physicsType: number; /** * The Phaser Object Type. */ type: number; /** * Clears all of the frames set on this Button. */ clearFrames(): void; /** * The Sound to be played when a Pointer presses down on this Button. * * @param sound The Sound that will be played. * @param marker A Sound Marker that will be used in the playback. */ setDownSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void; /** * Used to manually set the frames that will be used for the different states of the Button. * * Frames can be specified as either an integer (the frame ID) or a string (the frame name); these are the same values that can be used with a Sprite constructor. * * @param overFrame The frame / frameName when the button is in the Over state. * @param outFrame The frame / frameName when the button is in the Out state. * @param downFrame The frame / frameName when the button is in the Down state. * @param upFrame The frame / frameName when the button is in the Up state. */ setFrames(overFrame?: string | number, outFrame?: string | number, downFrame?: string | number, upFrame?: string | number): void; /** * Internal function that handles input events. * * @param sprite The Button that the event occurred on. * @param pointer The Pointer that activated the Button. */ onInputOverHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void; /** * Internal function that handles input events. * * @param sprite The Button that the event occurred on. * @param pointer The Pointer that activated the Button. */ onInputOutHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void; /** * Internal function that handles input events. * * @param sprite The Button that the event occurred on. * @param pointer The Pointer that activated the Button. */ onInputDownHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void; /** * Internal function that handles input events. * * @param sprite The Button that the event occurred on. * @param pointer The Pointer that activated the Button. * @param isOver Is the Pointer still over the Game Object? */ onInputUpHandler(sprite: Phaser.Button, pointer: Phaser.Pointer, isOver: boolean): void; removedFromWorld(): void; /** * The Sound to be played when a Pointer moves out of this Button. * * @param sound The Sound that will be played. * @param marker A Sound Marker that will be used in the playback. */ setOutSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void; /** * The Sound to be played when a Pointer moves over this Button. * * @param sound The Sound that will be played. * @param marker A Sound Marker that will be used in the playback. */ setOverSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void; /** * Sets the sounds to be played whenever this Button is interacted with. Sounds can be either full Sound objects, or markers pointing to a section of a Sound object. * The most common forms of sounds are 'hover' effects and 'click' effects, which is why the order of the parameters is overSound then downSound. * * Call this function with no parameters to reset all sounds on this Button. * * @param overSound Over Button Sound. * @param overMarker Over Button Sound Marker. * @param downSound Down Button Sound. * @param downMarker Down Button Sound Marker. * @param outSound Out Button Sound. * @param outMarker Out Button Sound Marker. * @param upSound Up Button Sound. * @param upMarker Up Button Sound Marker. */ setSounds(overSound?: Phaser.Sound | Phaser.AudioSprite, overMarker?: string, downSound?: Phaser.Sound | Phaser.AudioSprite, downMarker?: string, outSound?: Phaser.Sound | Phaser.AudioSprite, outMarker?: string, upSound?: Phaser.Sound | Phaser.AudioSprite, upMarker?: string): void; setState(newState: number): void; /** * The Sound to be played when a Pointer has pressed down and is released from this Button. * * @param sound The Sound that will be played. * @param marker A Sound Marker that will be used in the playback. */ setUpSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void; } /** * Enumeration categorizing operational modes of pointers. * * PointerType values represent valid bitmasks. * For example, a value representing both Mouse and Touch devices * can be expressed as `PointerMode.CURSOR | PointerMode.CONTACT`. * * Values may be added for future mode categorizations. */ class PointerMode { /** * A 'CURSOR' is a pointer with a *passive cursor* such as a mouse, touchpad, watcom stylus, or even TV-control arrow-pad. * * It has the property that a cursor is passively moved without activating the input. * This currently corresponds with {@link Phaser.Pointer#isMouse} property. */ static CURSOR: number; /** * A 'CONTACT' pointer has an *active cursor* that only tracks movement when actived; notably this is a touch-style input. */ static CONTACT: number; } /** * Phaser has one single cache in which it stores all assets. * * The cache is split up into sections, such as images, sounds, video, json, etc. All assets are stored using * a unique string-based key as their identifier. Assets stored in different areas of the cache can have the * same key, for example 'playerWalking' could be used as the key for both a sprite sheet and an audio file, * because they are unique data types. * * The cache is automatically populated by the Phaser.Loader. When you use the loader to pull in external assets * such as images they are automatically placed into their respective cache. Most common Game Objects, such as * Sprites and Videos automatically query the cache to extract the assets they need on instantiation. * * You can access the cache from within a State via `this.cache`. From here you can call any public method it has, * including adding new entries to it, deleting them or querying them. * * Understand that almost without exception when you get an item from the cache it will return a reference to the * item stored in the cache, not a copy of it. Therefore if you retrieve an item and then modify it, the original * object in the cache will also be updated, even if you don't put it back into the cache again. * * By default when you change State the cache is _not_ cleared, although there is an option to clear it should * your game require it. In a typical game set-up the cache is populated once after the main game has loaded and * then used as an asset store. */ class Cache { /** * Phaser has one single cache in which it stores all assets. * * The cache is split up into sections, such as images, sounds, video, json, etc. All assets are stored using * a unique string-based key as their identifier. Assets stored in different areas of the cache can have the * same key, for example 'playerWalking' could be used as the key for both a sprite sheet and an audio file, * because they are unique data types. * * The cache is automatically populated by the Phaser.Loader. When you use the loader to pull in external assets * such as images they are automatically placed into their respective cache. Most common Game Objects, such as * Sprites and Videos automatically query the cache to extract the assets they need on instantiation. * * You can access the cache from within a State via `this.cache`. From here you can call any public method it has, * including adding new entries to it, deleting them or querying them. * * Understand that almost without exception when you get an item from the cache it will return a reference to the * item stored in the cache, not a copy of it. Therefore if you retrieve an item and then modify it, the original * object in the cache will also be updated, even if you don't put it back into the cache again. * * By default when you change State the cache is _not_ cleared, although there is an option to clear it should * your game require it. In a typical game set-up the cache is populated once after the main game has loaded and * then used as an asset store. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); static BINARY: number; static BITMAPDATA: number; static BITMAPFONT: number; static CANVAS: number; static IMAGE: number; static JSON: number; static PHYSICS: number; /** * The maximum amount of time (ms) to wait for the built-in DEFAULT and MISSING images to load. * Default: 1000 */ static READY_TIMEOUT: number; static RENDER_TEXTURE: number; static SHADER: number; static SOUND: number; static SPRITE_SHEET: number; static TEXT: number; static TEXTURE: number; static TEXTURE_ATLAS: number; static TILEMAP: number; static XML: number; static VIDEO: number; /** * The default image used for a texture when no other is specified. */ static DEFAULT: PIXI.Texture; /** * The default image used for a texture when the source image is missing. */ static MISSING: PIXI.Texture; /** * Automatically resolve resource URLs to absolute paths for use with the Cache.getURL method. */ autoResolveURL: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * Dispatched when the DEFAULT and MISSING images have loaded (or the {@link #READY_TIMEOUT load timeout} was exceeded). */ onReady: Phaser.Signal; /** * This event is dispatched when the sound system is unlocked via a touch event on cellular devices. */ onSoundUnlock: Phaser.Signal; /** * Add a binary object in to the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param binaryData The binary object to be added to the cache. */ addBinary(key: string, binaryData: any): void; /** * Add a BitmapData object to the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param bitmapData The BitmapData object to be addded to the cache. * @param frameData Optional FrameData set associated with the given BitmapData. If not specified (or `undefined`) a new FrameData object is created containing the Bitmap's Frame. If `null` is supplied then no FrameData will be created. - Default: (auto create) * @return The BitmapData object to be addded to the cache. */ addBitmapData(key: string, bitmapData: Phaser.BitmapData, frameData?: Phaser.FrameData): Phaser.BitmapData; /** * Add a new Bitmap Font to the Cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra font data. * @param atlasData The Bitmap Font data. * @param atlasType The format of the Bitmap Font data file: `json` or `xml`. - Default: 'xml' * @param xSpacing If you'd like to add additional horizontal spacing between the characters then set the pixel value here. * @param ySpacing If you'd like to add additional vertical spacing between the lines then set the pixel value here. */ addBitmapFont(key: string, url: string, data: any, atlasData: any, atlasType: string, xSpacing?: number, ySpacing?: number): void; /** * Add a new Bitmap Font to the Cache, where the font texture is part of a Texture Atlas. * * The atlas must already exist in the cache, and be available based on the given `atlasKey`. * * The `atlasFrame` specifies the name of the frame within the atlas that the Bitmap Font is * stored in. * * The `dataKey` is the key of the XML or JSON Bitmap Font Data, which must already be in * the Cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param atlasKey The key of the Texture Atlas in the Cache. * @param atlasFrame The frame of the Texture Atlas that the Bitmap Font is in. * @param dataKey The key of the Bitmap Font data in the Cache * @param dataType The format of the Bitmap Font data: `json` or `xml`. - Default: 'xml' * @param xSpacing If you'd like to add additional horizontal spacing between the characters then set the pixel value here. * @param ySpacing If you'd like to add additional vertical spacing between the lines then set the pixel value here. */ addBitmapFontFromAtlas(key: string, atlasKey: string, atlasFrame: string, dataKey: string, dataType?: string, xSpacing?: number, ySpacing?: number): void; /** * Add a new canvas object in to the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param canvas The Canvas DOM element. * @param context The context of the canvas element. If not specified it will default go `getContext('2d')`. */ addCanvas(key: string, canvas: HTMLCanvasElement, context?: CanvasRenderingContext2D): void; /** * Adds a default image to be used in special cases such as WebGL Filters. * It uses the special reserved key of `__default`. * This method is called automatically when the Cache is created. * This image is skipped when `Cache.destroy` is called due to its internal requirements. */ addDefaultImage(): void; /** * Adds an Image file into the Cache. The file must have already been loaded, typically via Phaser.Loader, but can also have been loaded into the DOM. * If an image already exists in the cache with the same key then it is removed and destroyed, and the new image inserted in its place. * * If the image has not yet been fetched (successfully or not), a `console.warn` message will be displayed. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra image data. * @return The full image object that was added to the cache. */ addImage(key: string, url: string, data: any): HTMLImageElement; /** * Add a new json object into the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra json data. */ addJSON(key: string, urL: string, data: any): void; /** * Adds an image to be used when a key is wrong / missing. * It uses the special reserved key of `__missing`. * This method is called automatically when the Cache is created. * This image is skipped when `Cache.destroy` is called due to its internal requirements. */ addMissingImage(): void; /** * Add a new physics data object to the Cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param JSONData The physics data object (a JSON file). * @param format The format of the physics data. */ addPhysicsData(key: string, url: string, JSONData: any, format: number): void; /** * Add a new Phaser.RenderTexture in to the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param texture The texture to use as the base of the RenderTexture. */ addRenderTexture(key: string, texture: RenderTexture): void; /** * Adds a Fragment Shader in to the Cache. The file must have already been loaded, typically via Phaser.Loader. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra shader data. */ addShader(key: string, url: string, data: any): void; /** * Adds a Sound file into the Cache. The file must have already been loaded, typically via Phaser.Loader. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra sound data. * @param webAudio True if the file is using web audio. * @param audioTag True if the file is using legacy HTML audio. */ addSound(key: string, url: string, data: any, webAudio: boolean, audioTag: boolean): void; /** * Add a new sprite sheet in to the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra sprite sheet data. * @param frameWidth Width of the sprite sheet. * @param frameHeight Height of the sprite sheet. * @param frameMax How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly. - Default: -1 * @param margin If the frames have been drawn with a margin, specify the amount here. * @param spacing If the frames have been drawn with spacing between them, specify the amount here. * @param skipFrames Skip a number of frames. Useful when there are multiple sprite sheets in one image. */ addSpriteSheet(key: string, url: string, data: any, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number, skipFrames?: number): void; /** * Add a new text data. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra text data. */ addText(key: string, url: string, data: any): void; /** * Add a new texture atlas to the Cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra texture atlas data. * @param atlasData Texture atlas frames data. * @param format The format of the texture atlas. */ addTextureAtlas(key: string, url: string, data: any, atlasData: any, format: number): void; /** * Add a new tilemap to the Cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param mapData The tilemap data object (either a CSV or JSON file). * @param format The format of the tilemap data. */ addTilemap(key: string, url: string, mapData: any, format: number): void; /** * Adds a Video file into the Cache. The file must have already been loaded, typically via Phaser.Loader. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra video data. * @param isBlob True if the file was preloaded via xhr and the data parameter is a Blob. false if a Video tag was created instead. */ addVideo(key: string, url: string, data: any, isBlob?: boolean): void; /** * Add a new xml object into the cache. * * @param key The key that this asset will be stored in the cache under. This should be unique within this cache. * @param url The URL the asset was loaded from. If the asset was not loaded externally set to `null`. * @param data Extra text data. */ addXML(key: string, url: string, data: any): void; /** * Checks if the given key exists in the Binary Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkBinaryKey(key: string): boolean; /** * Checks if the given key exists in the BitmapData Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkBitmapDataKey(key: string): boolean; /** * Checks if the given key exists in the BitmapFont Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkBitmapFontKey(key: string): boolean; /** * Checks if the given key exists in the Canvas Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkCanvasKey(key: string): boolean; /** * Checks if the given key exists in the Image Cache. Note that this also includes Texture Atlases, Sprite Sheets and Retro Fonts. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkImageKey(key: string): boolean; /** * Checks if the given key exists in the JSON Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkJSONKey(key: string): boolean; /** * Checks if a key for the given cache object type exists. * * @param cache The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. * @param key The key of the asset within the cache. * @return True if the key exists, otherwise false. */ checkKey(cache: number, key: string): boolean; /** * Checks if the given key exists in the Physics Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkPhysicsKey(key: string): boolean; /** * Checks if the given key exists in the Render Texture Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkRenderTextureKey(key: string): boolean; /** * Checks if the given key exists in the Fragment Shader Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkShaderKey(key: string): boolean; /** * Checks if the given key exists in the Sound Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkSoundKey(key: string): boolean; /** * Checks if the given key exists in the Text Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkTextKey(key: string): boolean; /** * Checks if the given key exists in the Texture Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkTextureKey(key: string): boolean; /** * Checks if the given key exists in the Tilemap Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkTilemapKey(key: string): boolean; /** * Checks if the given URL has been loaded into the Cache. * This method will only work if Cache.autoResolveURL was set to `true` before any preloading took place. * The method will make a DOM src call to the URL given, so please be aware of this for certain file types, such as Sound files on Firefox * which may cause double-load instances. * * @param url The url to check for in the cache. * @return True if the url exists, otherwise false. */ checkURL(url: string): any; checkUrl(url: string): any; /** * Checks if the given key exists in the XML Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkXMLKey(key: string): boolean; /** * Checks if the given key exists in the Video Cache. * * @param key The key of the asset within the cache. * @return True if the key exists in the cache, otherwise false. */ checkVideoKey(key: string): boolean; /** * Empties out all of the GL Textures from Images stored in the cache. * This is called automatically when the WebGL context is lost and then restored. */ clearGLTextures(): void; /** * Add a new decoded sound. * * @param key The key of the asset within the cache. * @param data Extra sound data. */ decodedSound(key: string, data: any): void; /** * Clears the cache. Removes every local cache object reference. * If an object in the cache has a `destroy` method it will be called; * otherwise, `destroy` will be called on any of the object's `base`, `data`, * `frameData`, or `texture` properties. */ destroy(): void; /** * Gets a PIXI.BaseTexture by key from the given Cache. * * @param key Asset key of the image for which you want the BaseTexture for. * @param cache The cache to search for the item in. - Default: Phaser.Cache.IMAGE * @return The BaseTexture object. */ getBaseTexture(key: string, cache?: number): PIXI.BaseTexture; /** * Gets a binary object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The binary data object. */ getBinary(key: string): any; /** * Gets a BitmapData object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The requested BitmapData object if found, or null if not. */ getBitmapData(key: string): Phaser.BitmapData; /** * Gets a Bitmap Font object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The requested BitmapFont object if found, or null if not. */ getBitmapFont(key: string): Phaser.BitmapFont; /** * Gets a Canvas object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The canvas object or `null` if no item could be found matching the given key. */ getCanvas(key: string): HTMLCanvasElement; /** * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. * * @param key Asset key of the frame data to retrieve from the Cache. * @param cache The cache to search for the item in. - Default: Phaser.Cache.IMAGE * @return The frame data. */ getFrame(key: string, cache?: number): Phaser.Frame; /** * Get a single frame out of a frameData set by key. * * @param key Asset key of the frame data to retrieve from the Cache. * @param index The index of the frame you want to get. * @param cache The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. - Default: Phaser.Cache.IMAGE * @return The frame object. */ getFrameByIndex(key: string, index: number, cache?: number): Phaser.Frame; /** * Get a single frame out of a frameData set by key. * * @param key Asset key of the frame data to retrieve from the Cache. * @param name The name of the frame you want to get. * @param cache The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. - Default: Phaser.Cache.IMAGE * @return The frame object. */ getFrameByName(key: string, name: string, cache?: number): Phaser.Frame; /** * Get the total number of frames contained in the FrameData object specified by the given key. * * @param key Asset key of the FrameData you want. * @param cache The cache to search for the item in. - Default: Phaser.Cache.IMAGE * @return Then number of frames. 0 if the image is not found. */ getFrameCount(key: string, cache?: number): number; /** * Gets a Phaser.FrameData object from the Image Cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key Asset key of the frame data to retrieve from the Cache. * @param cache The cache to search for the item in. - Default: Phaser.Cache.IMAGE * @return The frame data. */ getFrameData(key: string, cache?: number): Phaser.FrameData; /** * Gets a Image object from the cache. This returns a DOM Image object, not a Phaser.Image object. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * Only the Image cache is searched, which covers images loaded via Loader.image, Sprite Sheets and Texture Atlases. * * If you need the image used by a bitmap font or similar then please use those respective 'get' methods. * * @param key The key of the asset to retrieve from the cache. If not given or null it will return a default image. If given but not found in the cache it will throw a warning and return the missing image. * @param full If true the full image object will be returned, if false just the HTML Image object is returned. * @return The Image object if found in the Cache, otherwise `null`. If `full` was true then a JavaScript object is returned. */ getImage(key: string, full?: boolean): HTMLImageElement; /** * Get an item from a cache based on the given key and property. * * This method is mostly used internally by other Cache methods such as `getImage` but is exposed * publicly for your own use as well. * * @param key The key of the asset within the cache. * @param cache The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. * @param method The string name of the method calling getItem. Can be empty, in which case no console warning is output. * @param property If you require a specific property from the cache item, specify it here. * @return The cached item if found, otherwise `null`. If the key is invalid and `method` is set then a console.warn is output. */ getItem(key: string, cache: number, method?: string, property?: string): any; /** * Gets a JSON object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * You can either return the object by reference (the default), or return a clone * of it by setting the `clone` argument to `true`. * * @param key The key of the asset to retrieve from the cache. * @param clone Return a clone of the original object (true) or a reference to it? (false) * @return The JSON object, or an Array if the key points to an Array property. If the property wasn't found, it returns null. */ getJSON(key: string, clone?: boolean): any; /** * Gets all keys used in the requested Cache. * * @param cache The Cache you wish to get the keys from. Can be any of the Cache consts such as `Phaser.Cache.IMAGE`, `Phaser.Cache.SOUND` etc. - Default: Phaser.Cache.IMAGE * @return The array of keys in the requested cache. */ getKeys(cache: number): string[]; /** * Gets a Physics Data object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * You can get either the entire data set, a single object or a single fixture of an object from it. * * @param key The key of the asset to retrieve from the cache. * @param object If specified it will return just the physics object that is part of the given key, if null it will return them all. * @param fixtureKey Fixture key of fixture inside an object. This key can be set per fixture with the Phaser Exporter. * @return The requested physics object data if found. */ getPhysicsData(key: string, object?: string, fixtureKey?: string): any[]; /** * Gets a RenderTexture object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The object with Phaser.RenderTexture and Phaser.Frame. */ getRenderTexture(key: string): Phaser.CachedRenderTexture; /** * Gets a fragment shader object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The shader object. */ getShader(key: string): string; /** * Gets a Phaser.Sound object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The sound object. */ getSound(key: string): Phaser.Sound; /** * Gets a raw Sound data object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The sound data. */ getSoundData(key: string): any; getSpriteSheetKey(key: string): boolean; /** * Gets a Text object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The text data. */ getText(key: string): string; getTextKeys(): string[]; getTexture(key: string): Phaser.RenderTexture; getTextureAtlasKey(key: string): boolean; /** * Get a single texture frame by key. * * You'd only do this to get the default Frame created for a non-atlas / spritesheet image. * * @param key The key of the asset to retrieve from the cache. * @return The frame data. */ getTextureFrame(key: string): Phaser.Frame; getTilemap(key: string): any; /** * Gets a raw Tilemap data object from the cache. This will be in either CSV or JSON format. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The raw tilemap data in CSV or JSON format. */ getTilemapData(key: string): any; /** * Get a cached object by the URL. * This only returns a value if you set Cache.autoResolveURL to `true` *before* starting the preload of any assets. * Be aware that every call to this function makes a DOM src query, so use carefully and double-check for implications in your target browsers/devices. * * @param url The url for the object loaded to get from the cache. * @return The cached object. */ getURL(url: string): any; /** * Gets an XML object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The XML object. */ getXML(key: string): any; /** * Gets a Phaser.Video object from the cache. * * The object is looked-up based on the key given. * * Note: If the object cannot be found a `console.warn` message is displayed. * * @param key The key of the asset to retrieve from the cache. * @return The video object. */ getVideo(key: string): Phaser.Video; /** * Check if the FrameData for the given key exists in the Image Cache. * * @param key Asset key of the frame data to retrieve from the Cache. * @param cache The cache to search for the item in. - Default: Phaser.Cache.IMAGE * @return True if the given key has frameData in the cache, otherwise false. */ hasFrameData(key: string, cache?: number): boolean; /** * Check if the given sound has finished decoding. * * @param key The key of the asset within the cache. * @return The decoded state of the Sound object. */ isSoundDecoded(key: string): boolean; /** * Check if the given sound is ready for playback. * A sound is considered ready when it has finished decoding and the device is no longer touch locked. * * @param key The key of the asset within the cache. * @return True if the sound is decoded and the device is not touch locked. */ isSoundReady(key: string): boolean; isSpriteSheet(key: string): boolean; /** * Reload a Sound file from the server. * * @param key The key of the asset within the cache. */ reloadSound(key: string): void; /** * Fires the onSoundUnlock event when the sound has completed reloading. * * @param key The key of the asset within the cache. */ reloadSoundComplete(key: string): void; /** * Removes a binary file from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeBinary(key: string): void; /** * Removes a bitmap data from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeBitmapData(key: string): void; /** * Removes a bitmap font from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeBitmapFont(key: string): void; /** * Removes a canvas from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeCanvas(key: string): void; /** * Removes an image from the cache. * * You can optionally elect to destroy it as well. This calls BaseTexture.destroy on it. * * Note that this only removes it from the Phaser Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. * @param destroyBaseTexture Should the BaseTexture behind this image also be destroyed? - Default: true */ removeImage(key: string, destroyBaseTexture?: boolean): void; /** * Removes a json object from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeJSON(key: string): void; /** * Removes a physics data file from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removePhysics(key: string): void; /** * Removes a Render Texture from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeRenderTexture(key: string): void; /** * Removes a shader from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeShader(key: string): void; /** * Removes a sound from the cache. * * If any `Phaser.Sound` objects use the audio file in the cache that you remove with this method, they will * _automatically_ destroy themselves. If you wish to have full control over when Sounds are destroyed then * you must finish your house-keeping and destroy them all yourself first, before calling this method. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeSound(key: string): void; /** * Removes a Sprite Sheet from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeSpriteSheet(key: string): void; /** * Removes a text file from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeText(key: string): void; /** * Removes a Texture Atlas from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeTextureAtlas(key: string): void; /** * Removes a tilemap from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeTilemap(key: string): void; /** * Removes a xml object from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeXML(key: string): void; /** * Removes a video from the cache. * * Note that this only removes it from the Phaser.Cache. If you still have references to the data elsewhere * then it will persist in memory. * * @param key Key of the asset you want to remove. */ removeVideo(key: string): void; /** * Replaces a set of frameData with a new Phaser.FrameData object. * * @param key The unique key by which you will reference this object. * @param frameData The new FrameData. * @param cache The cache to search. One of the Cache consts such as `Phaser.Cache.IMAGE` or `Phaser.Cache.SOUND`. - Default: Phaser.Cache.IMAGE */ updateFrameData(key: string, frameData: any, cache?: number): void; /** * Updates the sound object in the cache. * * @param key The key of the asset within the cache. */ updateSound(key: string, property: string, value: Phaser.Sound): void; } interface CachedRenderTexture { frame: Phaser.Frame; texture: Phaser.RenderTexture; } /** * A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. * The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y */ class Camera { /** * A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. * The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y * * @param game Game reference to the currently running game. * @param id Not being used at the moment, will be when Phaser supports multiple camera * @param x Position of the camera on the X axis * @param y Position of the camera on the Y axis * @param width The width of the view rectangle * @param height The height of the view rectangle */ constructor(game: Phaser.Game, id: number, x: number, y: number, width: number, height: number); /** * A follow style that uses no deadzone. */ static FOLLOW_LOCKON: number; /** * A follow style that uses a tall, narrow deadzone (0.33 x 0.125) with a center slightly above the view center. */ static FOLLOW_PLATFORMER: number; /** * A follow style that uses a square deadzone (0.25 of the larger view edge). */ static FOLLOW_TOPDOWN: number; /** * A follow style that uses a small square deadzone (0.125 of the larger view edge). */ static FOLLOW_TOPDOWN_TIGHT: number; static SHAKE_BOTH: number; static SHAKE_HORIZONTAL: number; static SHAKE_VERTICAL: number; static ENABLE_FX: number; /** * Whether this camera is flush with the World Bounds or not. */ /** * The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras x position. */ /** * The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras y position. */ atLimit: { x: boolean; y: boolean; }; /** * The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World. * The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound * at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the top-left of the world. The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere. */ bounds: Phaser.Rectangle; /** * Moving inside this Rectangle will not cause the camera to move. */ deadzone: Phaser.Rectangle; /** * The display object to which all game objects are added. Set by World.boot. */ displayObject: PIXI.DisplayObject; /** * Reserved for future multiple camera set-ups. */ id: number; /** * Immobile {@link Phaser.Camera#view view} rectangle. Its top-left is always (0, 0). You can use this align fixedToCamera objects. */ fixedView: Phaser.Rectangle; /** * The Graphics object used to handle camera fx such as fade and flash. */ fx: Phaser.Graphics; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The Cameras height. By default this is the same as the Game size and should not be adjusted for now. Gets or sets the cameras height. */ height: number; /** * The linear interpolation value to use when following a target. * The default values of 1 means the camera will instantly snap to the target coordinates. * A lower value, such as 0.1 means the camera will more slowly track the target, giving * a smooth transition. You can set the horizontal and vertical values independently, and also * adjust this value in real-time during your game. */ lerp: Phaser.Point; /** * The Cameras position. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras xy position using Phaser.Point object. */ position: Phaser.Point; /** * If a Camera has roundPx set to `true` it will call `view.floor` as part of its update loop, keeping its boundary to integer values. Set this to `false` to disable this from happening. * Default: true */ roundPx: boolean; /** * The scale of the display object to which all game objects are added. Set by World.boot. */ scale: Phaser.Point; /** * The Cameras shake intensity. Gets or sets the cameras shake intensity. */ shakeIntensity: number; /** * This signal is dispatched when the camera fade effect (fade in or fade out) completes. * You can look at the value of `Camera.fx.alpha` to determine which effect it was. * When the fade out effect completes `Camera.fx.alpha` is 1 and you will be left with the screen black (or whatever * color you faded to). In order to reset this call `Camera.resetFX`. `Camera.resetFX` is called automatically when you change State. * When the fade in effect completes, `Camera.fx.alpha` is 0 and there is no visible camera fill. */ onFadeComplete: Phaser.Signal; /** * This signal is dispatched when the camera flash effect completes. */ onFlashComplete: Phaser.Signal; /** * This signal is dispatched when the camera shake effect completes. */ onShakeComplete: Phaser.Signal; /** * If the camera is tracking a Sprite, this is a reference to it, otherwise null. */ target: Phaser.Sprite; /** * The total number of Sprites with `autoCull` set to `true` that are visible by this Camera. */ totalInView: number; /** * Camera view. * The view into the world we wish to render (by default the game dimensions). * The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render. * Sprites outside of this view are not rendered if Sprite.autoCull is set to `true`. Otherwise they are always rendered. */ view: Phaser.Rectangle; /** * Whether this camera is visible or not. * Default: true */ visible: boolean; /** * The Cameras width. By default this is the same as the Game size and should not be adjusted for now. Gets or sets the cameras width. */ width: number; /** * A reference to the game world. */ world: Phaser.World; /** * The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras x position. */ x: number; /** * The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras y position. */ y: number; /** * Method called to ensure the camera doesn't venture outside of the game world. * Called automatically by Camera.update. */ checkBounds(): void; /** * This creates a camera fade out effect. It works by filling the game with the * color specified, over the duration given, ending with a solid fill. * * You can use this for things such as transitioning to a new scene. * * The game will be left 'filled' at the end of this effect, likely obscuring * everything. In order to reset it you can call `Camera.resetFX` and it will clear the * fade. Or you can call `Camera.flash` with the same color as the fade, and it will * reverse the process, bringing the game back into view again. * * When the effect ends the signal Camera.onFadeComplete is dispatched. * * @param color The color the game will fade to. I.e. 0x000000 for black, 0xff0000 for red, etc. - Default: 0x000000 * @param duration The duration of the fade in milliseconds. - Default: 500 * @param force If a camera flash or fade effect is already running and force is true it will replace the previous effect, resetting the duration. * @param alpha The alpha value of the color applied to the fade effect. - Default: 1 * @return True if the effect was started, otherwise false. */ fade(color?: number, duration?: number, force?: boolean, alpha?: number): boolean; /** * This creates a camera flash effect. It works by filling the game with the solid fill * color specified, and then fading it away to alpha 0 over the duration given. * * You can use this for things such as hit feedback effects. * * When the effect ends the signal Camera.onFlashComplete is dispatched. * * @param color The color of the flash effect. I.e. 0xffffff for white, 0xff0000 for red, etc. - Default: 0xffffff * @param duration The duration of the flash effect in milliseconds. - Default: 500 * @param force If a camera flash or fade effect is already running and force is true it will replace the previous effect, resetting the duration. * @param alpha The alpha value of the color applied to the flash effect. - Default: 1 * @return True if the effect was started, otherwise false. */ flash(color?: number, duration?: number, force?: boolean, alpha?: number): boolean; /** * Move the camera focus on a display object instantly. * * @param displayObject The display object to focus the camera on. Must have visible x/y properties. */ focusOn(displayObject: PIXI.DisplayObject): void; /** * Move the camera focus on a location instantly. * * @param x X position. * @param y Y position. */ focusOnXY(x: number, y: number): void; /** * Tell the camera which sprite to follow. * * You can set the follow type and a linear interpolation value. * Use low lerp values (such as 0.1) to automatically smooth the camera motion. * * If you find you're getting a slight "jitter" effect when following a Sprite it's probably to do with sub-pixel rendering of the Sprite position. * This can be disabled by setting `game.renderer.renderSession.roundPixels = true` to force full pixel rendering. * * @param target The object you want the camera to track. Set to null to not follow anything. * @param style Leverage one of the existing {@link deadzone} presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow(). * @param lerpX A value between 0 and 1. This value specifies the amount of linear interpolation to use when horizontally tracking the target. The closer the value to 1, the faster the camera will track. - Default: 1 * @param lerpY A value between 0 and 1. This value specifies the amount of linear interpolation to use when vertically tracking the target. The closer the value to 1, the faster the camera will track. - Default: 1 */ follow(target: Phaser.Sprite, style?: number, lerpX?: number, lerpY?: number): void; /** * Resets the camera back to 0,0 and un-follows any object it may have been tracking. * Also immediately resets any camera effects that may have been running such as * shake, flash or fade. */ reset(): void; /** * Resets any active FX, such as a fade or flash and immediately clears it. * Useful to calling after a fade in order to remove the fade from the Stage. */ resetFX(): void; /** * Update the Camera bounds to match the game world. */ setBoundsToWorld(): void; /** * A helper function to set both the X and Y properties of the camera at once * without having to use game.camera.x and game.camera.y. * * @param x X position. * @param y Y position. */ setPosition(x: number, y: number): void; /** * Sets the size of the view rectangle given the width and height in parameters. * * @param width The desired width. * @param height The desired height. */ setSize(width: number, height: number): void; /** * This creates a camera shake effect. It works by applying a random amount of additional * spacing on the x and y axis each frame. You can control the intensity and duration * of the effect, and if it should effect both axis or just one. * * When the shake effect ends the signal Camera.onShakeComplete is dispatched. * * @param intensity The intensity of the camera shake. Given as a percentage of the camera size representing the maximum distance that the camera can move while shaking. - Default: 0.05 * @param duration The duration of the shake effect in milliseconds. - Default: 500 * @param force If a camera shake effect is already running and force is true it will replace the previous effect, resetting the duration. - Default: true * @param direction The directions in which the camera can shake. Either Phaser.Camera.SHAKE_BOTH, Phaser.Camera.SHAKE_HORIZONTAL or Phaser.Camera.SHAKE_VERTICAL. - Default: Phaser.Camera.SHAKE_BOTH * @param shakeBounds Is the effect allowed to shake the camera beyond its bounds (if set?). - Default: true * @return True if the shake effect was started, otherwise false. */ shake(intensity?: number, duration?: number, force?: boolean, direction?: number, shakeBounds?: boolean): boolean; /** * Sets the Camera follow target to null, stopping it from following an object if it's doing so. */ unfollow(): void; /** * The camera update loop. This is called automatically by the core game loop. */ update(): void; } /** * The Canvas class handles everything related to creating the `canvas` DOM tag that Phaser will use, * including styles, offset and aspect ratio. */ class Canvas { /** * Adds the given canvas element to the DOM. The canvas will be added as a child of the given parent. * If no parent is given it will be added as a child of the document.body. * * @param canvas The canvas to be added to the DOM. * @param parent The DOM element to add the canvas to. * @param overflowHidden If set to true it will add the overflow='hidden' style to the parent DOM element. - Default: true * @return Returns the source canvas. */ static addToDOM(canvas: HTMLCanvasElement, parent: HTMLElement, overflowHidden?: boolean): HTMLCanvasElement; /** * Creates a `canvas` DOM element. The element is not automatically added to the document. * * @param parent The object that will own the canvas that is created. * @param width The width of the canvas element. - Default: 256 * @param height The height of the canvas element.. - Default: 256 * @param id If specified, and not the empty string, this will be set as the ID of the canvas element. Otherwise no ID will be set. - Default: (none) * @param skipPool If `true` the canvas will not be placed in the CanvasPool global. * @return The newly created canvas element. */ static create(parent: HTMLDivElement, width?: number, height?: number, id?: string, skipPool?: boolean): HTMLCanvasElement; /** * Returns `true` if the given context has image smoothing enabled, otherwise returns `false`. * * @param context The context to check for smoothing on. * @return True if the given context has image smoothing enabled, otherwise false. */ static getSmoothingEnabled(context: CanvasRenderingContext2D): boolean; /** * Gets the Smoothing Enabled vendor prefix being used on the given context, or null if not set. * * @param context The context to enable or disable the image smoothing on. * @return Returns the smoothingEnabled vendor prefix, or null if not set on the context. */ static getSmoothingPrefix(context: CanvasRenderingContext2D): string; /** * Removes the given canvas element from the DOM. * * @param canvas The canvas to be removed from the DOM. */ static removeFromDOM(canvas: HTMLCanvasElement): void; /** * Sets the background color behind the canvas. This changes the canvas style property. * * @param canvas The canvas to set the background color on. * @param color The color to set. Can be in the format 'rgb(r,g,b)', or '#RRGGBB' or any valid CSS color. - Default: 'rgb(0,0,0)' * @return Returns the source canvas. */ static setBackgroundColor(canvas: HTMLCanvasElement, color: string): HTMLCanvasElement; /** * Sets the CSS image-rendering property on the given canvas to be 'bicubic' (aka 'auto'). * Note that if this doesn't given the desired result then see the CanvasUtils.setSmoothingEnabled method. * * @param canvas The canvas to set image-rendering bicubic on. * @return Returns the source canvas. */ static setImageRenderingBicubic(canvas: HTMLCanvasElement): HTMLCanvasElement; /** * Sets the CSS image-rendering property to `pixelated` or `crisp-edges`. * This can remove blurring when the game canvas is scaled up. * In some browsers this has no visible effect in WEBGL mode. * Note that if this doesn't given the desired result then see the setSmoothingEnabled. * * @param canvas The canvas to set image-rendering crisp on. * @return Returns the source canvas. */ static setImageRenderingCrisp(canvas: HTMLCanvasElement): HTMLCanvasElement; /** * Sets the Image Smoothing property on the given context. Set to false to disable image smoothing. * By default browsers have image smoothing enabled, which isn't always what you visually want, especially * when using pixel art in a game. Note that this sets the property on the context itself, so that any image * drawn to the context will be affected. This sets the property across all current browsers but support is * patchy on earlier browsers, especially on mobile. * * @param context The context to enable or disable the image smoothing on. * @param value If set to true it will enable image smoothing, false will disable it. * @return Returns the source context. */ static setSmoothingEnabled(context: CanvasRenderingContext2D, value: boolean): CanvasRenderingContext2D; /** * Sets the touch-action property on the canvas style. Can be used to disable default browser touch actions. * * @param canvas The canvas to set the touch action on. * @param value The touch action to set. Defaults to 'none'. * @return The source canvas. */ static setTouchAction(canvas: HTMLCanvasElement, value: string): HTMLCanvasElement; /** * Sets the transform of the given canvas to the matrix values provided. * * @param context The context to set the transform on. * @param translateX The value to translate horizontally by. * @param translateY The value to translate vertically by. * @param scaleX The value to scale horizontally by. * @param scaleY The value to scale vertically by. * @param skewX The value to skew horizontaly by. * @param skewY The value to skew vertically by. * @return Returns the source context. */ static setTransform(context: CanvasRenderingContext2D, translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): CanvasRenderingContext2D; /** * Sets the user-select property on the canvas style. Can be used to disable default browser selection actions. * * @param canvas The canvas to set the touch action on. * @param value The touch action to set. Defaults to 'none'. * @return The source canvas. */ static setUserSelect(canvas: HTMLCanvasElement, value?: string): HTMLCanvasElement; } /** * The CanvasPool is a global static object, that allows Phaser to recycle and pool Canvas DOM elements. */ export class CanvasPool { /** * Creates a new Canvas DOM element, or pulls one from the pool if free. * * @param parent The parent of the canvas element. * @param width The width of the canvas element. * @param height The height of the canvas element. * @return The canvas element. */ static create(parent: HTMLElement, width?: number, height?: number): HTMLCanvasElement; /** * Gets the first free canvas index from the pool. */ static getFirst(): HTMLCanvasElement; /** * Looks up a canvas based on its parent, and if found puts it back in the pool, freeing it up for re-use. * The canvas has its width and height set to 1, and its parent attribute nulled. * * @param parent The parent of the canvas element. */ static remove(parent: HTMLElement): void; /** * Looks up a canvas based on its type, and if found puts it back in the pool, freeing it up for re-use. * The canvas has its width and height set to 1, and its parent attribute nulled. * * @param canvas The canvas element to remove. */ static removeByCanvas(canvas: HTMLCanvasElement): HTMLCanvasElement; /** * Gets the total number of used canvas elements in the pool. * @return The number of in-use (parented) canvas elements in the pool. */ static getTotal(): number; /** * Gets the total number of free canvas elements in the pool. * @return The number of free (un-parented) canvas elements in the pool. */ static getFree(): number; static length: number; /** * Prints in-use, free, and total counts to console.log. */ static log(): void; } /** * Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. * If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created. */ class Circle { /** * Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. * If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created. * * @param x The x coordinate of the center of the circle. * @param y The y coordinate of the center of the circle. * @param diameter The diameter of the circle. */ constructor(x?: number, y?: number, diameter?: number); /** * The area of this Circle. */ area: number; /** * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter. Gets or sets the bottom of the circle. */ bottom: number; /** * The largest distance between any two points on the circle. The same as the radius * 2. Gets or sets the diameter of the circle. */ diameter: number; /** * Determines whether or not this Circle object is empty. Will return a value of true if the Circle objects diameter is less than or equal to 0; otherwise false. * If set to true it will reset all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0. Gets or sets the empty state of the circle. */ empty: boolean; /** * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. */ left: number; /** * The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter. Gets or sets the radius of the circle. */ radius: number; /** * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. Gets or sets the value of the rightmost point of the circle. */ right: number; /** * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter. Gets or sets the top of the circle. */ top: number; /** * The x coordinate of the center of the circle. */ x: number; /** * The y coordinate of the center of the circle. */ y: number; /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. * * @param angle The angle in radians (unless asDegrees is true) to return the point from. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @param out An optional Point object to put the result in to. If none specified a new Point object will be created. * @return The Point object holding the result. */ static circumferencePoint(a: Phaser.Circle, angle: number, asDegrees: boolean, out?: Phaser.Point): Phaser.Point; /** * Return true if the given x/y coordinates are within this Circle object. * * @param x The X value of the coordinate to test. * @param y The Y value of the coordinate to test. * @return True if the coordinates are within this circle, otherwise false. */ static contains(a: Phaser.Circle, x: number, y: number): boolean; /** * Determines whether the two Circle objects match. This method compares the x, y and diameter properties. * * @param a The first Circle object. * @param b The second Circle object. * @return A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false. */ static equals(a: Phaser.Circle, b: Phaser.Circle): boolean; /** * Determines whether the two Circle objects intersect. * This method checks the radius distances between the two Circle objects to see if they intersect. * * @param a The first Circle object. * @param b The second Circle object. * @return A value of true if the specified object intersects with this Circle object; otherwise false. */ static intersects(a: Phaser.Circle, b: Phaser.Circle): boolean; /** * Checks if the given Circle and Rectangle objects intersect. * * @param c The Circle object to test. * @param r The Rectangle object to test. * @return True if the two objects intersect, otherwise false. */ static intersectsRectangle(c: Phaser.Circle, r: Phaser.Rectangle): boolean; /** * The circumference of the circle. * @return The circumference of the circle. */ circumference(): number; /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. * * @param angle The angle in radians (unless asDegrees is true) to return the point from. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @param out An optional Point object to put the result in to. If none specified a new Point object will be created. * @return The Point object holding the result. */ circumferencePoint(angle: number, asDegrees?: boolean, out?: Phaser.Point): Phaser.Point; /** * Returns a new Circle object with the same values for the x, y, width, and height properties as this Circle object. * * @param output Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned. * @return The cloned Circle object. */ clone(output?: Phaser.Circle): Phaser.Circle; /** * Return true if the given x/y coordinates are within this Circle object. * * @param x The X value of the coordinate to test. * @param y The Y value of the coordinate to test. * @return True if the coordinates are within this circle, otherwise false. */ contains(x: number, y: number): boolean; /** * Copies the x, y and diameter properties from any given object to this Circle. * * @param source The object to copy from. * @return This Circle object. */ copyFrom(source: any): Circle; /** * Copies the x, y and diameter properties from this Circle to any given object. * * @param dest The object to copy to. * @return This dest object. */ copyTo(dest: any): any; /** * Returns the distance from the center of the Circle object to the given object * (can be Circle, Point or anything with x/y properties) * * @param dest The target object. Must have visible x and y properties that represent the center of the object. * @param round Round the distance to the nearest integer. * @return The distance between this Point object and the destination Point object. */ distance(dest: any, round?: boolean): number; /** * Returns the framing rectangle of the circle as a Phaser.Rectangle object. * @return The bounds of the Circle. */ getBounds(): Phaser.Rectangle; /** * Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts. * * @param dx Moves the x value of the Circle object by this amount. * @param dy Moves the y value of the Circle object by this amount. * @return This Circle object. */ offset(dx: number, dy: number): Phaser.Circle; /** * Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter. * * @param point A Point object to use to offset this Circle object (or any valid object with exposed x and y properties). * @return This Circle object. */ offsetPoint(point: Phaser.Point): Phaser.Circle; /** * Returns a uniformly distributed random point from anywhere within this Circle. * * @param out A Phaser.Point, or any object with public x/y properties, that the values will be set in. * If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object. * @return An object containing the random point in its `x` and `y` properties. */ random(out?: Phaser.Point): Phaser.Point; /** * Creates or positions points on the circle. * * The points are equally distributed in the half-closed interval [startAngle, endAngle). The default arc is the entire circle. * * If the `out` argument is omitted, this method creates and returns an array of {@link Phaser.Point points}. If an array is passed as `out`, its items are treated as points and placed in the same way. * * @param steps The number of points to place. - Default: 60 * @param startAngle The starting angle in radians (unless asDegrees is true). * @param endAngle The end angle in radians (unless asDegrees is true). - Default: Phaser.Math.PI2 * @param asDegrees Are the given angles in radians (false) or degrees (true)? * @param out An array of points or point-like objects (e.g., sprites). It should start at index 0 and its length should be equal to or greater than `steps`. * @return - The modified `out` argument or a new array of points. */ sample(steps?: number, startAngle?: number, endAngle?: number, asDegrees?: boolean, out?: any[]): any[]; scale(x: number, y?: number): Phaser.Rectangle; /** * Sets the members of Circle to the specified values. * * @param x The x coordinate of the center of the circle. * @param y The y coordinate of the center of the circle. * @param diameter The diameter of the circle. * @return This circle object. */ setTo(x: number, y: number, diameter: number): Circle; /** * Returns a string representation of this object. * @return a string representation of the instance. */ toString(): string; } /** * The Phaser.Color class is a set of static methods that assist in color manipulation and conversion. */ class Color { /** * Aqua (0x00ffff) * Default: 65535 */ static AQUA: number; /** * Black (0x000000) */ static BLACK: number; /** * Blue (0x0000ff) * Default: 255 */ static BLUE: number; /** * Gray (0x666666) * Default: 6710886 */ static GRAY: number; /** * Green (0x00ff00) * Default: 65280 */ static GREEN: number; /** * Orange (0xff9900) * Default: 16750848 */ static ORANGE: number; /** * Red (0xff0000) * Default: 16711680 */ static RED: number; /** * Violet/purple (0xff00ff) * Default: 16711935 */ static VIOLET: number; /** * White (0xffffff) * Default: 16777215 */ static WHITE: number; /** * Yellow (0xffff00) * Default: 16776960 */ static YELLOW: number; /** * Return 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. * @return A string of length 2 characters, i.e. 255 = ff, 100 = 64. */ static componentToHex(color: number): string; /** * A utility function to create a lightweight 'color' object with the default components. * Any components that are not specified will default to zero. * * This is useful when you want to use a shared color object for the getPixel and getPixelAt methods. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 1. - Default: 1 * @param h The hue, in the range 0 - 1. * @param s The saturation, in the range 0 - 1. * @param l The lightness, in the range 0 - 1. * @param v The value, in the range 0 - 1. * @return The resulting object with r, g, b, a properties and h, s, l and v. */ static createColor(r?: number, g?: number, b?: number, a?: number, h?: number, s?: number, l?: number, v?: number): ColorComponents; /** * A utility to convert an integer in 0xRRGGBBAA format to a color object. * This does not rely on endianness. * * @param rgba An RGBA hex * @param out The object to use, optional. * @return A color object. */ static fromRGBA(rgba: number, out?: ColorComponents): ColorComponents; /** * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255. * * @param color In the format 0xAARRGGBB. * @return The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)). */ static getAlpha(color: number): number; /** * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1. * * @param color In the format 0xAARRGGBB. * @return The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)). */ static getAlphaFloat(color: number): number; /** * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255. * * @param color In the format 0xAARRGGBB. * @return The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue). */ static getBlue(color: number): number; /** * Given 3 color values this will return an integer representation of it. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @return A native color value integer (format: 0xRRGGBB). */ static getColor(red: number, green: number, blue: number): number; /** * Given an alpha and 3 color values this will return an integer representation of it. * * @param a The alpha color component, in the range 0 - 255. * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @return A native color value integer (format: 0xAARRGGBB). */ static getColor32(alpha: number, red: number, green: number, blue: number): number; /** * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255. * * @param color In the format 0xAARRGGBB. * @return The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green). */ static getGreen(color: number): number; /** * Returns a random color value between black and white * Set the min value to start each channel from the given offset. * Set the max value to restrict the maximum color used per channel. * * @param min The lowest value to use for the color. * @param max The highest value to use for the color. - Default: 255 * @param alpha The alpha value of the returning color (default 255 = fully opaque). - Default: 255 * @return 32-bit color value with alpha. */ static getRandomColor(min?: number, max?: number, alpha?: number): number; /** * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255. * * @param color In the format 0xAARRGGBB. * @return The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red). */ static getRed(color: number): number; /** * Return the component parts of a color as an Object with the properties alpha, red, green, blue. * * Alpha will only be set if it exist in the given color (0xAARRGGBB) * * @param color Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB). * @return An Object with properties: alpha, red, green, blue (also r, g, b and a). Alpha will only be present if a color value > 16777215 was given. */ static getRGB(color: number): RGBColor; /** * Returns a CSS friendly string value from the given color. * * @param color Color in RGB (0xRRGGBB), ARGB format (0xAARRGGBB) or an Object with r, g, b, a properties. * @return A string in the format: 'rgba(r,g,b,a)' */ static getWebRGB(color: number | RGBColor): string; /** * Converts a hex color value to an [R, G, B] array. * * @param color The color to convert to an RGB array. In the format 0xRRGGBB. * @return An array with element 0 containing the Red value, 1 containing Green, and 2 containing Blue. */ static hexToRGBArray(color: number): number[]; /** * Converts a hex string into an integer color value. * * @param hex The hex string to convert. Can be in the short-hand format `#03f` or `#0033ff`. * @return The rgb color value in the format 0xAARRGGBB. */ static hexToRGB(h: string): number; /** * Converts a hex string into a Phaser Color object. * * The hex string can supplied as `'#0033ff'` or the short-hand format of `'#03f'`; it can begin with an optional "#" or "0x", or be unprefixed. * * An alpha channel is _not_ supported. * * @param hex The color string in a hex format. * @param out An object into which 3 properties will be created or set: r, g and b. If not provided a new object will be created. * @return An object with the red, green and blue values set in the r, g and b properties. */ static hexToColor(hex: string, out?: ColorComponents): ColorComponents; /** * Converts an HSL (hue, saturation and lightness) color value to RGB. * Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes HSL values are contained in the set [0, 1] and returns r, g and b values in the set [0, 255]. * Based on code by Michael Jackson (https://github.com/mjijackson) * * @param h The hue, in the range 0 - 1. * @param s The saturation, in the range 0 - 1. * @param l The lightness, in the range 0 - 1. * @param out An object into which 3 properties will be created: r, g and b. If not provided a new object will be created. * @return An object with the red, green and blue values set in the r, g and b properties. */ static HSLtoRGB(h: number, s: number, l: number, out?: ColorComponents): ColorComponents; /** * Get HSL color wheel values in an array which will be 360 elements in size. * * @param s The saturation, in the range 0 - 1. - Default: 0.5 * @param l The lightness, in the range 0 - 1. - Default: 0.5 * @return An array containing 360 elements corresponding to the HSL color wheel. */ static HSLColorWheel(s?: number, l?: number): ColorComponents[]; /** * Converts an HSV (hue, saturation and value) color value to RGB. * Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes HSV values are contained in the set [0, 1] and returns r, g and b values in the set [0, 255]. * Based on code by Michael Jackson (https://github.com/mjijackson) * * @param h The hue, in the range 0 - 1. * @param s The saturation, in the range 0 - 1. * @param v The value, in the range 0 - 1. * @param out An object into which 3 properties will be created: r, g and b. If not provided a new object will be created. * @return An object with the red, green and blue values set in the r, g and b properties. */ static HSVtoRGB(h: number, s: number, v: number, out?: ColorComponents): ColorComponents; /** * Get HSV color wheel values in an array which will be 360 elements in size. * * @param s The saturation, in the range 0 - 1. - Default: 1 * @param v The value, in the range 0 - 1. - Default: 1 * @return An array containing 360 elements corresponding to the HSV color wheel. */ static HSVColorWheel(s?: number, v?: number): ColorComponents[]; /** * Converts a hue to an RGB color. * Based on code by Michael Jackson (https://github.com/mjijackson) * * @param p * @param q * @param t * @return The color component value. */ static hueToColor(p: number, q: number, t: number): number; /** * Interpolates the two given colours based on the supplied step and currentStep properties. * * @param color1 The first color value. * @param color2 The second color value. * @param steps The number of steps to run the interpolation over. * @param currentStep The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two. * @param alpha The alpha of the returned color. * @param colorSpace The color space to interpolate in. 0 = RGB, 1 = HSV. * @return The interpolated color value. */ static interpolateColor(color1: number, color2: number, steps: number, currentStep: number, alpha?: number, colorSpace?: number): number; /** * Interpolates the two given colours based on the supplied step and currentStep properties. * * @param color The first color value. * @param r The red color value, between 0 and 0xFF (255). * @param g The green color value, between 0 and 0xFF (255). * @param b The blue color value, between 0 and 0xFF (255). * @param steps The number of steps to run the interpolation over. * @param currentStep The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two. * @return The interpolated color value. */ static interpolateColorWithRGB(color: number, r: number, g: number, b: number, steps: number, currentStep: number): number; /** * Interpolates the two given colours based on the supplied step and currentStep properties. * * @param r1 The red color value, between 0 and 0xFF (255). * @param g1 The green color value, between 0 and 0xFF (255). * @param b1 The blue color value, between 0 and 0xFF (255). * @param r2 The red color value, between 0 and 0xFF (255). * @param g2 The green color value, between 0 and 0xFF (255). * @param b2 The blue color value, between 0 and 0xFF (255). * @param steps The number of steps to run the interpolation over. * @param currentStep The currentStep value. If the interpolation will take 100 steps, a currentStep value of 50 would be half-way between the two. * @return The interpolated color value. */ static interpolateRGB(r1: number, g1: number, b1: number, r2: number, g2: number, b2: number, steps: number, currentStep: number): number; /** * Calculates a linear (interpolation) value of two colors over t. * * This is a slightly simpler interface to {@link Phaser.Color.interpolateColor}. * * The arguments are similar to {@link Phaser.Math.linear}. * * @param color1 The first color value. * @param color2 The second color value. * @param t A value between 0 and 1. * @return The interpolated color value. */ static linear(color1: number, color2: number, t: number): number; /** * Calculates a linear (interpolation) value of an array of colors over t. * * The arguments are similar to {@link Phaser.Math.linearInterpolation}. * * This can be used as a {@link Phaser.TweenData#interpolationFunction}. * * @param colors The input array of color values to interpolate between. * @param t The amount of interpolation, between 0 (start) and 1 (end). * @return The interpolated color value. */ static linearInterpolation(colors: number[], t: number): number; /** * Packs the r, g, b, a components into a single integer, for use with Int32Array. * If device is little endian then ABGR order is used. Otherwise RGBA order is used. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 255. * @return The packed color as uint32 */ static packPixel(r: number, g: number, b: number, a: number): number; /** * Converts an RGB color array, in the format: [R, G, B], to a hex color value. * * @param rgb An array with element 0 containing the Red value, 1 containing Green, and 2 containing Blue. * @return The color value, in the format 0xRRGGBB. */ static RGBArrayToHex(rgb: number[]): number; /** * Converts an RGB color value to HSL (hue, saturation and lightness). * Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes RGB values are contained in the set [0, 255] and returns h, s and l in the set [0, 1]. * Based on code by Michael Jackson (https://github.com/mjijackson) * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param out An object into which 3 properties will be created, h, s and l. If not provided a new object will be created. * @return An object with the hue, saturation and lightness values set in the h, s and l properties. */ static RGBtoHSL(r: number, g: number, b: number, out?: ColorComponents): ColorComponents; /** * Converts an RGB color value to HSV (hue, saturation and value). * Conversion forumla from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes RGB values are contained in the set [0, 255] and returns h, s and v in the set [0, 1]. * Based on code by Michael Jackson (https://github.com/mjijackson) * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param out An object into which 3 properties will be created, h, s and v. If not provided a new object will be created. * @return An object with the hue, saturation and value set in the h, s and v properties. */ static RGBtoHSV(r: number, g: number, b: number, out?: ColorComponents): ColorComponents; /** * Converts the given color values into a string. * If prefix was '#' it will be in the format `#RRGGBB` otherwise `0xAARRGGBB`. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 255. - Default: 255 * @param prefix The prefix used in the return string. If '#' it will return `#RRGGBB`, else `0xAARRGGBB`. - Default: '#' * @return A string containing the color values. If prefix was '#' it will be in the format `#RRGGBB` otherwise `0xAARRGGBB`. */ static RGBtoString(r: number, g: number, b: number, a?: number, prefix?: string): string; /** * A utility to convert RGBA components to a 32 bit integer in RRGGBBAA format. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 255. * @return A RGBA-packed 32 bit integer */ static toRGBA(r: number, g: number, b: number, a: number): number; /** * Converts RGBA components to a 32 bit integer in AABBGGRR format. * * @param r The red color component, in the range 0 - 255. * @param g The green color component, in the range 0 - 255. * @param b The blue color component, in the range 0 - 255. * @param a The alpha color component, in the range 0 - 255. * @return A RGBA-packed 32 bit integer */ static toABGR(r: number, g: number, b: number, a: number): number; /** * Unpacks the r, g, b, a components into the specified color object, or a new * object, for use with Int32Array. If little endian, then ABGR order is used when * unpacking, otherwise, RGBA order is used. The resulting color object has the * `r, g, b, a` properties which are unrelated to endianness. * * Note that the integer is assumed to be packed in the correct endianness. On little-endian * the format is 0xAABBGGRR and on big-endian the format is 0xRRGGBBAA. If you want a * endian-independent method, use fromRGBA(rgba) and toRGBA(r, g, b, a). * * @param rgba The integer, packed in endian order by packPixel. * @param out An object into which 3 properties will be created: r, g and b. If not provided a new object will be created. * @param hsl Also convert the rgb values into hsl? * @param hsv Also convert the rgb values into hsv? * @return An object with the red, green and blue values set in the r, g and b properties. */ static unpackPixel(rgba: number, out?: ColorComponents, hsl?: boolean, hsv?: boolean): ColorComponents; /** * Takes a color object and updates the rgba, color and color32 properties. * * @param out The color object to update. * @return A native color value integer (format: 0xAARRGGBB). */ static updateColor(out: ColorComponents): ColorComponents; /** * Converts a value - a "hex" string, a "CSS 'web' string", or a number - into red, green, blue, and alpha components. * * The value can be a string (see `hexToColor` and `webToColor` for the supported formats) or a packed integer (see `getRGB`). * * An alpha channel is _not_ supported when specifying a hex string. * * @param value The color expressed as a recognized string format or a packed integer. * @param out The object to use for the output. If not provided a new object will be created. * @return The (`out`) object with the red, green, blue, and alpha values set as the r/g/b/a properties. */ static valueToColor(value: string, out?: ColorComponents): ColorComponents; /** * Converts a CSS 'web' string into a Phaser Color object. * * The web string can be in the format `'rgb(r,g,b)'` or `'rgba(r,g,b,a)'` where r/g/b are in the range [0..255] and a is in the range [0..1]. * * @param web The color string in CSS 'web' format. * @param out An object into which 4 properties will be created: r, g, b and a. If not provided a new object will be created. * @return An object with the red, green, blue and alpha values set in the r, g, b and a properties. */ static webToColor(web: string, out?: ColorComponents): ColorComponents; /** * Blends the source color, ignoring the backdrop. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendNormal(a: number): number; /** * Selects the lighter of the backdrop and source colors. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendLighten(a: number, b: number): number; /** * Selects the darker of the backdrop and source colors. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendDarken(a: number, b: number): number; /** * Multiplies the backdrop and source color values. * The result color is always at least as dark as either of the two constituent * colors. Multiplying any color with black produces black; * multiplying with white leaves the original color unchanged. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendMultiply(a: number, b: number): number; /** * Takes the average of the source and backdrop colors. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendAverage(a: number, b: number): number; /** * Adds the source and backdrop colors together and returns the value, up to a maximum of 255. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendAdd(a: number, b: number): number; /** * Combines the source and backdrop colors and returns their value minus 255. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendSubtract(a: number, b: number): number; /** * Subtracts the darker of the two constituent colors from the lighter. * * Painting with white inverts the backdrop color; painting with black produces no change. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendDifference(a: number, b: number): number; /** * Negation blend mode. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendNegation(a: number, b: number): number; /** * Multiplies the complements of the backdrop and source color values, then complements the result. * The result color is always at least as light as either of the two constituent colors. * Screening any color with white produces white; screening with black leaves the original color unchanged. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendScreen(a: number, b: number): number; /** * Produces an effect similar to that of the Difference mode, but lower in contrast. * Painting with white inverts the backdrop color; painting with black produces no change. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendExclusion(a: number, b: number): number; /** * Multiplies or screens the colors, depending on the backdrop color. * Source colors overlay the backdrop while preserving its highlights and shadows. * The backdrop color is not replaced, but is mixed with the source color to reflect the lightness or darkness of the backdrop. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendOverlay(a: number, b: number): number; /** * Darkens or lightens the colors, depending on the source color value. * * If the source color is lighter than 0.5, the backdrop is lightened, as if it were dodged; * this is useful for adding highlights to a scene. * * If the source color is darker than 0.5, the backdrop is darkened, as if it were burned in. * The degree of lightening or darkening is proportional to the difference between the source color and 0.5; * if it is equal to 0.5, the backdrop is unchanged. * * Painting with pure black or white produces a distinctly darker or lighter area, but does not result in pure black or white. * The effect is similar to shining a diffused spotlight on the backdrop. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendSoftLight(a: number, b: number): number; /** * Multiplies or screens the colors, depending on the source color value. * * If the source color is lighter than 0.5, the backdrop is lightened, as if it were screened; * this is useful for adding highlights to a scene. * * If the source color is darker than 0.5, the backdrop is darkened, as if it were multiplied; * this is useful for adding shadows to a scene. * * The degree of lightening or darkening is proportional to the difference between the source color and 0.5; * if it is equal to 0.5, the backdrop is unchanged. * * Painting with pure black or white produces pure black or white. The effect is similar to shining a harsh spotlight on the backdrop. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendHardLight(a: number, b: number): number; /** * Brightens the backdrop color to reflect the source color. * Painting with black produces no change. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendColorDodge(a: number, b: number): number; /** * Darkens the backdrop color to reflect the source color. * Painting with white produces no change. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendColorBurn(a: number, b: number): number; /** * An alias for blendAdd, it simply sums the values of the two colors. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendLinearDodge(a: number, b: number): number; /** * An alias for blendSubtract, it simply sums the values of the two colors and subtracts 255. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendLinearBurn(a: number, b: number): number; /** * This blend mode combines Linear Dodge and Linear Burn (rescaled so that neutral colors become middle gray). * Dodge applies to values of top layer lighter than middle gray, and burn to darker values. * The calculation simplifies to the sum of bottom layer and twice the top layer, subtract 128. The contrast decreases. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendLinearLight(a: number, b: number): number; /** * This blend mode combines Color Dodge and Color Burn (rescaled so that neutral colors become middle gray). * Dodge applies when values in the top layer are lighter than middle gray, and burn to darker values. * The middle gray is the neutral color. When color is lighter than this, this effectively moves the white point of the bottom * layer down by twice the difference; when it is darker, the black point is moved up by twice the difference. The perceived contrast increases. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendVividLight(a: number, b: number): number; /** * If the backdrop color (light source) is lighter than 50%, the blendDarken mode is used, and colors lighter than the backdrop color do not change. * If the backdrop color is darker than 50% gray, colors lighter than the blend color are replaced, and colors darker than the blend color do not change. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendPinLight(a: number, b: number): number; /** * Runs blendVividLight on the source and backdrop colors. * If the resulting color is 128 or more, it receives a value of 255; if less than 128, a value of 0. * Therefore, all blended pixels have red, green, and blue channel values of either 0 or 255. * This changes all pixels to primary additive colors (red, green, or blue), white, or black. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendHardMix(a: number, b: number): number; /** * Reflect blend mode. This mode is useful when adding shining objects or light zones to images. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendReflect(a: number, b: number): number; /** * Glow blend mode. This mode is a variation of reflect mode with the source and backdrop colors swapped. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendGlow(a: number, b: number): number; /** * Phoenix blend mode. This subtracts the lighter color from the darker color, and adds 255, giving a bright result. * * @param a The source color to blend, in the range 1 to 255. * @param b The backdrop color to blend, in the range 1 to 255. * @return The blended color value, in the range 1 to 255. */ static blendPhoenix(a: number, b: number): number; } module Component { module Core { var skipTypeChecks: boolean; } } interface RGBColor { r: number; g: number; b: number; a: number; } interface ColorComponents extends RGBColor { h: number; s: number; v: number; l: number; color: number; color32: number; rgba: string; } /** * The Phaser.Create class is a collection of smaller helper methods that allow you to generate game content * quickly and easily, without the need for any external files. You can create textures for sprites and in * coming releases we'll add dynamic sound effect generation support as well (like sfxr). * * Access this via `Game.create` (`this.game.create` from within a State object). */ class Create { /** * The Phaser.Create class is a collection of smaller helper methods that allow you to generate game content * quickly and easily, without the need for any external files. You can create textures for sprites and in * coming releases we'll add dynamic sound effect generation support as well (like sfxr). * * Access this via `Game.create` (`this.game.create` from within a State object). * * @param game Game reference to the currently running game. */ constructor(game: Phaser.Game); /** * A 16 color palette by [Arne](http://androidarts.com/palette/16pal.htm) */ static PALETTE_ARNE: number; /** * A 16 color JMP inspired palette. */ static PALETTE_JMP: number; /** * A 16 color CGA inspired palette. */ static PALETTE_CGA: number; /** * A 16 color C64 inspired palette. */ static PALETTE_C64: number; /** * A 16 color palette inspired by Japanese computers like the MSX. */ static PALETTE_JAPANESE_MACHINE: number; /** * The internal BitmapData Create uses to generate textures from. */ bmd: Phaser.BitmapData; /** * The canvas the BitmapData uses. */ canvas: HTMLCanvasElement; /** * The 2d context of the canvas. */ ctx: CanvasRenderingContext2D; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * A range of 16 color palettes for use with sprite generation. */ palettes: any; /** * Copies the contents of {@link bmd Create's canvas} to the given BitmapData object, or a new BitmapData object. * * @param dest The BitmapData receiving the copied image. * @param x The x coordinate to translate to before drawing. * @param y The y coordinate to translate to before drawing. * @param width The new width of the Sprite being copied. * @param height The new height of the Sprite being copied. * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @param roundPx Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. * @return - The `dest` argument (if passed), or a new BitmapData object */ copy(dest?: Phaser.BitmapData, x?: number, y?: number, width?: number, height?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData; /** * Creates a grid texture based on the given dimensions. * * Use {@link Phaser.Loader#imageFromGrid} to preload an image of the same. * * @param key The key used to store this texture in the Phaser Cache. * @param width The width of the grid in pixels. * @param height The height of the grid in pixels. * @param cellWidth The width of the grid cells in pixels. * @param cellHeight The height of the grid cells in pixels. * @param color The color to draw the grid lines in. Should be a Canvas supported color string like `#ff5500` or `rgba(200,50,3,0.5)`. * @param generateTexture When false, a new BitmapData object is returned instead. - Default: true * @param callback A function to execute once the texture is generated. It will be passed the newly generated texture. * @param callbackContext The context in which to invoke the callback. * @return The newly generated texture, or a new BitmapData object if `generateTexture` is false, or `null` if a callback was passed and the texture isn't available yet. */ grid(key: string, width: number, height: number, cellWidth: number, cellHeight: number, color: string, generateTexture?: boolean, callback?: Function, callbackContext?: any): PIXI.Texture; /** * Generates a new PIXI.Texture from the given data, which can be applied to a Sprite. * * This allows you to create game graphics quickly and easily, with no external files but that use actual proper images * rather than Phaser.Graphics objects, which are expensive to render and limited in scope. * * Each element of the array is a string holding the pixel color values, as mapped to one of the Phaser.Create PALETTE consts. * * For example: * * `var data = [ * ' 333 ', * ' 777 ', * 'E333E', * ' 333 ', * ' 3 3 ' * ];` * * `game.create.texture('bob', data);` * * The above will create a new texture called `bob`, which will look like a little man wearing a hat. You can then use it * for sprites the same way you use any other texture: `game.add.sprite(0, 0, 'bob');` * * Use {@link Phaser.Loader#imageFromTexture} to preload an image of the same. * * @param key The key used to store this texture in the Phaser Cache. * @param data An array of pixel data. * @param pixelWidth The width of each pixel. - Default: 8 * @param pixelHeight The height of each pixel. - Default: 8 * @param palette The palette to use when rendering the texture. One of the Phaser.Create.PALETTE consts. * @param generateTexture When false, a new BitmapData object is returned instead. - Default: true * @param callback A function to execute once the texture is generated. It will be passed the newly generated texture. * @param callbackContext The context in which to invoke the callback. * @return The newly generated texture, or a new BitmapData object if `generateTexture` is false, or `null` if a callback was passed and the texture isn't available yet. */ texture(key: string, data: any, pixelWidth?: number, pixelHeight?: number, palette?: number, generateTexture?: boolean, callback?: Function, callbackContext?: any): PIXI.Texture; } interface CursorKeys { up: Phaser.Key; down: Phaser.Key; left: Phaser.Key; right: Phaser.Key; } /** * Detects device support capabilities and is responsible for device initialization - see {@link Phaser.Device.whenReady whenReady}. * * This class represents a singleton object that can be accessed directly as `game.device` * (or, as a fallback, `Phaser.Device` when a game instance is not available) without the need to instantiate it. * * Unless otherwise noted the device capabilities are only guaranteed after initialization. Initialization * occurs automatically and is guaranteed complete before {@link Phaser.Game} begins its "boot" phase. * Feature detection can be modified in the {@link Phaser.Device.onInitialized onInitialized} signal, e.g., * * ```javascript * Phaser.Device.onInitialized.add(function (device) { * * device.canvasBitBltShift = true; * device.mspointer = false; * * }); * * var game = new Phaser.Game(); * ``` * * When checking features using the exposed properties only the *truth-iness* of the value should be relied upon * unless the documentation states otherwise: properties may return `false`, `''`, `null`, or even `undefined` * when indicating the lack of a feature. * * Uses elements from System.js by MrDoob and Modernizr */ class Device { /** * Same value as `littleEndian`. */ static LITTLE_ENDIAN: boolean; /** * This signal is dispatched after device initialization occurs but before any of the ready * callbacks (see {@link Phaser.Device.whenReady whenReady}) have been invoked. * * Local "patching" for a particular device can/should be done in this event. * * _Note_: This signal is removed after the device has been readied; if a handler has not been * added _before_ `new Phaser.Game(..)` it is probably too late. */ static onInitialized: Phaser.Signal; static checkFullScreenSupport(): void; /** * Check whether the host environment can play audio. * * @param type One of 'mp3, 'ogg', 'm4a', 'wav', 'webm' or 'opus'. * @return True if the given file type is supported by the browser, otherwise false. */ static canPlayAudio(type: string): boolean; /** * Check whether the host environment can play video files. * * @param type One of 'mp4, 'ogg', 'webm' or 'mpeg'. * @return True if the given file type is supported by the browser, otherwise false. */ static canPlayVideo(type: string): boolean; static isConsoleOpen(): boolean; /** * Detect if the host is a an Android Stock browser. * This is available before the device "ready" event. * * Authors might want to scale down on effects and switch to the CANVAS rendering method on those devices. */ static isAndroidStockBrowser(): string; static whenReady: (callback: Function, context?: any) => void; /** * Is running on android? */ android: boolean; /** * Set to true if running in Arora. */ arora: boolean; /** * Are Audio tags available? */ audioData: boolean; cancelFullScreen: string; /** * If the browser isn't capable of handling tinting with alpha this will be false. */ canHandleAlpha: boolean; /** * Whether or not the {@link http://caniuse.com/#feat=canvas-blending Canvas Blend Modes} are supported, consequently the ability to tint using the multiply method. * * Expect `false` in Internet Explorer <= 11. */ canUseMultiply: boolean; /** * Is canvas available? */ canvas: boolean; /** * Set to true if running in Chrome. */ chrome: boolean; /** * Is running on chromeOS? */ chromeOS: boolean; /** * If running in Chrome this will contain the major version number. */ chromeVersion: number; /** * Is the game running under CocoonJS? */ cocoonJS: boolean; /** * Is this game running with CocoonJS.App? */ cocoonJSApp: boolean; /** * Is the game running under Apache Cordova? */ cordova: boolean; /** * Is the game running under the Intel Crosswalk XDK? */ crosswalk: boolean; /** * Is css3D available? */ css3D: boolean; /** * Is running on a desktop? */ desktop: boolean; /** * The time the device became ready. */ deviceReadyAt: number; /** * Set to true if running in Microsoft Edge browser. */ edge: boolean; /** * Is the game running under GitHub Electron? */ electron: boolean; /** * Is the game running under Ejecta? */ ejecta: boolean; /** * Set to true if running in Epiphany. */ epiphany: boolean; /** * Is file available? */ file: boolean; /** * Is fileSystem available? */ fileSystem: boolean; /** * Set to true if running in Firefox. */ firefox: boolean; /** * If running in Firefox this will contain the major version number. */ firefoxVersion: number; fullScreen: boolean; fullScreenKeyboard: boolean; /** * Does the device support the getUserMedia API? * Default: true */ getUserMedia: boolean; game: Phaser.Game; /** * Can this device play h264 mp4 video files? */ h264Video: boolean; /** * Can this device play hls video files? */ hlsVideo: boolean; /** * Set to true if running in Internet Explorer. */ ie: boolean; /** * If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion. */ ieVersion: number; /** * Is running on iOS? */ iOS: boolean; /** * If running in iOS this will contain the major version number. */ iOSVersion: number; /** * The time as which initialization has completed. */ initialized: boolean; /** * Is running on iPad? */ iPad: boolean; /** * Is running on iPhone? */ iPhone: boolean; /** * Is running on iPhone4? */ iPhone4: boolean; kindle: boolean; /** * Is running on linux? */ linux: boolean; /** * Is the device big or little endian? (only detected if the browser supports TypedArrays) */ littleEndian: boolean; /** * Is localStorage available? */ localStorage: boolean; /** * Can this device play m4a files? True if this device can play m4a files. */ m4a: boolean; /** * Is running on macOS? */ macOS: boolean; /** * Set to true if running in Midori. */ midori: boolean; /** * Set to true if running in Mobile Safari. */ mobileSafari: boolean; /** * Can this device play mp3 files? */ mp3: boolean; /** * Can this device play h264 mp4 video files? */ mp4Video: boolean; /** * Is mspointer available? */ mspointer: boolean; /** * Is the game running under Node.js? */ node: boolean; /** * Is the game running under Node-Webkit? */ nodeWebkit: boolean; /** * Can this device play ogg files? */ ogg: boolean; /** * Can this device play ogg video files? */ oggVideo: number; /** * Set to true if running in Opera. */ opera: boolean; /** * Can this device play opus files? */ opus: boolean; /** * PixelRatio of the host device? */ pixelRatio: number; /** * Is Pointer Lock available? */ pointerLock: boolean; /** * Is the browser running in strict mode (false) or quirks mode? (true) */ quirksMode: boolean; requestFullScreen: string; /** * Set to true if running in Safari. */ safari: boolean; /** * Set to true if running in the Silk browser (as used on the Amazon Kindle) */ silk: boolean; /** * Does the device context support 32bit pixel manipulation using array buffer views? */ support32bit: boolean; /** * Is touch available? */ touch: boolean; /** * Set to true if running a Trident version of Internet Explorer (IE11+) */ trident: boolean; /** * If running in Internet Explorer 11 this will contain the major version number. See {@link http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx} */ tridentVersion: number; /** * Does the browser support TypedArrays? */ typedArray: boolean; /** * Does the device support the Vibration API? */ vibration: boolean; vita: boolean; /** * Can this device play wav files? */ wav: boolean; /** * Set to true if running as a WebApp, i.e. within a WebView */ webApp: boolean; /** * Is the WebAudio API available? */ webAudio: boolean; /** * Is webGL available? */ webGL: boolean; /** * Can this device play webm files? */ webm: boolean; /** * Can this device play webm video files? */ webmVideo: boolean; /** * Is running on windows? */ windows: boolean; /** * Is running on a Windows Phone? */ windowsPhone: boolean; /** * The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll' */ wheelEvent: string; /** * Is worker available? */ worker: boolean; wp9Video: boolean; } /** * DeviceButtons belong to both `Phaser.Pointer` and `Phaser.SinglePad` (Gamepad) instances. * * For Pointers they represent the various buttons that can exist on mice and pens, such as the left button, right button, * middle button and advanced buttons like back and forward. * * Access them via `Pointer.leftbutton`, `Pointer.rightButton` and so on. * * On Gamepads they represent all buttons on the pad: from shoulder buttons to action buttons. * * At the time of writing this there are device limitations you should be aware of: * * - On Windows, if you install a mouse driver, and its utility software allows you to customize button actions * (e.g., IntelliPoint and SetPoint), the middle (wheel) button, the 4th button, and the 5th button might not be set, * even when they are pressed. * - On Linux (GTK), the 4th button and the 5th button are not supported. * - On Mac OS X 10.5 there is no platform API for implementing any advanced buttons. */ class DeviceButton { /** * DeviceButtons belong to both `Phaser.Pointer` and `Phaser.SinglePad` (Gamepad) instances. * * For Pointers they represent the various buttons that can exist on mice and pens, such as the left button, right button, * middle button and advanced buttons like back and forward. * * Access them via `Pointer.leftbutton`, `Pointer.rightButton` and so on. * * On Gamepads they represent all buttons on the pad: from shoulder buttons to action buttons. * * At the time of writing this there are device limitations you should be aware of: * * - On Windows, if you install a mouse driver, and its utility software allows you to customize button actions * (e.g., IntelliPoint and SetPoint), the middle (wheel) button, the 4th button, and the 5th button might not be set, * even when they are pressed. * - On Linux (GTK), the 4th button and the 5th button are not supported. * - On Mac OS X 10.5 there is no platform API for implementing any advanced buttons. * * @param parent A reference to the parent of this button. Either a Pointer or a Gamepad. * @param buttonCode The button code this DeviceButton is responsible for. */ constructor(parent: Phaser.Pointer | Phaser.SinglePad, butonCode: number); /** * The buttoncode of this button if a Gamepad, or the DOM button event value if a Pointer. */ buttonCode: number; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The "down" state of the button. */ isDown: boolean; /** * The "up" state of the button. * Default: true */ isUp: boolean; /** * This Signal is dispatched every time this DeviceButton is pressed down. * It is only dispatched once (until the button is released again). * When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button. */ onDown: Phaser.Signal; /** * Gamepad only. * This Signal is dispatched every time this DeviceButton changes floating value (between, but not exactly, 0 and 1). * When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button. */ onFloat: Phaser.Signal; /** * This Signal is dispatched every time this DeviceButton is released from a down state. * It is only dispatched once (until the button is pressed again). * When dispatched it sends 2 arguments: A reference to this DeviceButton and the value of the button. */ onUp: Phaser.Signal; pad: Phaser.Gamepad; /** * Gamepad only. * If a button is held down this holds down the number of times the button has 'repeated'. */ repeats: number; /** * The timestamp when the button was last pressed down. */ timeDown: number; /** * The timestamp when the button was last released. */ timeUp: number; /** * Button value. Mainly useful for checking analog buttons (like shoulder triggers) on Gamepads. */ value: number; /** * Destroys this DeviceButton, this disposes of the onDown, onUp and onFloat signals * and clears the parent and game references. */ destroy(): void; /** * Returns the "just pressed" state of this button. * Just pressed is considered true if the button was pressed down within the duration given (default 250ms). * * @param duration The duration in ms below which the button is considered as being just pressed. - Default: 250 * @return True if the button is just pressed otherwise false. */ justPressed(duration?: number): boolean; /** * Returns the "just released" state of this button. * Just released is considered as being true if the button was released within the duration given (default 250ms). * * @param duration The duration in ms below which the button is considered as being just released. - Default: 250 * @return True if the button is just released otherwise false. */ justReleased(duration?: number): boolean; processButtonDown(value: number): void; processButtonFloat(value: number): void; processButtonUp(value: number): void; /** * Resets this DeviceButton, changing it to an isUp state and resetting the duration and repeats counters. */ reset(): void; } module Easing { var Default: Function; var Power0: Function; var Power1: Function; var power2: Function; var power3: Function; var power4: Function; /** * Back easing. */ class Back { /** * Back ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Back ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Back ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Bounce easing. */ class Bounce { /** * Bounce ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Bounce ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Bounce ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Circular easing. */ class Circular { /** * Circular ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Circular ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Circular ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Cubic easing. */ class Cubic { /** * Cubic ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Cubic ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Cubic ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Elastic easing. */ class Elastic { /** * Elastic ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Elastic ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Elastic ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Exponential easing. */ class Exponential { /** * Exponential ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Exponential ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Exponential ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Linear easing. */ class Linear { /** * Linear Easing (no variation). * * @param k The value to be tweened. * @return k. */ static None(k: number): number; } /** * Quadratic easing. */ class Quadratic { /** * Ease-in. * * @param k The value to be tweened. * @return k^2. */ static In(k: number): number; /** * Ease-out. * * @param k The value to be tweened. * @return k* (2-k). */ static Out(k: number): number; /** * Ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Quartic easing. */ class Quartic { /** * Quartic ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Quartic ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Quartic ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Quintic easing. */ class Quintic { /** * Quintic ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Quintic ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Quintic ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } /** * Sinusoidal easing. */ class Sinusoidal { /** * Sinusoidal ease-in. * * @param k The value to be tweened. * @return The tweened value. */ static In(k: number): number; /** * Sinusoidal ease-out. * * @param k The value to be tweened. * @return The tweened value. */ static Out(k: number): number; /** * Sinusoidal ease-in/out. * * @param k The value to be tweened. * @return The tweened value. */ static InOut(k: number): number; } } /** * Creates a Ellipse object. A curve on a plane surrounding two focal points. */ class Ellipse { /** * Creates a Ellipse object. A curve on a plane surrounding two focal points. * * @param x The X coordinate of the upper-left corner of the framing rectangle of this ellipse. * @param y The Y coordinate of the upper-left corner of the framing rectangle of this ellipse. * @param width The overall width of this ellipse. * @param height The overall height of this ellipse. */ constructor(x?: number, y?: number, width?: number, height?: number); /** * The sum of the y and height properties. Changing the bottom property of an Ellipse doesn't adjust the y property, but does change the height. Gets or sets the bottom of the ellipse. */ bottom: number; /** * The x coordinate of the center of the Ellipse. */ centerX: number; /** * The y coordinate of the center of the Ellipse. */ centerY: number; /** * Determines whether or not this Ellipse object is empty. Will return a value of true if the Ellipse objects dimensions are less than or equal to 0; otherwise false. * If set to true it will reset all of the Ellipse objects properties to 0. An Ellipse object is empty if its width or height is less than or equal to 0. Gets or sets the empty state of the ellipse. */ empty: boolean; /** * The overall height of this ellipse. */ height: number; /** * The left coordinate of the Ellipse. The same as the X coordinate. */ left: number; /** * The x coordinate of the rightmost point of the Ellipse. Changing the right property of an Ellipse object has no effect on the x property, but does adjust the width. Gets or sets the value of the rightmost point of the ellipse. */ right: number; /** * The top of the Ellipse. The same as its y property. Gets or sets the top of the ellipse. */ top: number; /** * The const type of this object. */ type: number; /** * The overall width of this ellipse. */ width: number; /** * The X coordinate of the upper-left corner of the framing rectangle of this ellipse. */ x: number; /** * The Y coordinate of the upper-left corner of the framing rectangle of this ellipse. */ y: number; static constains(a: Phaser.Ellipse, x: number, y: number): boolean; /** * Returns a new Ellipse object with the same values for the x, y, width, and height properties as this Ellipse object. * * @param output Optional Ellipse object. If given the values will be set into the object, otherwise a brand new Ellipse object will be created and returned. * @return The cloned Ellipse object. */ clone(output?: Phaser.Ellipse): Phaser.Ellipse; /** * Return true if the given x/y coordinates are within this Ellipse object. * * @param x The X value of the coordinate to test. * @param y The Y value of the coordinate to test. * @return True if the coordinates are within this ellipse, otherwise false. */ contains(x: number, y: number): boolean; /** * Copies the x, y, width and height properties from any given object to this Ellipse. * * @param source The object to copy from. * @return This Ellipse object. */ copyFrom(source: any): Phaser.Ellipse; /** * Copies the x, y, width and height properties from this Ellipse to any given object. * * @param dest The object to copy to. * @return This dest object. */ copyTo(dest: any): any; /** * Returns the framing rectangle of the ellipse as a Phaser.Rectangle object. * @return The bounds of the Ellipse. */ getBounds(): Phaser.Rectangle; /** * Returns a uniformly distributed random point from anywhere within this Ellipse. * * @param out A Phaser.Point, or any object with public x/y properties, that the values will be set in. * If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object. * @return An object containing the random point in its `x` and `y` properties. */ random(out?: Phaser.Point): Phaser.Point; /** * Sets the members of the Ellipse to the specified values. * * @param x The X coordinate of the upper-left corner of the framing rectangle of this ellipse. * @param y The Y coordinate of the upper-left corner of the framing rectangle of this ellipse. * @param width The overall width of this ellipse. * @param height The overall height of this ellipse. * @return This Ellipse object. */ setTo(x: number, y: number, width: number, height: number): Phaser.Ellipse; /** * Returns a string representation of this object. * @return A string representation of the instance. */ toString(): string; } /** * The Events component is a collection of events fired by the parent Game Object. * * Phaser uses what are known as 'Signals' for all event handling. All of the events in * this class are signals you can subscribe to, much in the same way you'd "listen" for * an event. * * For example to tell when a Sprite has been added to a new group, you can bind a function * to the {@link Phaser.Events#onAddedToGroup onAddedToGroup} signal: * * `sprite.events.onAddedToGroup.add(yourFunction, this);` * * Where `yourFunction` is the function you want called when this event occurs. * * For more details about how signals work please see the {@link Phaser.Signal} class. * * The Input-related events will only be dispatched if the Sprite has had {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true` * and the Animation-related events only apply to game objects with animations like {@link Phaser.Sprite}. */ class Events { /** * The Events component is a collection of events fired by the parent Game Object. * * Phaser uses what are known as 'Signals' for all event handling. All of the events in * this class are signals you can subscribe to, much in the same way you'd "listen" for * an event. * * For example to tell when a Sprite has been added to a new group, you can bind a function * to the {@link Phaser.Events#onAddedToGroup onAddedToGroup} signal: * * `sprite.events.onAddedToGroup.add(yourFunction, this);` * * Where `yourFunction` is the function you want called when this event occurs. * * For more details about how signals work please see the {@link Phaser.Signal} class. * * The Input-related events will only be dispatched if the Sprite has had {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true` * and the Animation-related events only apply to game objects with animations like {@link Phaser.Sprite}. * * @param sprite A reference to the game object / Sprite that owns this Events object. */ constructor(sprite: Phaser.Sprite); /** * The Sprite that owns these events. */ parent: Phaser.Sprite; /** * This signal is dispatched when this Game Object is added to a new {@link Phaser.Group Group}. * It is sent two arguments: * * - {any} The Game Object that was added to the Group. * - {Phaser.Group} The Group it was added to. */ onAddedToGroup: Phaser.Signal; /** * This signal is dispatched when the Game Object is removed from a {@link Phaser.Group Group}. * It is sent two arguments: * * - {any} The Game Object that was removed from the Group. * - {Phaser.Group} The Group it was removed from. */ onRemovedFromGroup: Phaser.Signal; onRemovedFromWorld: Phaser.Signal; /** * This signal is dispatched when the Game Object is killed. * This happens when {@link Phaser.Sprite#kill Sprite.kill()} is called. * Please understand the difference between {@link Phaser.Sprite#kill kill} and {@link Phaser.Sprite#destroy destroy} by looking at their respective methods. * It is sent one argument: * * - {any} The Game Object that was killed. */ onKilled: Phaser.Signal; /** * This signal is dispatched when the Game Object is revived from a previously killed state. * This happens when {@link Phaser.Sprite#revive Sprite.revive()} is called. * It is sent one argument: * * - {any} The Game Object that was revived. */ onRevived: Phaser.Signal; /** * This signal is dispatched when the Game Object leaves the Phaser.World {@link Phaser.World#bounds bounds}. * This signal is only if {@link Phaser.Sprite#checkWorldBounds Sprite.checkWorldBounds} is set to `true`. * It is sent one argument: * * - {any} The Game Object that left the World bounds. */ onOutOfBounds: Phaser.Signal; /** * This signal is dispatched when the Game Object returns within the Phaser.World {@link Phaser.World#bounds bounds}, having previously been outside of them. * This signal is only if {@link Phaser.Sprite#checkWorldBounds Sprite.checkWorldBounds} is set to `true`. * It is sent one argument: * * - {any} The Game Object that entered the World bounds. */ onEnterBounds: Phaser.Signal; /** * This signal is dispatched if the Game Object has {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true`, * and receives an over event from a {@link Phaser.Pointer}. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. */ onInputOver: Phaser.Signal; /** * This signal is dispatched if the Game Object has {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true`, * and receives an out event from a {@link Phaser.Pointer}, which was previously over it. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. */ onInputOut: Phaser.Signal; /** * This signal is dispatched if the Game Object has {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true`, * and receives a down event from a {@link Phaser.Pointer}. This effectively means the Pointer has been * pressed down (but not yet released) on the Game Object. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. */ onInputDown: Phaser.Signal; /** * This signal is dispatched if the Game Object has {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} set to `true`, * and receives an up event from a {@link Phaser.Pointer}. This effectively means the Pointer had been * pressed down, and was then released on the Game Object. * It is sent three arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. * - {boolean} isOver - Is the Pointer still over the Game Object? */ onInputUp: Phaser.Signal; /** * This signal is dispatched when the Game Object is destroyed. * This happens when {@link Phaser.Sprite#destroy Sprite.destroy()} is called, or {@link Phaser.Group#destroy Group.destroy()} with `destroyChildren` set to true. * It is sent one argument: * * - {any} The Game Object that was destroyed. */ onDestroy: Phaser.Signal; /** * This signal is dispatched if the Game Object has been {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} and {@link Phaser.InputHandler#enableDrag enableDrag} has been set. * It is sent when a {@link Phaser.Pointer} starts to drag the Game Object, taking into consideration the various * drag limitations that may be set. * It is sent four arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. * - {number} The x coordinate that the drag started from. * - {number} The y coordinate that the drag started from. */ onDragStart: Phaser.Signal; /** * This signal is dispatched if the Game Object has been {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} and {@link Phaser.InputHandler#enableDrag enableDrag} has been set. * It is sent when a {@link Phaser.Pointer} stops dragging the Game Object. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. */ onDragStop: Phaser.Signal; /** * This signal is dispatched if the Game Object has been {@link Phaser.Component.InputEnabled#inputEnabled inputEnabled} and {@link Phaser.InputHandler#enableDrag enableDrag} has been set. * It is sent when a {@link Phaser.Pointer} is actively dragging the Game Object. * Be warned: This is a high volume Signal. Be careful what you bind to it. * It is sent six arguments: * * - {any} The Game Object that received the event. * - {Phaser.Pointer} The Phaser.Pointer object that caused the event. * - {number} The new x coordinate of the Game Object. * - {number} The new y coordinate of the Game Object. * - {Phaser.Point} A Point object that contains the point the Game Object was snapped to, if `snapOnDrag` has been enabled. * - {boolean} The `fromStart` boolean, indicates if this is the first update immediately after the drag has started. */ onDragUpdate: Phaser.Signal; /** * This signal is dispatched if the Game Object has the {@link Phaser.AnimationManager AnimationManager} component, * and an Animation has been played. * You can also listen to {@link Phaser.Animation#onStart} rather than via the Game Objects events. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Animation} The Phaser.Animation that was started. */ onAnimationStart: Phaser.Signal; /** * This signal is dispatched if the Game Object has the {@link Phaser.AnimationManager AnimationManager} component, * and an Animation has been stopped (via {@link Phaser.AnimationManager#stop animation.stop()} and the `dispatchComplete` argument has been set. * You can also listen to {@link Phaser.Animation#onComplete} rather than via the Game Objects events. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Animation} The Phaser.Animation that was stopped. */ onAnimationComplete: Phaser.Signal; /** * This signal is dispatched if the Game Object has the {@link Phaser.AnimationManager AnimationManager} component, * and an Animation has looped playback. * You can also listen to {@link Phaser.Animation#onLoop} rather than via the Game Objects events. * It is sent two arguments: * * - {any} The Game Object that received the event. * - {Phaser.Animation} The Phaser.Animation that looped. */ onAnimationLoop: Phaser.Signal; /** * Removes all events. */ destroy(): void; } /** * This is a base Filter class to use for any Phaser filter development. * If you want to make a custom filter, this should be your base class. * * The default uniforms, types and values for all Filters are: * * ```javascript * resolution: { type: '2f', value: { x: 256, y: 256 }} * time: { type: '1f', value: 0 } * mouse: { type: '2f', value: { x: 0.0, y: 0.0 } } * date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] } * sampleRate: { type: '1f', value: 44100.0 } * iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } } * ``` * * The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and * therefore only work in WebGL and are not supported by Canvas at all. */ class Filter extends PIXI.AbstractFilter { /** * This is a base Filter class to use for any Phaser filter development. * If you want to make a custom filter, this should be your base class. * * The default uniforms, types and values for all Filters are: * * ```javascript * resolution: { type: '2f', value: { x: 256, y: 256 }} * time: { type: '1f', value: 0 } * mouse: { type: '2f', value: { x: 0.0, y: 0.0 } } * date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] } * sampleRate: { type: '1f', value: 44100.0 } * iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } } * iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } } * ``` * * The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and * therefore only work in WebGL and are not supported by Canvas at all. * * @param game A reference to the currently running game. * @param uniforms Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same. * @param fragmentSrc The fragment shader code. Either an array, one element per line of code, or a string. */ constructor(game: Phaser.Game, uniforms: any, fragmentSrc: string | string[]); /** * Internal PIXI var. * Default: true */ dirty: boolean; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The height (resolution uniform) */ height: number; /** * The fragment shader code. */ fragmentSrc: string | string[]; /** * Internal PIXI var. */ padding: number; /** * The previous position of the pointer (we don't update the uniform if the same) */ prevPoint: Phaser.Point; /** * The const type of this object, either Phaser.WEBGL_FILTER or Phaser.CANVAS_FILTER. */ type: number; /** * Default uniform mappings. Compatible with ShaderToy and GLSLSandbox. */ uniforms: any; /** * The width (resolution uniform) */ width: number; /** * Creates a new Phaser.Image object using a blank texture and assigns * this Filter to it. The image is then added to the world. * * If you don't provide width and height values then Filter.width and Filter.height are used. * * If you do provide width and height values then this filter will be resized to match those * values. * * @param x The x coordinate to place the Image at. * @param y The y coordinate to place the Image at. * @param width The width of the Image. If not specified (or null) it will use Filter.width. If specified Filter.width will be set to this value. * @param height The height of the Image. If not specified (or null) it will use Filter.height. If specified Filter.height will be set to this value. * @param anchorX Set the x anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param anchorY Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @return The newly added Image object. */ addToWorld(x?: number, y?: number, width?: number, height?: number, anchorX?: number, anchorY?: number): Phaser.Image; apply(frameBuffer: WebGLFramebuffer): void; /** * Clear down this Filter and null out references to game. */ destroy(): void; /** * This should be over-ridden. Will receive a variable number of arguments. */ init(...args: any[]): void; /** * Set the resolution uniforms on the filter. * * @param width The width of the display. * @param height The height of the display. */ setResolution(width: number, height: number): void; /** * Syncs the uniforms between the class object and the shaders. */ syncUniforms(): void; /** * Updates the filter. * * @param pointer A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform. */ update(pointer?: Phaser.Pointer): void; } module Filter { class BinarySerpents extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, march?: number, maxDistance?: number); fog: number; } class BlurX extends Phaser.Filter { blur: number; } class BlurY extends Phaser.Filter { blur: number; } class CausticLight extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, divisor?: number); init(width: number, height: number, divisor?: number): void; } class CheckerWave extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number); alpha: number; cameraX: number; cameraY: number; cameraZ: number; init(width: number, height: number): void; setColor1(red: number, green: number, blue: number): void; setColor2(red: number, green: number, blue: number): void; } class ColorBars extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number); alpha: number; init(width: number, height: number): void; } class Fire extends Phaser.Filter { constructor(width: number, height: number, alpha?: number, shift?: number); alpha: number; shift: number; speed: number; init(width: number, height: number, alpha?: number, shift?: number): void; } class Gray extends Phaser.Filter { gray: number; } class HueRotate extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, texture: any); alpha: number; init(width: number, height: number, texture: any): void; } class LazerBeam extends Phaser.Filter { init(width: number, height: number, divisor?: number): void; } class LightBeam extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number); alpha: number; blue: number; green: number; red: number; thickness: number; speed: number; init(width: number, height: number): void; } class Marble extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, speed?: number, intensity?: number); alpha: number; intensity: number; speed: number; init(width: number, height: number, speed?: number, intensity?: number): void; } class Pixelate extends Phaser.Filter { size: number; sizeX: number; sizeY: number; } class Plasma extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, alpha?: number, size?: number); alpha: number; blueShift: number; greenShift: number; redShift: number; size: number; init(width: number, height: number, alpha?: number, size?: number): void; } class SampleFilter extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, divisor?: number); init(width: number, height: number, divisor?: number): void; } class Tunnel extends Phaser.Filter { constructor(game: Phaser.Game, width: number, height: number, texture: any); alpha: number; origin: number; init(width: number, height: number, texture: any): void; } } /** * WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete. * Please try to avoid using in production games with a long time to build. * This is also why the documentation is incomplete. * * FlexGrid is a a responsive grid manager that works in conjunction with the ScaleManager RESIZE scaling mode and FlexLayers * to provide for game object positioning in a responsive manner. */ class FlexGrid { /** * WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete. * Please try to avoid using in production games with a long time to build. * This is also why the documentation is incomplete. * * FlexGrid is a a responsive grid manager that works in conjunction with the ScaleManager RESIZE scaling mode and FlexLayers * to provide for game object positioning in a responsive manner. * * @param manager The ScaleManager. * @param width The width of the game. * @param height The height of the game. */ constructor(manager: Phaser.ScaleManager, width: number, height: number); /** * A reference to the currently running Game. */ game: Phaser.Game; /** * A reference to the ScaleManager. */ manager: Phaser.ScaleManager; width: number; height: number; boundsCustom: Phaser.Rectangle; boundsFluid: Phaser.Rectangle; boundsFull: Phaser.Rectangle; boundsNone: Phaser.Rectangle; customWidth: number; customHeight: number; customOffsetX: number; customOffsetY: number; /** * - */ positionCustom: Phaser.Point; positionFluid: Phaser.Point; positionFull: Phaser.Point; positionNone: Phaser.Point; /** * The scale factor based on the game dimensions vs. the scaled dimensions. */ scaleCustom: Phaser.Point; scaleFluid: Phaser.Point; scaleFluidInversed: Phaser.Point; scaleFull: Phaser.Point; scaleNone: Phaser.Point; ratioH: number; ratioV: number; multiplier: number; /** * A custom layer is centered on the game and maintains its aspect ratio as it scales up and down. * * @param width Width of this layer in pixels. * @param height Height of this layer in pixels. * @param children An array of children that are used to populate the FlexLayer. * @return The Layer object. */ createCustomLayer(width: number, height: number, children?: PIXI.DisplayObject[], addToWorld?: boolean): Phaser.FlexLayer; /** * A fluid layer is centered on the game and maintains its aspect ratio as it scales up and down. * * @param children An array of children that are used to populate the FlexLayer. * @return The Layer object. */ createFluidLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer; /** * A full layer is placed at 0,0 and extends to the full size of the game. Children are scaled according to the fluid ratios. * * @param children An array of children that are used to populate the FlexLayer. * @return The Layer object. */ createFullLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer; /** * A fixed layer is centered on the game and is the size of the required dimensions and is never scaled. * * @param children An array of children that are used to populate the FlexLayer. * @return The Layer object. */ createFixedLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer; /** * Call in the render function to output the bounds rects. */ debug(): void; /** * Fits a sprites width to the bounds. * * @param sprite The Sprite to fit. */ fitSprite(sprite: Phaser.Sprite): void; /** * Called when the game container changes dimensions. * * @param width The new width of the game container. * @param height The new height of the game container. */ onResize(width: number, height: number): void; /** * Updates all internal vars such as the bounds and scale values. */ refresh(): void; /** * Resets the layer children references */ reset(): void; /** * Sets the core game size. This resets the w/h parameters and bounds. * * @param width The new dimensions. * @param height The new dimensions. */ setSize(width: number, height: number): void; } /** * WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete. * Please try to avoid using in production games with a long time to build. * This is also why the documentation is incomplete. * * A responsive grid layer. */ class FlexLayer extends Phaser.Group { /** * WARNING: This is an EXPERIMENTAL class. The API will change significantly in the coming versions and is incomplete. * Please try to avoid using in production games with a long time to build. * This is also why the documentation is incomplete. * * A responsive grid layer. * * @param manager The FlexGrid that owns this FlexLayer. * @param position A reference to the Point object used for positioning. * @param bounds A reference to the Rectangle used for the layer bounds. * @param scale A reference to the Point object used for layer scaling. */ constructor(manager: Phaser.ScaleManager, position: Phaser.Point, bounds: Phaser.Rectangle, scale: Phaser.Point); /** * A reference to the FlexGrid that owns this layer. */ grid: Phaser.FlexGrid; /** * A reference to the ScaleManager. */ manager: Phaser.ScaleManager; bottomLeft: Phaser.Point; bottomMiddle: Phaser.Point; bottomRight: Phaser.Point; bounds: Phaser.Rectangle; /** * Should the FlexLayer remain through a State swap? */ persist: boolean; position: Phaser.Point; scale: Phaser.Point; topLeft: Phaser.Point; topMiddle: Phaser.Point; topRight: Phaser.Point; /** * Debug. */ debug(): void; /** * Resize. */ resize(): void; } /** * A Frame is a single frame of an animation and is part of a FrameData collection. */ class Frame { /** * A Frame is a single frame of an animation and is part of a FrameData collection. * * @param index The index of this Frame within the FrameData set it is being added to. * @param x X position of the frame within the texture image. * @param y Y position of the frame within the texture image. * @param width Width of the frame within the texture image. * @param height Height of the frame within the texture image. * @param name The name of the frame. In Texture Atlas data this is usually set to the filename. */ constructor(index: number, x: number, y: number, width: number, height: number, name: string); /** * The bottom of the frame (y + height). */ bottom: number; /** * Center X position within the image to cut from. */ centerX: number; /** * Center Y position within the image to cut from. */ centerY: number; /** * The distance from the top left to the bottom-right of this Frame. */ distance: number; /** * Height of the frame. */ height: number; /** * The index of this Frame within the FrameData set it is being added to. */ index: number; /** * Useful for Texture Atlas files (is set to the filename value). */ name: string; /** * The right of the Frame (x + width). */ right: number; /** * Is the frame rotated in the source texture? */ rotated: boolean; /** * Height of the original sprite before it was trimmed. */ sourceSizeH: number; /** * Width of the original sprite before it was trimmed. */ sourceSizeW: number; /** * Height of the trimmed sprite. */ spriteSourceSizeH: number; /** * Width of the trimmed sprite. */ spriteSourceSizeW: number; /** * X position of the trimmed sprite inside original sprite. */ spriteSourceSizeX: number; /** * Y position of the trimmed sprite inside original sprite. */ spriteSourceSizeY: number; /** * Was it trimmed when packed? */ trimmed: boolean; uuid: string; /** * Width of the frame. */ width: number; /** * X position within the image to cut from. */ x: number; /** * Y position within the image to cut from. */ y: number; /** * Clones this Frame into a new Phaser.Frame object and returns it. * Note that all properties are cloned, including the name and index. * @return An exact copy of this Frame object. */ clone(): Phaser.Frame; /** * Returns a Rectangle set to the dimensions of this Frame. * * @param out A rectangle to copy the frame dimensions to. * @return A rectangle. */ getRect(out?: Phaser.Rectangle): Phaser.Rectangle; /** * If the frame was trimmed when added to the Texture Atlas this records the trim and source data. * * @param trimmed If this frame was trimmed or not. * @param actualWidth The width of the frame before being trimmed. * @param actualHeight The height of the frame before being trimmed. * @param destX The destination X position of the trimmed frame for display. * @param destY The destination Y position of the trimmed frame for display. * @param destWidth The destination width of the trimmed frame for display. * @param destHeight The destination height of the trimmed frame for display. */ setTrim(trimmed: boolean, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number): void; /** * Adjusts of all the Frame properties based on the given width and height values. * * @param width The new width of the Frame. * @param height The new height of the Frame. */ resize(width: number, height: number): void; } /** * FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser. */ class FrameData { /** * The total number of frames in this FrameData set. */ total: number; /** * Adds a new Frame to this FrameData collection. Typically called by the Animation.Parser and not directly. * * @param frame The frame to add to this FrameData set. * @return The frame that was just added. */ addFrame(frame: Frame): Phaser.Frame; /** * Check if there is a Frame with the given name. * * @param name The name of the frame you want to check. * @return True if the frame is found, otherwise false. */ checkFrameName(name: string): boolean; /** * Makes a copy of this FrameData including copies (not references) to all of the Frames it contains. * @return A clone of this object, including clones of the Frame objects it contains. */ clone(): Phaser.FrameData; /** * Get a Frame by its numerical index. * * @param index The index of the frame you want to get. * @return The frame, if found, or undefined. */ getFrame(index: number): Phaser.Frame; /** * Get a Frame by its frame name. * * @param name The name of the frame you want to get. * @return The frame, if found, or null. */ getFrameByName(name: string): Phaser.Frame; /** * Returns all of the Frame indexes in this FrameData set. * The frames indexes are returned in the output array, or if none is provided in a new Array object. * * @param frames An Array containing the indexes of the frames to retrieve. If undefined or the array is empty then all frames in the FrameData are returned. * @param useNumericIndex Are the given frames using numeric indexes (default) or strings? (false) - Default: true * @param output If given the results will be appended to the end of this array otherwise a new array will be created. * @return An array of all Frame indexes matching the given names or IDs. */ getFrameIndexes(frames?: number[], useNumericIndex?: boolean, output?: number[]): number[]; /** * Returns a range of frames based on the given start and end frame indexes and returns them in an Array. * * @param start The starting frame index. * @param end The ending frame index. * @param output If given the results will be appended to the end of this array otherwise a new array will be created. * @return An array of Frames between the start and end index values, or an empty array if none were found. */ getFrameRange(start: number, end: number, output: Phaser.Frame[]): Phaser.Frame[]; /** * Returns all of the Frames in this FrameData set where the frame index is found in the input array. * The frames are returned in the output array, or if none is provided in a new Array object. * * @param frames An Array containing the indexes of the frames to retrieve. If the array is empty or undefined then all frames in the FrameData are returned. * @param useNumericIndex Are the given frames using numeric indexes (default) or strings? (false) - Default: true * @param output If given the results will be appended to the end of this array otherwise a new array will be created. * @return An array of all Frames in this FrameData set matching the given names or IDs. */ getFrames(frames?: number[], useNumericIndex?: boolean, output?: Phaser.Frame[]): Phaser.Frame[]; } interface IGameConfig { alignH?: boolean; alignV?: boolean; antialias?: boolean; backgroundColor?: number | string; canvas?: HTMLCanvasElement; canvasId?: string; canvasStyle?: string; crisp?: boolean; disableVisibilityChange?: boolean; disableStart?: boolean; enableDebug?: boolean; failIfMajorPerformanceCaveat?: boolean; forceSetTimeOut?: boolean; fullScreenScaleMode?: number; fullScreenTarget?: HTMLElement; height?: number | string; keyboard?: boolean; maxPointers?: number; mouse?: boolean; mouseWheel?: boolean; mspointer?: boolean; multiTexture?: boolean; parent?: HTMLElement | string; physicsConfig?: any; pointerLock?: boolean; powerPreference?: string; preserveDrawingBuffer?: boolean; renderer?: number; resolution?: number; roundPixels?: boolean; scaleH?: number; scaleMode?: number; scaleV?: number seed?: number; state?: any; touch?: boolean; transparent?: boolean; trimH?: number; trimV?: number; width?: number | string; } interface InputConfig { keyboard?: boolean; maxPointers?: number; mouse?: boolean; mouseWheel?: boolean; mspointer?: boolean; pointerLock?: boolean; touch?: boolean; } /** * The Phaser.Game object is the main controller for the entire Phaser game. It is responsible * for handling the boot process, parsing the configuration values, creating the renderer, * and setting-up all of the Phaser systems, such as physics, sound and input. * Once that is complete it will start the default State, and then begin the main game loop. * * You can access lots of the Phaser systems via the properties on the `game` object. For * example `game.renderer` is the Renderer, `game.sound` is the Sound Manager, and so on. * * Anywhere you can access the `game` property, you can access all of these core systems. * For example a Sprite has a `game` property, allowing you to talk to the various parts * of Phaser directly, without having to look after your own references. * * In its most simplest form, a Phaser game can be created by providing the arguments * to the constructor: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }); * ``` * * In the example above it is passing in a State object directly. You can also use the State * Manager to do this: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO); * game.state.add('Boot', BasicGame.Boot); * game.state.add('Preloader', BasicGame.Preloader); * game.state.add('MainMenu', BasicGame.MainMenu); * game.state.add('Game', BasicGame.Game); * game.state.start('Boot'); * ``` * * In the example above, 4 States are added to the State Manager, and Phaser is told to * start running the `Boot` state when it has finished initializing. There are example * project templates you can use in the Phaser GitHub repo, inside the `resources` folder. * * Instead of specifying arguments you can also pass {@link GameConfig a single object} instead: * * ```javascript * var config = { * width: 800, * height: 600, * renderer: Phaser.AUTO, * antialias: true, * multiTexture: true, * state: { * preload: preload, * create: create, * update: update * } * } * * var game = new Phaser.Game(config); * ``` */ class Game { /** * The Phaser.Game object is the main controller for the entire Phaser game. It is responsible * for handling the boot process, parsing the configuration values, creating the renderer, * and setting-up all of the Phaser systems, such as physics, sound and input. * Once that is complete it will start the default State, and then begin the main game loop. * * You can access lots of the Phaser systems via the properties on the `game` object. For * example `game.renderer` is the Renderer, `game.sound` is the Sound Manager, and so on. * * Anywhere you can access the `game` property, you can access all of these core systems. * For example a Sprite has a `game` property, allowing you to talk to the various parts * of Phaser directly, without having to look after your own references. * * In its most simplest form, a Phaser game can be created by providing the arguments * to the constructor: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }); * ``` * * In the example above it is passing in a State object directly. You can also use the State * Manager to do this: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO); * game.state.add('Boot', BasicGame.Boot); * game.state.add('Preloader', BasicGame.Preloader); * game.state.add('MainMenu', BasicGame.MainMenu); * game.state.add('Game', BasicGame.Game); * game.state.start('Boot'); * ``` * * In the example above, 4 States are added to the State Manager, and Phaser is told to * start running the `Boot` state when it has finished initializing. There are example * project templates you can use in the Phaser GitHub repo, inside the `resources` folder. * * Instead of specifying arguments you can also pass {@link GameConfig a single object} instead: * * ```javascript * var config = { * width: 800, * height: 600, * renderer: Phaser.AUTO, * antialias: true, * multiTexture: true, * state: { * preload: preload, * create: create, * update: update * } * } * * var game = new Phaser.Game(config); * ``` * * @param width The width of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage width of the parent container, or the browser window if no parent is given. - Default: 800 * @param height The height of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage height of the parent container, or the browser window if no parent is given. - Default: 600 * @param renderer Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.WEBGL_MULTI, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all). - Default: Phaser.AUTO * @param parent The DOM element into which this game canvas will be injected. Either a DOM `id` (string) or the element itself. If omitted (or no such element exists), the game canvas is appended to the document body. - Default: '' * @param state The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null. * @param transparent Use a transparent canvas background or not. * @param antialias Draw all image textures anti-aliased or not. The default is for smooth textures, but disable if your game features pixel art. - Default: true * @param physicsConfig A physics configuration object to pass to the Physics world on creation. */ constructor(width?: number | string, height?: number | string, renderer?: number, parent?: any, state?: any, transparent?: boolean, antialias?: boolean, physicsConfig?: any); /** * The Phaser.Game object is the main controller for the entire Phaser game. It is responsible * for handling the boot process, parsing the configuration values, creating the renderer, * and setting-up all of the Phaser systems, such as physics, sound and input. * Once that is complete it will start the default State, and then begin the main game loop. * * You can access lots of the Phaser systems via the properties on the `game` object. For * example `game.renderer` is the Renderer, `game.sound` is the Sound Manager, and so on. * * Anywhere you can access the `game` property, you can access all of these core systems. * For example a Sprite has a `game` property, allowing you to talk to the various parts * of Phaser directly, without having to look after your own references. * * In its most simplest form, a Phaser game can be created by providing the arguments * to the constructor: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }); * ``` * * In the example above it is passing in a State object directly. You can also use the State * Manager to do this: * * ```javascript * var game = new Phaser.Game(800, 600, Phaser.AUTO); * game.state.add('Boot', BasicGame.Boot); * game.state.add('Preloader', BasicGame.Preloader); * game.state.add('MainMenu', BasicGame.MainMenu); * game.state.add('Game', BasicGame.Game); * game.state.start('Boot'); * ``` * * In the example above, 4 States are added to the State Manager, and Phaser is told to * start running the `Boot` state when it has finished initializing. There are example * project templates you can use in the Phaser GitHub repo, inside the `resources` folder. * * Instead of specifying arguments you can also pass {@link GameConfig a single object} instead: * * ```javascript * var config = { * width: 800, * height: 600, * renderer: Phaser.AUTO, * antialias: true, * multiTexture: true, * state: { * preload: preload, * create: create, * update: update * } * } * * var game = new Phaser.Game(config); * ``` * * @param width The width of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage width of the parent container, or the browser window if no parent is given. - Default: 800 * @param height The height of your game in game pixels. If given as a string the value must be between 0 and 100 and will be used as the percentage height of the parent container, or the browser window if no parent is given. - Default: 600 * @param renderer Which renderer to use: Phaser.AUTO will auto-detect, Phaser.WEBGL, Phaser.WEBGL_MULTI, Phaser.CANVAS or Phaser.HEADLESS (no rendering at all). - Default: Phaser.AUTO * @param parent The DOM element into which this game canvas will be injected. Either a DOM `id` (string) or the element itself. If omitted (or no such element exists), the game canvas is appended to the document body. - Default: '' * @param state The default state object. A object consisting of Phaser.State functions (preload, create, update, render) or null. * @param transparent Use a transparent canvas background or not. * @param antialias Draw all image textures anti-aliased or not. The default is for smooth textures, but disable if your game features pixel art. - Default: true * @param physicsConfig A physics configuration object to pass to the Physics world on creation. */ constructor(config: IGameConfig); /** * Reference to the Phaser.GameObjectFactory. */ add: Phaser.GameObjectFactory; /** * Anti-alias graphics (as set when the Game is created). By default scaled and rotated images are smoothed in Canvas and WebGL; set `antialias` to false to disable this globally. After the game boots, use `game.stage.smoothed` instead. * Default: true */ antialias: boolean; /** * Reference to the assets cache. */ cache: Phaser.Cache; /** * A handy reference to world.camera. */ camera: Phaser.Camera; /** * A handy reference to renderer.view, the canvas that the game is being rendered in to. */ canvas: HTMLCanvasElement; /** * Clear the Canvas each frame before rendering the display list. * You can set this to `false` to gain some performance if your game always contains a background that completely fills the display. * This must be `true` to show any {@link Phaser.Stage#backgroundColor} set on the Stage. * This is effectively **read-only after the game has booted**. * Use the {@link GameConfig} setting `clearBeforeRender` when creating the game, or set `game.renderer.clearBeforeRender` afterwards. * Default: true */ clearBeforeRender: boolean; /** * The Phaser.Game configuration object. */ config: IGameConfig; /** * A handy reference to renderer.context (only set for CANVAS games, not WebGL) */ context: CanvasRenderingContext2D; count: number; /** * The Asset Generator. */ create: Phaser.Create; /** * A set of useful debug utilities. */ debug: Phaser.Utils.Debug; /** * Contains device information and capabilities. */ device: Phaser.Device; /** * Skip a logic update and render if the delta is too large (see {@link Phaser.Time#deltaMax}). */ dropFrames: boolean; /** * Should the game loop make one render per animation frame, even without a preceding logic update? */ forceSingleRender: boolean; /** * Use a variable-step game loop (true) or a fixed-step game loop (false). * Default: true */ forceSingleUpdate: boolean; /** * If the game is struggling to maintain the desired FPS, this signal will be dispatched. * The desired/chosen FPS should probably be closer to the {@link Phaser.Time#suggestedFps} value. */ fpsProblemNotifier: Phaser.Signal; /** * The current Game Height in pixels. * * _Do not modify this property directly:_ use {@link Phaser.ScaleManager#setGameSize} - e.g. `game.scale.setGameSize(width, height)` - instead. * Default: 600 */ height: number; /** * Phaser Game ID */ id: number; /** * Reference to the input manager */ input: Phaser.Input; /** * Whether the game engine is booted, aka available. */ isBooted: boolean; /** * Is game running or paused? */ isRunning: boolean; /** * Reference to the assets loader. */ load: Phaser.Loader; /** * If `false` Phaser will automatically render the display list every update. If `true` the render loop will be skipped. * You can toggle this value at run-time to gain exact control over when Phaser renders. This can be useful in certain types of game or application. * Please note that if you don't render the display list then none of the game object transforms will be updated, so use this value carefully. */ lockRender: boolean; /** * Reference to the GameObject Creator. */ make: Phaser.GameObjectCreator; /** * Reference to the math helper. */ math: Phaser.Math; /** * This event is fired when the game no longer has focus (typically on page hide). */ onBlur: Phaser.Signal; /** * This event is fired after the game boots but before the first game update. */ onBoot: Phaser.Signal; /** * This event is fired when the game has focus (typically on page show). */ onFocus: Phaser.Signal; /** * This event is fired when the game pauses. */ onPause: Phaser.Signal; /** * This event is fired when the game resumes from a paused state. */ onResume: Phaser.Signal; /** * The Game's DOM parent (or name thereof), if any, as set when the game was created. The actual parent can be found in `game.canvas.parentNode`. Setting this has no effect after {@link Phaser.ScaleManager} is booted. */ parent: HTMLElement; /** * The Particle Manager. */ particles: Phaser.Particles; /** * The paused state of the Game. A paused game doesn't update any of its subsystems. * When a game is paused the onPause event is dispatched. When it is resumed the onResume event is dispatched. Gets and sets the paused state of the Game. */ paused: boolean; /** * Destroy the game at the next update. */ pendingDestroy: boolean; /** * An internal property used by enableStep, but also useful to query from your own game objects. */ pendingStep: boolean; /** * Reference to the physics manager. */ physics: Phaser.Physics; /** * The Phaser.Physics.World configuration object. */ physicsConfig: any; /** * Reference to the plugin manager. */ plugins: PluginManager; /** * When the WebGL renderer is used, hint to the browser which GPU to use. * Default: default */ powerPreference: string; /** * The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering. */ preserveDrawingBuffer: Boolean; /** * Automatically handles the core game loop via requestAnimationFrame or setTimeout */ raf: Phaser.RequestAnimationFrame; /** * The Pixi Renderer. */ renderer: PIXI.CanvasRenderer | PIXI.WebGLRenderer; /** * The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS, Phaser.WEBGL, Phaser.WEBGL_MULTI or Phaser.HEADLESS. After the game boots, renderType reflects the renderer in use: AUTO changes to CANVAS or WEBGL and WEBGL_MULTI changes to WEBGL. HEADLESS skips `preRender`, `render`, and `postRender` hooks, just like {@link Phaser.Game#lockRender lockRender}. */ renderType: number; /** * The resolution of your game, as a ratio of canvas pixels to game pixels. This value is read only, but can be changed at start time it via a game configuration object. * Default: 1 */ resolution: number; /** * Instance of repeatable random data generator helper. */ rnd: Phaser.RandomDataGenerator; /** * The game scale manager. */ scale: Phaser.ScaleManager; scratch: Phaser.BitmapData; /** * Reference to the sound manager. */ sound: Phaser.SoundManager; /** * Reference to the stage. */ stage: Phaser.Stage; /** * The StateManager. */ state: Phaser.StateManager; /** * When stepping is enabled this contains the current step cycle. */ stepCount: number; /** * Enable core loop stepping with Game.enableStep(). */ stepping: boolean; /** * Reference to the core game clock. */ time: Phaser.Time; /** * Use a transparent canvas background or not. */ transparent: boolean; /** * Reference to the tween manager. */ tweens: Phaser.TweenManager; /** * The ID of the current/last logic update applied this animation frame, starting from 0. * The first update is `currentUpdateID === 0` and the last update is `currentUpdateID === updatesThisFrame.` */ currentUpdateID: number; /** * Number of logic updates expected to occur this animation frame; will be 1 unless there are catch-ups required (and allowed). */ updatesThisFrame: number; /** * The current Game Width in pixels. * * _Do not modify this property directly:_ use {@link Phaser.ScaleManager#setGameSize} - e.g. `game.scale.setGameSize(width, height)` - instead. * Default: 800 */ width: number; /** * Reference to the world. */ world: Phaser.World; /** * Initialize engine sub modules and start the game. */ boot(): void; /** * Nukes the entire game from orbit. * * Calls destroy on Game.state, Game.sound, Game.scale, Game.stage, Game.input, Game.physics and Game.plugins. * * Then sets all of those local handlers to null, destroys the renderer, removes the canvas from the DOM * and resets the PIXI default renderer. * * To destroy the game during an update callback, set {@link Phaser.Game#pendingDestroy pendingDestroy} instead. */ destroy(): void; /** * Disables core game loop stepping. */ disableStep(): void; /** * Enable core game loop stepping. When enabled you must call game.step() directly (perhaps via a DOM button?) * Calling step will advance the game loop by one frame. This is extremely useful for hard to track down errors! */ enableStep(): void; /** * Called by the Stage visibility handler. * * @param event The DOM event that caused the game to pause, if any. */ focusGain(event: any): void; /** * Called by the Stage visibility handler. * * @param event The DOM event that caused the game to pause, if any. */ focusLoss(event: any): void; /** * Called by the Stage visibility handler. * * @param event The DOM event that caused the game to pause, if any. */ gamePaused(event: any): void; /** * Called by the Stage visibility handler. * * @param event The DOM event that caused the game to pause, if any. */ gameResumed(event: any): void; /** * Parses a Game configuration object. */ parseConfig(config: any): void; removeFromDOM(canvas: HTMLCanvasElement): void; /** * Checks if the device is capable of using the requested renderer and sets it up or an alternative if not. */ setUpRenderer(): void; /** * Displays a Phaser version debug header in the console. */ showDebugHeader(): void; /** * When stepping is enabled you must call this function directly (perhaps via a DOM button?) to advance the game loop by one frame. * This is extremely useful to hard to track down errors! Use the internal stepCount property to monitor progress. */ step(): void; /** * The core game loop. * * @param time The current time in milliseconds as provided by RequestAnimationFrame. */ update(time: number): void; /** * Updates all logic subsystems in Phaser. Called automatically by Game.update. * * @param delta The current time step value in seconds, as determined by Game.update. */ updateLogic(timeStep: number): void; /** * Runs the Render cycle. * It starts by calling State.preRender. In here you can do any last minute adjustments of display objects as required. * It then calls the renderer, which renders the entire display list, starting from the Stage object and working down. * It then calls plugin.render on any loaded plugins, in the order in which they were enabled. * After this State.render is called. Any rendering that happens here will take place on-top of the display list. * Finally plugin.postRender is called on any loaded plugins, in the order in which they were enabled. * This method is called automatically by Game.update, you don't need to call it directly. * Should you wish to have fine-grained control over when Phaser renders then use the `Game.lockRender` boolean. * Phaser will only render when this boolean is `false`. */ updateRender(timeStep: number): void; } /** * The GameObjectCreator is a quick way to create common game objects _without_ adding them to the game world. * The object creator can be accessed with {@linkcode Phaser.Game#make `game.make`}. */ class GameObjectCreator { /** * The GameObjectCreator is a quick way to create common game objects _without_ adding them to the game world. * The object creator can be accessed with {@linkcode Phaser.Game#make `game.make`}. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * A reference to the currently running Game. */ game: Phaser.Game; /** * A reference to the game world. */ world: Phaser.World; /** * Creates a new Sound object. * * @param key The Game.cache key of the sound that this object will use. * @param volume The volume at which the sound will be played. - Default: 1 * @param loop Whether or not the sound will loop. * @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true * @return The newly created text object. */ audio(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound; /** * Creates a new AudioSprite object. * * @param key The Game.cache key of the sound that this object will use. * @return The newly created AudioSprite object. */ audioSprite(key: string): Phaser.AudioSprite; /** * Create a BitmpaData object. * * A BitmapData object can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites. * * @param width The width of the BitmapData in pixels. - Default: 256 * @param height The height of the BitmapData in pixels. - Default: 256 * @param key Asset key for the BitmapData when stored in the Cache (see addToCache parameter). - Default: '' * @param addToCache Should this BitmapData be added to the Game.Cache? If so you can retrieve it with Cache.getBitmapData(key) * @return The newly created BitmapData object. */ bitmapData(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.BitmapData; /** * Create a new BitmapText object. * * BitmapText objects work by taking a texture file and an XML file that describes the font structure. * It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to * match the font structure. * * BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability * to use Web Fonts. However you trade this flexibility for pure rendering speed. You can also create visually compelling BitmapTexts by * processing the font texture in an image editor first, applying fills and any other effects required. * * To create multi-line text insert \r, \n or \r\n escape codes into the text string. * * To create a BitmapText data files you can use: * * 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/ * * @param x X coordinate to display the BitmapText object at. * @param y Y coordinate to display the BitmapText object at. * @param font The key of the BitmapText as stored in Phaser.Cache. * @param text The text that will be rendered. This can also be set later via BitmapText.text. - Default: '' * @param size The size the font will be rendered at in pixels. - Default: 32 * @param align The alignment of multi-line text. Has no effect if there is only one line of text. - Default: 'left' * @return The newly created bitmapText object. */ bitmapText(x: number, y: number, font: string, text?: string, size?: number, align?: string): Phaser.BitmapText; /** * Creates a new Button object. * * @param x X position of the new button object. * @param y Y position of the new button object. * @param key The image key as defined in the Game.Cache to use as the texture for this button. * @param callback The function to call when this button is pressed * @param callbackContext The context in which the callback will be called (usually 'this') * @param overFrame This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param outFrame This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param downFrame This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. * @param upFrame This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. * @return The newly created button object. */ button(x?: number, y?: number, key?: string, callback?: Function, callbackContext?: any, overFrame?: any, outFrame?: any, downFrame?: any, upFrame?: any): Phaser.Button; /** * Creat a new Emitter. * * An Emitter is a lightweight particle emitter. It can be used for one-time explosions or for * continuous effects like rain and fire. All it really does is launch Particle objects out * at set intervals, and fixes their positions and velocities accorindgly. * * @param x The x coordinate within the Emitter that the particles are emitted from. * @param y The y coordinate within the Emitter that the particles are emitted from. * @param maxParticles The total number of particles in this emitter. - Default: 50 * @return The newly created emitter object. */ emitter(x?: number, y?: number, maxParticles?: number): Phaser.Particles.Arcade.Emitter; /** * A WebGL shader/filter that can be applied to Sprites. * * @param filter The name of the filter you wish to create, for example HueRotate or SineWave. * @param undefined Whatever parameters are needed to be passed to the filter init function. * @return The newly created Phaser.Filter object. */ filter(filter: any, ...args: any[]): Phaser.Filter; /** * Creates a new Graphics object. * * @param x X position of the new graphics object. * @param y Y position of the new graphics object. * @return The newly created graphics object. */ graphics(x?: number, y?: number): Phaser.Graphics; /** * A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * * @param parent The parent Group or DisplayObjectContainer that will hold this group, if any. `undefined`, `null`, or `false` will assign no parent. * @param name A name for this Group. Not used internally but useful for your debugging. - Default: 'group' * @param addToStage If set to true this Group will be added directly to `game.stage`. * @param enableBody If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType. * @param physicsBodyType If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc. * @return The newly created Group. */ group(parent?: any, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number): Phaser.Group; /** * Create a new Image object. * * An Image is a light-weight object you can use to display anything that doesn't need physics or animation. * It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics. * * @param x X position of the image. * @param y Y position of the image. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. * @return the newly created sprite object. */ image(x: number, y: number, key?: any, frame?: any): Phaser.Image; /** * A dynamic initially blank canvas to which images can be drawn. * * @param width the width of the RenderTexture. - Default: 100 * @param height the height of the RenderTexture. - Default: 100 * @param key Asset key for the RenderTexture when stored in the Cache (see addToCache parameter). - Default: '' * @param addToCache Should this RenderTexture be added to the Game.Cache? If so you can retrieve it with Cache.getTexture(key) * @return The newly created RenderTexture object. */ renderTexture(width?: number, height?: number, key?: any, addToCache?: boolean): Phaser.RenderTexture; /** * Create a new RetroFont object. * * A RetroFont can be used as a texture for an Image or Sprite and optionally add it to the Cache. * A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set. * If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText * is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text. * The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all, * i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects. * * @param font The key of the image in the Game.Cache that the RetroFont will use. * @param characterWidth The width of each character in the font set. * @param characterHeight The height of each character in the font set. * @param chars The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. * @param charsPerRow The number of characters per row in the font set. * @param xSpacing If the characters in the font set have horizontal spacing between them set the required amount here. * @param ySpacing If the characters in the font set have vertical spacing between them set the required amount here. * @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. * @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. * @return The newly created RetroFont texture which can be applied to an Image or Sprite. */ retroFont(font: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number): Phaser.RetroFont; /** * Creates a new Rope object. * * @param x The x coordinate (in world space) to position the Rope at. * @param y The y coordinate (in world space) to position the Rope at. * @param width The width of the Rope. * @param height The height of the Rope. * @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The newly created rope object. */ rope(x: number, y: number, key: any, frame?: any, points?: Phaser.Point[]): Phaser.Rope; /** * Creates a new Sound object. * * @param key The Game.cache key of the sound that this object will use. * @param volume The volume at which the sound will be played. - Default: 1 * @param loop Whether or not the sound will loop. * @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true * @return The newly created text object. */ sound(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound; /** * Create a new Sprite with specific position and sprite sheet key. * * @param x X position of the new sprite. * @param y Y position of the new sprite. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. * @return the newly created sprite object. */ sprite(x: number, y: number, key?: any, frame?: any): Phaser.Sprite; /** * Create a new SpriteBatch. * * @param parent The parent Group or DisplayObjectContainer that will hold this group, if any. * @param name A name for this Group. Not used internally but useful for debugging. - Default: 'group' * @param addToStage If set to true this Group will be added directly to the Game.Stage instead of Game.World. * @return The newly created group. */ spriteBatch(parent: any, name?: String, addToStage?: boolean): Phaser.SpriteBatch; /** * Creates a new Text object. * * @param x X position of the new text object. * @param y Y position of the new text object. * @param text The actual text that will be written. * @param style The style object containing style attributes like font, font size , etc. * @return The newly created text object. */ text(x: number, y: number, text?: string, style?: PhaserTextStyle): Phaser.Text; /** * Creates a new Phaser.Tilemap object. * * The map can either be populated with data from a Tiled JSON file or from a CSV file. * To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key. * When using CSV data you must provide the key and the tileWidth and tileHeight parameters. * If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here. * 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 it. * * @param key The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`. * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 */ tilemap(key: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): Phaser.Tilemap; /** * Creates a new TileSprite object. * * @param x The x coordinate (in world space) to position the TileSprite at. * @param y The y coordinate (in world space) to position the TileSprite at. * @param width The width of the TileSprite. * @param height The height of the TileSprite. * @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Phaser Image Cache entry, or an instance of a PIXI.Texture or BitmapData. * @param frame If this TileSprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The newly created tileSprite object. */ tileSprite(x: number, y: number, width: number, height: number, key: any, frame: any): Phaser.TileSprite; /** * Create a tween object for a specific object. * * The object can be any JavaScript object or Phaser object such as Sprite. * * @param obj Object the tween will be run on. * @return The Tween object. */ tween(obj: any): Phaser.Tween; } /** * The GameObjectFactory is a quick way to create many common game objects * using {@linkcode Phaser.Game#add `game.add`}. * * Created objects are _automatically added_ to the appropriate Manager, World, or manually specified parent Group. */ class GameObjectFactory { /** * The GameObjectFactory is a quick way to create many common game objects * using {@linkcode Phaser.Game#add `game.add`}. * * Created objects are _automatically added_ to the appropriate Manager, World, or manually specified parent Group. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * A reference to the currently running Game. */ game: Phaser.Game; /** * A reference to the game world. */ world: Phaser.World; /** * Creates a new Sound object. * * @param key The Game.cache key of the sound that this object will use. * @param volume The volume at which the sound will be played. - Default: 1 * @param loop Whether or not the sound will loop. * @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true * @return The newly created sound object. */ audio(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound; /** * Creates a new AudioSprite object. * * @param key The Game.cache key of the sound that this object will use. * @return The newly created AudioSprite object. */ audioSprite(key: string): Phaser.AudioSprite; /** * Create a BitmapData object. * * A BitmapData object can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites. * * @param width The width of the BitmapData in pixels. - Default: 256 * @param height The height of the BitmapData in pixels. - Default: 256 * @param key Asset key for the BitmapData when stored in the Cache (see addToCache parameter). - Default: '' * @param addToCache Should this BitmapData be added to the Game.Cache? If so you can retrieve it with Cache.getBitmapData(key) * @return The newly created BitmapData object. */ bitmapData(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.BitmapData; /** * Create a new BitmapText object. * * BitmapText objects work by taking a texture file and an XML file that describes the font structure. * It then generates a new Sprite object for each letter of the text, proportionally spaced out and aligned to * match the font structure. * * BitmapText objects are less flexible than Text objects, in that they have less features such as shadows, fills and the ability * to use Web Fonts. However you trade this flexibility for pure rendering speed. You can also create visually compelling BitmapTexts by * processing the font texture in an image editor first, applying fills and any other effects required. * * To create multi-line text insert \r, \n or \r\n escape codes into the text string. * * To create a BitmapText data files you can use: * * 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/ * * @param x X coordinate to display the BitmapText object at. * @param y Y coordinate to display the BitmapText object at. * @param font The key of the BitmapText as stored in Phaser.Cache. * @param text The text that will be rendered. This can also be set later via BitmapText.text. - Default: '' * @param size The size the font will be rendered at in pixels. - Default: 32 * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created bitmapText object. */ bitmapText(x: number, y: number, font: string, text?: string, size?: number, group?: Phaser.Group | Phaser.Stage): Phaser.BitmapText; /** * Creates a new Button object. * * @param x The x coordinate of the Button. The coordinate is relative to any parent container this button may be in. * @param y The y coordinate of the Button. The coordinate is relative to any parent container this button may be in. * @param key The image key as defined in the Game.Cache to use as the texture for this button. * @param callback The function to call when this button is pressed * @param callbackContext The context in which the callback will be called (usually 'this') * @param overFrame This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. * @param outFrame This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. * @param downFrame This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. * @param upFrame This is the frame or frameName that will be set when this button is in an up state. Give either a number to use a frame ID or a string for a frame name. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created Button object. */ button(x?: number, y?: number, key?: string, callback?: Function, callbackContext?: any, overFrame?: any, outFrame?: any, downFrame?: any, upFrame?: any, group?: Phaser.Group | Phaser.Stage): Phaser.Button; /** * Create a new Emitter. * * A particle emitter can be used for one-time explosions or for * continuous effects like rain and fire. All it really does is launch Particle objects out * at set intervals, and fixes their positions and velocities accordingly. * * @param x The x coordinate within the Emitter that the particles are emitted from. * @param y The y coordinate within the Emitter that the particles are emitted from. * @param maxParticles The total number of particles in this emitter. - Default: 50 * @return The newly created emitter object. */ emitter(x?: number, y?: number, maxParticles?: number): Phaser.Particles.Arcade.Emitter; /** * Adds an existing display object to the game world. * * @param object An instance of Phaser.Sprite, Phaser.Button or any other display object. * @return The child that was added to the World. */ existing(object: any): any; /** * A WebGL shader/filter that can be applied to Sprites. * * @param filter The name of the filter you wish to create, for example HueRotate or SineWave. * @param undefined Whatever parameters are needed to be passed to the filter init function. * @return The newly created Phaser.Filter object. */ filter(filter: string, ...args: any[]): Phaser.Filter; /** * Creates a new Graphics object. * * @param x The x coordinate of the Graphic. The coordinate is relative to any parent container this object may be in. * @param y The y coordinate of the Graphic. The coordinate is relative to any parent container this object may be in. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created graphics object. */ graphics(x?: number, y?: number, group?: Phaser.Group | Phaser.Stage): Phaser.Graphics; /** * A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * * @param parent The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default. * @param name A name for this Group. Not used internally but useful for debugging. - Default: 'group' * @param addToStage If set to true this Group will be added directly to the Game.Stage instead of Game.World. * @param enableBody If true all Sprites created with `Group.create` or `Group.createMulitple` will have a physics body created on them. Change the body type with physicsBodyType. * @param physicsBodyType If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2, Phaser.Physics.NINJA, etc. * @return The newly created Group. */ group(parent?: any, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number): Phaser.Group; /** * Create a new `Image` object. * * An Image is a light-weight object you can use to display anything that doesn't need physics or animation. * * It can still rotate, scale, crop and receive input events. * This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics. * * @param x The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in. * @param y The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in. * @param key The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created Image object. */ image(x?: number, y?: number, key?: any, frame?: any, group?: Phaser.Group | Phaser.Stage): Phaser.Image; /** * A Group is a container for display objects that allows for fast pooling, recycling and collision checks. * * A Physics Group is the same as an ordinary Group except that is has enableBody turned on by default, so any Sprites it creates * are automatically given a physics body. * * @param physicsBodyType If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2JS, Phaser.Physics.NINJA, etc. - Default: Phaser.Physics.ARCADE * @param parent The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default. * @param name A name for this Group. Not used internally but useful for debugging. - Default: 'group' * @param addToStage If set to true this Group will be added directly to the Game.Stage instead of Game.World. * @return The newly created Group. */ physicsGroup(physicsBodyType?: number, parent?: any, name?: string, addToStage?: boolean): Phaser.Group; /** * Add a new Plugin into the PluginManager. * * The Plugin must have 2 properties: `game` and `parent`. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager. * * @param plugin The Plugin to add into the PluginManager. This can be a function or an existing object. * @param args Additional parameters that will be passed to the Plugin.init method. * @return The Plugin that was added to the manager. */ plugin(plugin: Phaser.Plugin, ...parameter: any[]): Phaser.Plugin; /** * A dynamic initially blank canvas to which images can be drawn. * * @param width the width of the RenderTexture. - Default: 100 * @param height the height of the RenderTexture. - Default: 100 * @param key Asset key for the RenderTexture when stored in the Cache (see addToCache parameter). - Default: '' * @param addToCache Should this RenderTexture be added to the Game.Cache? If so you can retrieve it with Cache.getTexture(key) * @return The newly created RenderTexture object. */ renderTexture(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.RenderTexture; /** * Create a new RetroFont object. * * A RetroFont can be used as a texture for an Image or Sprite and optionally add it to the Cache. * A RetroFont uses a bitmap which contains fixed with characters for the font set. You use character spacing to define the set. * If you need variable width character support then use a BitmapText object instead. The main difference between a RetroFont and a BitmapText * is that a RetroFont creates a single texture that you can apply to a game object, where-as a BitmapText creates one Sprite object per letter of text. * The texture can be asssigned or one or multiple images/sprites, but note that the text the RetroFont uses will be shared across them all, * i.e. if you need each Image to have different text in it, then you need to create multiple RetroFont objects. * * @param font The key of the image in the Game.Cache that the RetroFont will use. * @param characterWidth The width of each character in the font set. * @param characterHeight The height of each character in the font set. * @param chars The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. * @param charsPerRow The number of characters per row in the font set. * @param xSpacing If the characters in the font set have horizontal spacing between them set the required amount here. * @param ySpacing If the characters in the font set have vertical spacing between them set the required amount here. * @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. * @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. * @return The newly created RetroFont texture which can be applied to an Image or Sprite. */ retroFont(font: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number): Phaser.RetroFont; /** * Creates a new Rope object. * * Example usage: https://github.com/codevinsky/phaser-rope-demo/blob/master/dist/demo.js * * @param x The x coordinate of the Rope. The coordinate is relative to any parent container this rope may be in. * @param y The y coordinate of the Rope. The coordinate is relative to any parent container this rope may be in. * @param key The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name. * @param points An array of {Phaser.Point}. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created Rope object. */ rope(x?: number, y?: number, key?: any, frame?: any, points?: Phaser.Point[]): Phaser.Rope; /** * Creates a new Sound object. * * @param key The Game.cache key of the sound that this object will use. * @param volume The volume at which the sound will be played. - Default: 1 * @param loop Whether or not the sound will loop. * @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true * @return The newly created sound object. */ sound(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound; /** * Create a new Sprite with specific position and sprite sheet key. * * At its most basic a Sprite consists of a set of coordinates and a texture that is used when rendered. * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. * * @param x The x coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in. * @param y The y coordinate of the sprite. The coordinate is relative to any parent container this sprite may be in. * @param key The image used as a texture by this display object during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created Sprite object. */ sprite(x?: number, y?: number, key?: any, frame?: any, group?: Phaser.Group | Phaser.Stage): Phaser.Sprite; /** * A SpriteBatch is a really fast version of a Phaser Group built solely for speed. * Use when you need a lot of sprites or particles all sharing the same texture. * The speed gains are specifically for WebGL. In Canvas mode you won't see any real difference. * * @param parent The parent Group that will hold this Sprite Batch. Set to `undefined` or `null` to add directly to game.world. * @param name A name for this Sprite Batch. Not used internally but useful for debugging. - Default: 'group' * @param addToStage If set to true this Sprite Batch will be added directly to the Game.Stage instead of the parent. * @return The newly created Sprite Batch. */ spriteBatch(parent: any, name?: string, addToStage?: boolean): Phaser.SpriteBatch; /** * Creates a new Text object. * * @param x The x coordinate of the Text. The coordinate is relative to any parent container this text may be in. * @param y The y coordinate of the Text. The coordinate is relative to any parent container this text may be in. * @param text The text string that will be displayed. - Default: '' * @param style The style object containing style attributes like font, font size , etc. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created text object. */ text(x?: number, y?: number, text?: string, style?: PhaserTextStyle, group?: Phaser.Group | Phaser.Stage): Phaser.Text; /** * Creates a new Phaser.Tilemap object. * * The map can either be populated with data from a Tiled JSON file or from a CSV file. * To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key. * When using CSV data you must provide the key and the tileWidth and tileHeight parameters. * If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here. * 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 it. * * @param key The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`. * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @return The newly created tilemap object. */ tilemap(key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): Phaser.Tilemap; /** * Creates a new TileSprite object. * * @param x The x coordinate of the TileSprite. The coordinate is relative to any parent container this TileSprite may be in. * @param y The y coordinate of the TileSprite. The coordinate is relative to any parent container this TileSprite may be in. * @param width The width of the TileSprite. * @param height The height of the TileSprite. * @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Phaser Image Cache entry, or an instance of a PIXI.Texture or BitmapData. * @param frame If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used. Use either an integer for a Frame ID or a string for a frame name. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The newly created TileSprite object. */ tileSprite(x: number, y: number, width: number, height: number, key?: any, frame?: any, group?: Phaser.Group | Phaser.Stage): Phaser.TileSprite; /** * Create a tween on a specific object. * * The object can be any JavaScript object or Phaser object such as Sprite. * * @param object Object the tween will be run on. * @return The newly created Phaser.Tween object. */ tween(obj: any): Phaser.Tween; /** * Weapons provide the ability to easily create a bullet pool and manager. * * Weapons fire Phaser.Bullet objects, which are essentially Sprites with a few extra properties. * The Bullets are enabled for Arcade Physics. They do not currently work with P2 Physics. * * The Bullets are created inside of `Weapon.bullets`, which is a Phaser.Group instance. Anything you * can usually do with a Group, such as move it around the display list, iterate it, etc can be done * to the bullets Group too. * * Bullets can have textures and even animations. You can control the speed at which they are fired, * the firing rate, the firing angle, and even set things like gravity for them. * * @param quantity The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand. - Default: 1 * @param key The image used as a texture by the bullets during rendering. If a string Phaser will get for an entry in the Image Cache. Or it can be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If a Texture Atlas or Sprite Sheet is used this allows you to specify the frame to be used by the bullets. Use either an integer for a Frame ID or a string for a frame name. * @param group Optional Group to add the Weapon to. If not specified it will be added to the World group. * @param bulletClass The Class of the bullets that are launched by this Weapon. See {@link Phaser.Weapon#bulletClass} * @return A Weapon instance. */ weapon(quantity?: number, key?: any, frame?: any, group?: Phaser.Group, bulletClass?: Phaser.Bullet): Phaser.Weapon; /** * Create a Video object. * * This will return a Phaser.Video object which you can pass to a Sprite to be used as a texture. * * @param key The key of the video file in the Phaser.Cache that this Video object will play. Set to `null` or leave undefined if you wish to use a webcam as the source. See `startMediaStream` to start webcam capture. * @param url If the video hasn't been loaded then you can provide a full URL to the file here (make sure to set key to null) * @return The newly created Video object. */ video(key?: string, url?: string): Phaser.Video; } /** * The Gamepad class handles gamepad input and dispatches gamepad events. * * Remember to call `gamepad.start()`. * * HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE! * At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it * via prefs flags (about:config, search gamepad). The browsers map the same controllers differently. * This class has constants for Windows 7 Chrome mapping of XBOX 360 controller. */ class Gamepad { /** * The Gamepad class handles gamepad input and dispatches gamepad events. * * Remember to call `gamepad.start()`. * * HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE! * At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it * via prefs flags (about:config, search gamepad). The browsers map the same controllers differently. * This class has constants for Windows 7 Chrome mapping of XBOX 360 controller. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); static BUTTON_0: number; static BUTTON_1: number; static BUTTON_2: number; static BUTTON_3: number; static BUTTON_4: number; static BUTTON_5: number; static BUTTON_6: number; static BUTTON_7: number; static BUTTON_8: number; static BUTTON_9: number; static BUTTON_10: number; static BUTTON_11: number; static BUTTON_12: number; static BUTTON_13: number; static BUTTON_14: number; static BUTTON_15: number; static AXIS_0: number; static AXIS_1: number; static AXIS_2: number; static AXIS_3: number; static AXIS_4: number; static AXIS_5: number; static AXIS_6: number; static AXIS_7: number; static AXIS_8: number; static AXIS_9: number; static XBOX360_A: number; static XBOX360_B: number; static XBOX360_X: number; static XBOX360_Y: number; static XBOX360_LEFT_BUMPER: number; static XBOX360_RIGHT_BUMPER: number; static XBOX360_LEFT_TRIGGER: number; static XBOX360_RIGHT_TRIGGER: number; static XBOX360_BACK: number; static XBOX360_START: number; static XBOX360_STICK_LEFT_BUTTON: number; static XBOX360_STICK_RIGHT_BUTTON: number; static XBOX360_DPAD_LEFT: number; static XBOX360_DPAD_RIGHT: number; static XBOX360_DPAD_UP: number; static XBOX360_DPAD_DOWN: number; static XBOX360_STICK_LEFT_X: number; static XBOX360_STICK_LEFT_Y: number; static XBOX360_STICK_RIGHT_X: number; static XBOX360_STICK_RIGHT_Y: number; static PS3XC_X: number; static PS3XC_CIRCLE: number; static PS3XC_SQUARE: number; static PS3XC_TRIANGLE: number; static PS3XC_L1: number; static PS3XC_R1: number; static PS3XC_L2: number; static PS3XC_R2: number; static PS3XC_SELECT: number; static PS3XC_START: number; static PS3XC_STICK_LEFT_BUTTON: number; static PS3XC_STICK_RIGHT_BUTTON: number; static PS3XC_DPAD_UP: number; static PS3XC_DPAD_DOWN: number; static PS3XC_DPAD_LEFT: number; static PS3XC_DPAD_RIGHT: number; static PS3XC_STICK_LEFT_X: number; static PS3XC_STICK_LEFT_Y: number; static PS3XC_STICK_RIGHT_X: number; static PS3XC_STICK_RIGHT_Y: number; /** * If the gamepad input is active or not - if not active it should not be updated from Input.js */ active: boolean; /** * The context under which the callbacks are run. */ callbackContext: any; /** * Gamepad input will only be processed if enabled. * Default: true */ enabled: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * This callback is invoked every time any gamepad axis is changed. */ onAxisCallback: Function; /** * This callback is invoked every time any gamepad is connected */ onConnectCallback: Function; /** * This callback is invoked every time any gamepad is disconnected */ onDisconnectCallback: Function; /** * This callback is invoked every time any gamepad button is pressed down. */ onDownCallback: Function; /** * This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1. */ onFloatCallback: Function; /** * This callback is invoked every time any gamepad button is released. */ onUpCallback: Function; /** * Gamepad #1 */ pad1: Phaser.SinglePad; /** * Gamepad #2 */ pad2: Phaser.SinglePad; /** * Gamepad #3 */ pad3: Phaser.SinglePad; /** * Gamepad #4 */ pad4: Phaser.SinglePad; /** * How many live gamepads are currently connected. */ padsConnected: number; /** * Whether or not gamepads are supported in current browser. */ supported: boolean; /** * Add callbacks to the main Gamepad handler to handle connect/disconnect/button down/button up/axis change/float value buttons. * * @param context The context under which the callbacks are run. * @param callbacks Object that takes six different callback methods: * onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback */ addCallbacks(context: any, callbacks: any): void; /** * Returns true if the button is currently pressed down, on ANY gamepad. * * @param buttonCode The buttonCode of the button to check for. * @return True if a button is currently down. */ isDown(buttonCode: number): boolean; /** * Returns the "just pressed" state of a button from ANY gamepad connected. Just pressed is considered true if the button was pressed down within the duration given (default 250ms). * * @param buttonCode The buttonCode of the button to check for. * @param duration The duration below which the button is considered as being just pressed. - Default: 250 * @return True if the button is just pressed otherwise false. */ justPressed(buttonCode: number, duration?: number): boolean; justReleased(buttonCode: number, duration?: number): boolean; /** * Reset all buttons/axes of all gamepads */ reset(): void; /** * Sets the deadZone variable for all four gamepads */ setDeadZones(value: any): void; /** * Starts the Gamepad event handling. * This MUST be called manually before Phaser will start polling the Gamepad API. */ start(): void; /** * Stops the Gamepad event handling. */ stop(): void; /** * Main gamepad update loop. Should not be called manually. */ update(): void; } /** * A Graphics object is a way to draw primitives 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 object it will * be empty. To 'draw' to it you first specify a lineStyle or fillStyle (or both), and then draw a shape. For example: * * ```javascript * graphics.beginFill(0xff0000); * graphics.drawCircle(50, 50, 100); * graphics.endFill(); * ``` * * This will draw a circle shape to the Graphics object, with a diameter of 100, located at x: 50, y: 50. * * When a Graphics object is rendered it will render differently based on if the game is running under Canvas or * WebGL. Under Canvas it will use the HTML Canvas context drawing operations to draw the path. Under WebGL the * graphics data is decomposed into polygons. Both of these are expensive processes, especially with complex shapes. * * If your Graphics object doesn't change much (or at all) once you've drawn your shape to it, then you will help * performance by calling `Graphics.generateTexture`. This will 'bake' the Graphics object into a Texture, and return it. * You can then use this Texture for Sprites or other display objects. If your Graphics object updates frequently then * you should avoid doing this, as it will constantly generate new textures, which will consume memory. * * As you can tell, Graphics objects are a bit of a trade-off. While they are extremely useful, you need to be careful * in their complexity and quantity of them in your game. * * You may have to modify {@link Phaser.Graphics#scale} rather than {@link Phaser.Graphics#width} or * {@link Phaser.Graphics#height} to avoid an unusual race condition * ({@link #489 https://github.com/photonstorm/phaser-ce/issues/489}). */ class Graphics extends PIXI.DisplayObjectContainer { /** * A Graphics object is a way to draw primitives 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 object it will * be empty. To 'draw' to it you first specify a lineStyle or fillStyle (or both), and then draw a shape. For example: * * ```javascript * graphics.beginFill(0xff0000); * graphics.drawCircle(50, 50, 100); * graphics.endFill(); * ``` * * This will draw a circle shape to the Graphics object, with a diameter of 100, located at x: 50, y: 50. * * When a Graphics object is rendered it will render differently based on if the game is running under Canvas or * WebGL. Under Canvas it will use the HTML Canvas context drawing operations to draw the path. Under WebGL the * graphics data is decomposed into polygons. Both of these are expensive processes, especially with complex shapes. * * If your Graphics object doesn't change much (or at all) once you've drawn your shape to it, then you will help * performance by calling `Graphics.generateTexture`. This will 'bake' the Graphics object into a Texture, and return it. * You can then use this Texture for Sprites or other display objects. If your Graphics object updates frequently then * you should avoid doing this, as it will constantly generate new textures, which will consume memory. * * As you can tell, Graphics objects are a bit of a trade-off. While they are extremely useful, you need to be careful * in their complexity and quantity of them in your game. * * You may have to modify {@link Phaser.Graphics#scale} rather than {@link Phaser.Graphics#width} or * {@link Phaser.Graphics#height} to avoid an unusual race condition * ({@link #489 https://github.com/photonstorm/phaser-ce/issues/489}). * * @param game Current game instance. * @param x X position of the new graphics object. * @param y Y position of the new graphics object. */ constructor(game: Phaser.Game, x?: number, y?: number); /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * The blend mode to be applied to the graphic shape. Apply a value of PIXI.blendModes.NORMAL to reset the blend mode. * Default: PIXI.blendModes.NORMAL; */ blendMode: Phaser.blendModes; /** * `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated * properties and methods via it. * * By default Game Objects won't add themselves to any physics system and their `body` property will be `null`. * * To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object * and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`. * * You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group. * * Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5, * so the physics body is centered on the Game Object. * * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. */ body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The bounds' padding used for bounds calculation. */ boundsPadding: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * The local center x coordinate of the Game Object. * This is the same as `(x - offsetX) + (width / 2)`. */ centerX: number; /** * The local center y coordinate of the Game Object. * This is the same as `(y - offsetY) + (height / 2)`. */ centerY: number; /** * If this is set to `true` the Game Object checks if it is within the World bounds each frame. * * When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event. * * If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event. * * It also optionally kills the Game Object if `outOfBoundsKill` is `true`. * * When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ checkWorldBounds: boolean; /** * The components this Game Object has installed. */ components: any; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Game Object is processed by the core game loop. * If this Game Object has a physics body it also controls if its physics body is updated or not. * When `exists` is set to `false` it will remove its physics body from the physics world if it has one. * It also toggles the `visible` property to false as well. * * Setting `exists` to true will add its physics body back in to the physics world, if it has one. * It will also set the `visible` property to `true`. */ exists: boolean; /** * The alpha value used when filling the Graphics object. */ fillAlpha: number; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set */ height: number; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; /** * Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds. */ inWorld: boolean; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; /** * Whether this shape is being used as a mask. */ isMask: boolean; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * The lifespan allows you to give a Game Object a lifespan in milliseconds. * * Once the Game Object is 'born' you can set this to a positive value. * * It is automatically decremented by `game.time.delta` each frame. * When it reaches zero it will call the `kill` method. * * Very handy for particles, bullets, collectibles, or any other short-lived entity. */ lifespan: number; /** * The color of any lines drawn. * Default: 0 */ lineColor: number; /** * The width (thickness) of any lines drawn. */ lineWidth: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false. */ outOfBoundsKill: boolean; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The const physics body type of this object. */ physicsType: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF (Phaser.Color.WHITE) to reset the tint. * Default: 0xFFFFFF */ tint: number; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The const type of this object. */ type: number; /** * The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set */ width: number; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The multiplied alpha value of this DisplayObject. A value of 1 is fully opaque. A value of 0 is transparent. * This value is the calculated total, based on the alpha values of all parents of this DisplayObjects * in the display list. * * To obtain, and set, the local alpha value, see the `alpha` property. * * Note: This property is only updated at the end of the `updateTransform` call, once per render. Until * that happens this property will contain values based on the previous frame. Be mindful of this if * accessing this property outside of the normal game flow, i.e. from an asynchronous event callback. */ worldAlpha: number; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * The arc method creates an arc/curve (used to create circles, or parts of circles). * * @param cx The x-coordinate of the center of the circle * @param cy The y-coordinate of the center of the circle * @param radius The radius of the circle * @param startAngle The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle) * @param endAngle The ending angle, in radians * @param anticlockwise Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise. * @param segments Optional. The number of segments to use when calculating the arc. The default is 40. If you need more fidelity use a higher number. */ arc(cx: number, cy: number, radius: number, startAngle: number, endAngle: number, anticlockwise: boolean): Phaser.Graphics; /** * The arcTo() method creates an arc/curve between two tangents on the canvas. * * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google! * * @param x1 The x-coordinate of the beginning of the arc * @param y1 The y-coordinate of the beginning of the arc * @param x2 The x-coordinate of the end of the arc * @param y2 The y-coordinate of the end of the arc * @param radius The radius of the arc */ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): Phaser.Graphics; /** * Specifies a simple one-color fill that subsequent calls to other Graphics methods * (such as lineTo() or drawCircle()) use when drawing. * * @param color the color of the fill * @param alpha the alpha of the fill */ beginFill(color?: number, alpha?: number): Phaser.Graphics; /** * Calculate the points for a bezier curve and then draws it. * * @param cpX Control point x * @param cpY Control point y * @param cpX2 Second Control point x * @param cpY2 Second Control point y * @param toX Destination point x * @param toY Destination point y */ bezierCurveTo(cpX: number, cpY: number, cpX2: number, cpY2: number, toX: number, toY: number): Phaser.Graphics; /** * Clears the graphics that were drawn to this Graphics object, and resets fill and line style settings. */ clear(): Phaser.Graphics; /** * Destroy this Graphics instance. * * @param destroyChildren Should every child of this object have its destroy method called? - Default: true */ destroy(destroyChildren?: boolean): void; /** * Destroys a previous cached sprite. */ destroyCachedSprite(): void; /** * Draws a circle. * * @param x The X coordinate of the center of the circle * @param y The Y coordinate of the center of the circle * @param diameter The diameter of the circle */ drawCircle(x: number, y: number, diameter: number): Phaser.Graphics; /** * Draws an ellipse. * * @param centerX The X coordinate of the center of the ellipse * @param centerY The Y coordinate of the center of the ellipse * @param halfWidth The half width of the ellipse * @param halfHeight The half height of the ellipse */ drawEllipse(centerX: number, centerY: number, halfWidth: number, halfHeight: number): Phaser.Graphics; /** * Draws a polygon using the given path. * * @param path The path data used to construct the polygon. Can either be an array of points or a Phaser.Polygon object. */ drawPolygon(...path: any[]): Phaser.Graphics; /** * * * @param x The X coord of the top-left of the rectangle * @param y The Y coord of the top-left of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle */ drawRect(x: number, y: number, width: number, height: number): Phaser.Graphics; /** * * * @param x The X coord of the top-left of the rectangle * @param y The Y coord of the top-left of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @param radius Radius of the rectangle corners. In WebGL this must be a value between 0 and 9. */ drawRoundedRect(x: number, y: number, width: number, height: number, radius: number): Phaser.Graphics; /** * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. * * @param shape The Shape object to draw. * @return The generated GraphicsData object. */ drawShape(shape: Circle): Phaser.GraphicsData; /** * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. * * @param shape The Shape object to draw. * @return The generated GraphicsData object. */ drawShape(shape: Ellipse): Phaser.GraphicsData; /** * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. * * @param shape The Shape object to draw. * @return The generated GraphicsData object. */ drawShape(shape: Polygon): Phaser.GraphicsData; /** * Draws the given shape to this Graphics object. Can be any of Circle, Rectangle, Ellipse, Line or Polygon. * * @param shape The Shape object to draw. * @return The generated GraphicsData object. */ drawShape(shape: Rectangle): Phaser.GraphicsData; /** * Draws a single {@link Phaser.Polygon} triangle from a {@link Phaser.Point} array * * @param points An array of Phaser.Points that make up the three vertices of this triangle * @param cull Should we check if the triangle is back-facing */ drawTriangle(points: Phaser.Point[], cull?: boolean): void; /** * Draws {@link Phaser.Polygon} triangles * * @param vertices An array of Phaser.Points or numbers that make up the vertices of the triangles * @param indices An array of numbers that describe what order to draw the vertices in * @param cull Should we check if the triangle is back-facing */ drawTriangles(vertices: Phaser.Point[] | number[], indices?: number[], cull?: boolean): void; /** * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method. */ endFill(): Phaser.Graphics; /** * Useful function that returns a texture of the graphics object that can then be used to create sprites * This can be quite useful if your geometry is complicated and needs to be reused multiple times. * * Transparent areas adjoining the edges may be removed ({@link https://github.com/photonstorm/phaser-ce/issues/283 #283}). * * @param resolution The resolution of the texture being generated - Default: 1 * @param scaleMode Should be one of the PIXI.scaleMode consts * @param padding Add optional extra padding to the generated texture (default 0) * @return a texture of the graphics object */ generateTexture(resolution?: number, scaleMode?: Phaser.scaleModes, padding?: number): Phaser.RenderTexture; /** * Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false. * * It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal. * * Note that killing a Game Object is a way for you to quickly recycle it in an object pool, * it doesn't destroy the object or free it up from memory. * * If you don't need this Game Object any more you should call `destroy` instead. * @return This instance. */ kill(): Phaser.Graphics; /** * Specifies the line style used for subsequent calls to Graphics methods such as the lineTo() method or the drawCircle() method. * * @param lineWidth width of the line to draw, will update the objects stored style * @param color color of the line to draw, will update the objects stored style * @param alpha alpha of the line to draw, will update the objects stored style */ lineStyle(lineWidth?: number, color?: number, alpha?: number): Phaser.Graphics; /** * Draws a line using the current line style from the current drawing position to (x, y); * The current drawing position is then set to (x, y). * * @param x the X coordinate to draw to * @param y the Y coordinate to draw to */ lineTo(x: number, y: number): Phaser.Graphics; /** * Moves the current drawing position to x, y. * * @param x the X coordinate to move to * @param y the Y coordinate to move to */ moveTo(x: number, y: number): Phaser.Graphics; /** * Automatically called by World */ postUpdate(): void; /** * Automatically called by World.preUpdate. */ preUpdate(): void; /** * Calculate the points for a quadratic bezier curve and then draws it. * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c * * @param cpX Control point x * @param cpY Control point y * @param toX Destination point x * @param toY Destination point y */ quadraticCurveTo(cpX: number, cpY: number, toX: number, toY: number): Phaser.Graphics; /** * Resets the Game Object. * * This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`, * `visible` and `renderable` to true. * * If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value. * * If this Game Object has a Physics Body it will reset the Body. * * @param x The x coordinate (in world space) to position the Game Object at. * @param y The y coordinate (in world space) to position the Game Object at. * @param health The health to give the Game Object if it has the Health component. - Default: 1 * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.Graphics; /** * Brings a 'dead' Game Object back to life, optionally resetting its health value in the process. * * A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true. * * It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal. * * @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100 * @return This instance. */ revive(health?: number): Phaser.Graphics; /** * Override this method in your own custom objects to handle any update requirements. * It is called immediately after `preUpdate` and before `postUpdate`. * Remember if this Game Object has any children you should call update on those too. */ update(): void; } /** * A GraphicsData object. */ class GraphicsData { /** * A GraphicsData object. * * @param lineWidth the width of the line to draw * @param lineColor the color of the line to draw * @param lineAlpha the alpha of the line to draw * @param fillColor the color of the fill * @param fillAlpha the alpha of the fill * @param fill whether or not the shape is filled with a colour * @param shape The shape object to draw. */ constructor(lineWidth?: number, lineColor?: number, lineAlpha?: number, fillColor?: number, fillAlpha?: number, fill?: boolean, shape?: any); lineWidth: number; lineColor: number; lineAlpha: number; fillColor: number; fillAlpha: number; fill: boolean; shape: any; type: number; } /** * A Group is a container for {@link DisplayObject display objects} including {@link Phaser.Sprite Sprites} and {@link Phaser.Image Images}. * * Groups form the logical tree structure of the display/scene graph where local transformations are applied to children. * For instance, all children are also moved/rotated/scaled when the group is moved/rotated/scaled. * * In addition, Groups provides support for fast pooling and object recycling. * * Groups are also display objects and can be nested as children within other Groups. */ class Group extends PIXI.DisplayObjectContainer { /** * A Group is a container for {@link DisplayObject display objects} including {@link Phaser.Sprite Sprites} and {@link Phaser.Image Images}. * * Groups form the logical tree structure of the display/scene graph where local transformations are applied to children. * For instance, all children are also moved/rotated/scaled when the group is moved/rotated/scaled. * * In addition, Groups provides support for fast pooling and object recycling. * * Groups are also display objects and can be nested as children within other Groups. * * @param game A reference to the currently running game. * @param parent The parent Group (or other {@link DisplayObject}) that this group will be added to. * If undefined/unspecified the Group will be added to the {@link Phaser.Game#world Game World}; if null the Group will not be added to any parent. - Default: (game world) * @param name A name for this group. Not used internally but useful for debugging. - Default: 'group' * @param addToStage If true this group will be added directly to the Game.Stage instead of Game.World. * @param enableBody If true all Sprites created with {@link #create} or {@link #createMulitple} will have a physics body created on them. Change the body type with {@link #physicsBodyType}. * @param physicsBodyType The physics body type to use when physics bodies are automatically added. See {@link #physicsBodyType} for values. */ constructor(game: Phaser.Game, parent?: PIXI.DisplayObjectContainer, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number); /** * A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg. */ static RETURN_CHILD: number; /** * A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg. */ static RETURN_NONE: number; /** * A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg. */ static RETURN_TOTAL: number; /** * A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg. */ static RETURN_ALL: number; /** * A sort ordering value, as specified in {@link Phaser.Group#sort sort} eg. */ static SORT_ASCENDING: number; /** * A sort ordering value, as specified in {@link Phaser.Group#sort sort} eg. */ static SORT_DESCENDING: number; alpha: number; /** * The angle of rotation of the group container, in degrees. * * This adjusts the group itself by modifying its local rotation transform. * * This has no impact on the rotation/angle properties of the children, but it will update their worldTransform * and on-screen orientation and position. */ angle: number; /** * The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive. * Default: true */ alive: boolean; /** * The bottom coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ bottom: number; /** * If this object is {@link Phaser.Group#fixedToCamera fixedToCamera} then this stores the x/y position offset relative to the top-left of the camera view. * If the parent of this Group is also `fixedToCamera` then the offset here is in addition to that and should typically be disabled. */ cameraOffset: Phaser.Point; /** * The center x coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ centerX: number; /** * The center y coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ centerY: number; /** * The type of objects that will be created when using {@link Phaser.Group#create create} or {@link Phaser.Group#createMultiple createMultiple}. * * It should extend either Sprite or Image and accept the same constructor arguments: `(game, x, y, key, frame)`. * Default: {@link Phaser.Sprite} */ classType: any; /** * The current display object that the group cursor is pointing to, if any. (Can be set manually.) * * The cursor is a way to iterate through the children in a Group using {@link Phaser.Group#next next} and {@link Phaser.Group#previous previous}. */ cursor: any; /** * The current index of the Group cursor. Advance it with Group.next. */ cursorIndex: number; /** * If true all Sprites created by, or added to this group, will have a physics body enabled on them. * * If there are children already in the Group at the time you set this property, they are not changed. * * The default body type is controlled with {@link Phaser.Group#physicsBodyType physicsBodyType}. */ enableBody: boolean; /** * If true when a physics body is created (via {@link Phaser.Group#enableBody enableBody}) it will create a physics debug object as well. * * This only works for P2 bodies. */ enableBodyDebug: boolean; /** * If exists is false the group will be excluded from collision checks and filters such as {@link Phaser.Group#forEachExists forEachExists}. The group will not call `preUpdate` and `postUpdate` on its children and the children will not receive physics updates or camera/world boundary checks. The group will still be {@link Phaser.Group#visible visible} and will still call `update` on its children (unless {@link Phaser.Group#updateOnlyExistingChildren updateOnlyExistingChildren} is true). * Default: true */ exists: boolean; /** * A Group that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Group.cameraOffset. * * Note that the cameraOffset values are in addition to any parent in the display list. * So if this Group was in a Group that has x: 200, then this will be added to the cameraOffset.x */ fixedToCamera: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The hash array is an array belonging to this Group into which you can add any of its children via Group.addToHash and Group.removeFromHash. * * Only children of this Group can be added to and removed from the hash. * * This hash is used automatically by Phaser Arcade Physics in order to perform non z-index based destructive sorting. * However if you don't use Arcade Physics, or this isn't a physics enabled Group, then you can use the hash to perform your own * sorting and filtering of Group children without touching their z-index (and therefore display draw order) */ hash: PIXI.DisplayObject[]; /** * A group with `ignoreDestroy` set to `true` ignores all calls to its `destroy` method. */ ignoreDestroy: boolean; /** * A Group with `inputEnableChildren` set to `true` will automatically call `inputEnabled = true` * on any children _added_ to, or _created by_, this Group. * * If there are children already in the Group at the time you set this property, they are not changed. */ inputEnableChildren: boolean; /** * The left coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ left: number; /** * Total number of children in this group, regardless of exists/alive status. */ length: number; /** * A name for this group. Not used internally but useful for debugging. */ name: string; /** * This Signal is dispatched whenever a child of this Group emits an onInputDown signal as a result * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to * every child Sprite. * * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and * a reference to the Pointer that caused it. */ onChildInputDown: Phaser.Signal; /** * This Signal is dispatched whenever a child of this Group emits an onInputUp signal as a result * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to * every child Sprite. * * This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal, * a reference to the Pointer that caused it, and a boolean value `isOver` that tells you if the Pointer * is still over the Sprite or not. */ onChildInputUp: Phaser.Signal; /** * This Signal is dispatched whenever a child of this Group emits an onInputOver signal as a result * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to * every child Sprite. * * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and * a reference to the Pointer that caused it. */ onChildInputOver: Phaser.Signal; /** * This Signal is dispatched whenever a child of this Group emits an onInputOut signal as a result * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to * every child Sprite. * * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and * a reference to the Pointer that caused it. */ onChildInputOut: Phaser.Signal; /** * This signal is dispatched when the group is destroyed. */ onDestroy: Phaser.Signal; /** * A Group is that has `pendingDestroy` set to `true` is flagged to have its destroy method * called on the next logic update. * You can set it directly to flag the Group to be destroyed on its next update. * * This is extremely useful if you wish to destroy a Group from within one of its own callbacks * or a callback of one of its children. */ pendingDestroy: boolean; /** * If {@link Phaser.Group#enableBody enableBody} is true this is the type of physics body that is created on new Sprites. * * The valid values are {@link Phaser.Physics.ARCADE}, {@link Phaser.Physics.P2JS}, {@link Phaser.Physics.NINJA}, etc. */ physicsBodyType: number; /** * The const physics body type of this object. */ physicsType: number; /** * If this Group contains Arcade Physics Sprites you can set a custom sort direction via this property. * * It should be set to one of the Phaser.Physics.Arcade sort direction constants: * * Phaser.Physics.Arcade.SORT_NONE * Phaser.Physics.Arcade.LEFT_RIGHT * Phaser.Physics.Arcade.RIGHT_LEFT * Phaser.Physics.Arcade.TOP_BOTTOM * Phaser.Physics.Arcade.BOTTOM_TOP * * If set to `null` the Group will use whatever Phaser.Physics.Arcade.sortDirection is set to. This is the default behavior. */ physicsSortDirection: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The right coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ right: number; rotation: number; /** * The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject * at its default size. A value of 0.5 would scale this DisplayObject by half, and so on. * * The value of this property does not reflect any scaling happening further up the display list. * To obtain that value please see the `worldScale` property. */ scale: Phaser.Point; /** * The top coordinate of this Group. * * It is derived by calling `getBounds`, calculating the Groups dimensions based on its * visible children. */ top: number; /** * Total number of existing children in the group. */ total: number; /** * Internal Phaser Type value. */ type: number; /** * Skip children with `exists = false` in {@link Phaser.Group#update update}. */ updateOnlyExistingChildren: boolean; visible: boolean; /** * The z-depth value of this object within its parent container/Group - the World is a Group as well. * This value must be unique for each child in a Group. */ z: number; /** * Adds an existing object as the top child in this group. * * The child is automatically added to the top of the group, and is displayed above every previous child. * * Or if the _optional_ index is specified, the child is added at the location specified by the index value, * this allows you to control child ordering. * * If the child was already in this Group, it is simply returned, and nothing else happens to it. * * If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist. * * Use {@link Phaser.Group#create create} to create and add a new child. * * @param child The display object to add as a child. * @param silent If true the child will not dispatch the `onAddedToGroup` event. * @param index The index within the group to insert the child to. Where 0 is the bottom of the Group. * @return The child that was added to the group. */ add(child: any, silent?: boolean, index?: number): any; /** * Adds the amount to the given property on all children in this group. * * `Group.addAll('x', 10)` will add 10 to the child.x value for each child. * * @param property The property to increment, for example 'body.velocity.x' or 'angle'. * @param amount The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50. * @param checkAlive If true the property will only be changed if the child is alive. * @param checkVisible If true the property will only be changed if the child is visible. */ addAll(property: string, amount: number, checkAlive?: boolean, checkVisible?: boolean): void; /** * Adds an existing object to this group. * * The child is added to the group at the location specified by the index value, this allows you to control child ordering. * * If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist. * * @param child The display object to add as a child. * @param index The index within the group to insert the child to. * @param silent If true the child will not dispatch the `onAddedToGroup` event. * @return The child that was added to the group. */ addAt(child: any, index: number, silent?: boolean): any; /** * Adds an array of existing Display Objects to this Group. * * The Display Objects are automatically added to the top of this Group, and will render on-top of everything already in this Group. * * As well as an array you can also pass another Group as the first argument. In this case all of the children from that * Group will be removed from it and added into this Group. * * If `Group.enableBody` is set, then a physics body will be created on the objects, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the objects, so long as one does not already exist. * * @param children An array of display objects or a Phaser.Group. If a Group is given then *all* children will be moved from it. * @param silent If true the children will not dispatch the `onAddedToGroup` event. * @return The array of children or Group of children that were added to this Group. */ addMultiple(children: any[], silent?: boolean): any[]; /** * Adds a child of this Group into the hash array. * This call will return false if the child is not a child of this Group, or is already in the hash. * * @param child The display object to add to this Groups hash. Must be a member of this Group already and not present in the hash. * @return True if the child was successfully added to the hash, otherwise false. */ addToHash(child: PIXI.DisplayObject): boolean; /** * This method iterates through all children in the Group (regardless if they are visible or exist) * and then changes their position so they are arranged in a Grid formation. Children must have * the `alignTo` method in order to be positioned by this call. All default Phaser Game Objects have * this. * * The grid dimensions are determined by the first four arguments. The `width` and `height` arguments * relate to the width and height of the grid respectively. * * For example if the Group had 100 children in it: * * `Group.align(10, 10, 32, 32)` * * This will align all of the children into a grid formation of 10x10, using 32 pixels per * grid cell. If you want a wider grid, you could do: * * `Group.align(25, 4, 32, 32)` * * This will align the children into a grid of 25x4, again using 32 pixels per grid cell. * * You can choose to set _either_ the `width` or `height` value to -1. Doing so tells the method * to keep on aligning children until there are no children left. For example if this Group had * 48 children in it, the following: * * `Group.align(-1, 8, 32, 32)` * * ... will align the children so that there are 8 children vertically (the second argument), * and each row will contain 6 sprites, except the last one, which will contain 5 (totaling 48) * * You can also do: * * `Group.align(10, -1, 32, 32)` * * In this case it will create a grid 10 wide, and as tall as it needs to be in order to fit * all of the children in. * * The `position` property allows you to control where in each grid cell the child is positioned. * This is a constant and can be one of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, * `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, * `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * * The final argument; `offset` lets you start the alignment from a specific child index. * * @param width The width of the grid in items (not pixels). Set to -1 for a dynamic width. If -1 then you must set an explicit height value. * @param height The height of the grid in items (not pixels). Set to -1 for a dynamic height. If -1 then you must set an explicit width value. * @param cellWidth The width of each grid cell, in pixels. * @param cellHeight The height of each grid cell, in pixels. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offset Optional index to start the alignment from. Defaults to zero, the first child in the Group, but can be set to any valid child index value. * @return True if the Group children were aligned, otherwise false. */ align(width: number, height: number, cellWidth: number, cellHeight: number, position?: number, offset?: number): boolean; alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): Phaser.Group; alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): Phaser.Group; /** * Brings the given child to the top of this group so it renders above all other children. * * @param child The child to bring to the top of this group. * @return The child that was moved. */ bringToTop(child: any): any; /** * Calls a function, specified by name, on all on children. * * The function is called for all children regardless if they are dead or alive (see callAllExists for different options). * After the method parameter and context you can add as many extra parameters as you like, which will all be passed to the child. * * @param method Name of the function on the child to call. Deep property lookup is supported. * @param context A string containing the context under which the method will be executed. Set to null to default to the child. * @param args Additional parameters that will be passed to the method. */ callAll(method: string, context: any, ...parameters: any[]): void; /** * Calls a function, specified by name, on all children in the group who exist (or do not exist). * * After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback. * * @param callback Name of the function on the children to call. * @param existsValue Only children with exists=existsValue will be called. * @param parameter Additional parameters that will be passed to the callback. */ callAllExists(callback: string, existsValue: boolean, ...parameters: any[]): void; /** * Returns a reference to a function that exists on a child of the group based on the given callback array. * * @param child The object to inspect. * @param callback The array of function names. * @param length The size of the array (pre-calculated in callAll). */ callbackFromArray(child: any, callback: Function, length: number): void; /** * Test that the same property across all children of this group is equal to the given value. * * This call doesn't descend down children, so if you have a Group inside of this group, the property will be checked on the group but not its children. * * @param key The property, as a string, to be checked. For example: 'body.velocity.x' * @param value The value that will be checked. * @param checkAlive If set then only children with alive=true will be checked. This includes any Groups that are children. * @param checkVisible If set then only children with visible=true will be checked. This includes any Groups that are children. * @param force Also return false if the property is missing or undefined (regardless of the `value` argument). * @return - True if all eligible children have the given property value (but see `force`); otherwise false. */ checkAll(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean, force?: boolean): boolean; /** * Test that at least one child of this group has the given property value. * * This call doesn't descend down children, so if you have a Group inside of this group, the property will be checked on the group but not its children. * * @param key The property, as a string, to be checked. For example: 'body.velocity.x' * @param value The value that will be checked. * @param checkAlive If set then only children with alive=true will be checked. This includes any Groups that are children. * @param checkVisible If set then only children with visible=true will be checked. This includes any Groups that are children. * @return - True if at least one eligible child has the given property value; otherwise false. */ checkAny(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean): boolean; /** * Checks a property for the given value on the child. * * @param child The child to check the property value on. * @param key The property, as a string, to be checked. For example: 'body.velocity.x' * @param value The value that will be checked. * @param force Also return false if the property is missing or undefined (regardless of the `value` argument). * @return True if `child` is a child of this Group and the property was equal to value, false if not. */ checkProperty(child: any, key: string, value: any, force?: boolean): boolean; /** * Get the number of children with the given property name and value. * * @param key The child property to check. * @param value A child matches if `child[key] === value` is true. * @return The number of children matching the query. */ count(key: string, value: any): number; /** * Get the number of dead children in this group. * @return The number of children flagged as dead. */ countDead(): number; /** * Get the number of living children in this group. * @return The number of children flagged as alive. */ countLiving(): number; /** * Creates a new Phaser.Sprite object and adds it to the top of this group. * * Use {@link Phaser.Group#classType classType} to change the type of object created. * * The child is automatically added to the top of the group, and is displayed above every previous child. * * Or if the _optional_ index is specified, the child is added at the location specified by the index value, * this allows you to control child ordering. * * If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist. * * @param x The x coordinate to display the newly created Sprite at. The value is in relation to the group.x point. * @param y The y coordinate to display the newly created Sprite at. The value is in relation to the group.y point. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param exists The default exists state of the Sprite. - Default: true * @param index The index within the group to insert the child to. Where 0 is the bottom of the Group. * @return The child that was created: will be a {@link Phaser.Sprite} unless {@link #classType} has been changed. */ create(x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, exists?: boolean, index?: number): any; /** * Creates multiple Phaser.Sprite objects and adds them to the top of this Group. * * This method is useful if you need to quickly generate a pool of sprites, such as bullets. * * Use {@link Phaser.Group#classType classType} to change the type of object created. * * You can provide an array as the `key` and / or `frame` arguments. When you do this * it will create `quantity` Sprites for every key (and frame) in the arrays. * * For example: * * `createMultiple(25, ['ball', 'carrot'])` * * In the above code there are 2 keys (ball and carrot) which means that 50 sprites will be * created in total, 25 of each. You can also have the `frame` as an array: * * `createMultiple(5, 'bricks', [0, 1, 2, 3])` * * In the above there is one key (bricks), which is a sprite sheet. The frames array tells * this method to use frames 0, 1, 2 and 3. So in total it will create 20 sprites, because * the quantity was set to 5, so that is 5 brick sprites of frame 0, 5 brick sprites with * frame 1, and so on. * * If you set both the key and frame arguments to be arrays then understand it will create * a total quantity of sprites equal to the size of both arrays times each other. I.e.: * * `createMultiple(20, ['diamonds', 'balls'], [0, 1, 2])` * * The above will create 20 'diamonds' of frame 0, 20 with frame 1 and 20 with frame 2. * It will then create 20 'balls' of frame 0, 20 with frame 1 and 20 with frame 2. * In total it will have created 120 sprites. * * By default the Sprites will have their `exists` property set to `false`, and they will be * positioned at 0x0, relative to the `Group.x / y` values. * * If `Group.enableBody` is set, then a physics body will be created on the objects, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the objects, so long as one does not already exist. * * @param quantity The number of Sprites to create. * @param key The Cache key of the image that the Sprites will use. Or an Array of keys. See the description for details on how the quantity applies when arrays are used. * @param frame If the Sprite image contains multiple frames you can specify which one to use here. Or an Array of frames. See the description for details on how the quantity applies when arrays are used. * @param exists The default exists state of the Sprite. * @param callback The function that will be called for each applicable child. It will be passed the new child and the loop index (0 through quantity - 1). * @param callbackContext The context in which the function should be called (usually 'this'). The default context is the new child. * @return An array containing all of the Sprites that were created. */ createMultiple(quantity: number, key: string | string[], frame?: any | any[], exists?: boolean, callback?: Function, callbackContext?: any): any[]; /** * Sort the children in the group according to custom sort function. * * The `sortHandler` is provided the two parameters: the two children involved in the comparison (a and b). * It should return -1 if `a > b`, 1 if `a < b` or 0 if `a === b`. * * @param sortHandler The custom sort function. * @param context The context in which the sortHandler is called. */ customSort(sortHandler: Function, context?: any): void; /** * Destroys this group. * * Removes all children, then removes this group from its parent and nulls references. * * @param destroyChildren If true `destroy` will be invoked on each removed child. - Default: true * @param soft A 'soft destroy' (set to true) doesn't remove this group from its parent or null the game reference. Set to false and it does. */ destroy(destroyChildren?: boolean, soft?: boolean): void; /** * Divides the given property by the amount on all children in this group. * * `Group.divideAll('x', 2)` will half the child.x value for each child. * * @param property The property to divide, for example 'body.velocity.x' or 'angle'. * @param amount The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50. * @param checkAlive If true the property will only be changed if the child is alive. * @param checkVisible If true the property will only be changed if the child is visible. */ divideAll(property: string, amount: number, checkAlive?: boolean, checkVisible?: boolean): void; /** * Call a function on each child in this group. * * Additional arguments for the callback can be specified after the `checkExists` parameter. For example, * * Group.forEach(awardBonusGold, this, true, 100, 500) * * would invoke `awardBonusGold` function with the parameters `(child, 100, 500)`. * * Note: This check will skip any children which are Groups themselves. * * @param callback The function that will be called for each applicable child. The child will be passed as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param checkExists If set only children matching for which `exists` is true will be passed to the callback, otherwise all children will be passed. * @param args Additional arguments to pass to the callback function, after the child item. - Default: (none) */ forEach(callback: Function, callbackContext?: any, checkExists?: boolean, ...args: any[]): void; /** * Call a function on each alive child in this group. * * See {@link Phaser.Group#forEach forEach} for details. * * @param callback The function that will be called for each applicable child. The child will be passed as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param args Additional arguments to pass to the callback function, after the child item. - Default: (none) */ forEachAlive(callback: Function, callbackContext?: any, ...args: any[]): void; /** * Call a function on each dead child in this group. * * See {@link Phaser.Group#forEach forEach} for details. * * @param callback The function that will be called for each applicable child. The child will be passed as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param args Additional arguments to pass to the callback function, after the child item. - Default: (none) */ forEachDead(callback: Function, callbackContext?: any, ...args: any[]): void; /** * Call a function on each existing child in this group. * * See {@link Phaser.Group#forEach forEach} for details. * * @param callback The function that will be called for each applicable child. The child will be passed as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param args Additional arguments to pass to the callback function, after the child item. - Default: (none) */ forEachExists(callback: Function, callbackContext?: any): void; /** * Find children matching a certain predicate. * * For example: * * var healthyList = Group.filter(function(child, index, children) { * return child.health > 10 ? true : false; * }, true); * healthyList.callAll('attack'); * * Note: Currently this will skip any children which are Groups themselves. * * @param predicate The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, the index as the second, and the entire child array as the third * @param checkExists If true, only existing can be selected; otherwise all children can be selected and will be passed to the predicate. * @return Returns an array list containing all the children that the predicate returned true for */ filter(predicate: Function, checkExists?: boolean): ArraySet; /** * Returns all children in this Group. * * You can optionally specify a matching criteria using the `property` and `value` arguments. * * For example: `getAll('exists', true)` would return only children that have an `exists` property equal to `true`. * * Optionally you can specify a start and end index. For example if this Group had 100 children, * and you set `startIndex` to 0 and `endIndex` to 50, it would return the first 50 children in the Group. * If `property` and `value` are also specified, only children within the given index range are searched. * * @param property An optional property to test against the value argument. * @param value If property is set then Child.property must strictly equal this value to be included in the results. * @param startIndex The first child index to start the search from. * @param endIndex The last child index to search up until. * @return - An array containing all, some, or none of the Children of this Group. */ getAll(property?: string, value?: any, startIndex?: number, endIndex?: number): any[]; /** * Returns the child found at the given index within this group. * * @param index The index to return the child from. * @return The child that was found at the given index, or -1 for an invalid index. */ getAt(index: number): PIXI.DisplayObject | number; /** * Returns the child at the bottom of this group. * * The bottom child the child being displayed (rendered) below every other child. * @return The child at the bottom of the Group. */ getBottom(): any; /** * Searches the Group for the first instance of a child with the `name` * property matching the given argument. Should more than one child have * the same name only the first instance is returned. * * @param name The name to search for. * @return The first child with a matching name, or null if none were found. */ getByName(name: string): any; /** * Get the closest child to given Object, with optional callback to filter children. * * This can be a Sprite, Group, Image or any object with public x and y properties. * * 'close' is determined by the distance from the objects `x` and `y` properties compared to the childs `x` and `y` properties. * * You can use the optional `callback` argument to apply your own filter to the distance checks. * If the child is closer then the previous child, it will be sent to `callback` as the first argument, * with the distance as the second. The callback should return `true` if it passes your * filtering criteria, otherwise it should return `false`. * * @param object The object used to determine the distance. This can be a Sprite, Group, Image or any object with public x and y properties. * @param callback The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, with the distance as the second. It should return `true` if the child passes the matching criteria. * @param callbackContext The context in which the function should be called (usually 'this'). * @return The child closest to given object, or `null` if no child was found. */ getClosestTo(object: any, callback?: Function, callbackContext?: any): any; /** * Get the first display object with the given property name and value. * * @param key The child property to check. * @param value A child matches if `child[key] === value` is true. * @return The first child matching the query, or `null` if none were found. */ getFirst(key: string, value: any): any; /** * Get the first child that is alive (`child.alive === true`). * * This is handy for choosing a squad leader, etc. * * You can use the optional argument `createIfNull` to create a new Game Object if no alive ones were found in this Group. * * It works by calling `Group.create` passing it the parameters given to this method, and returning the new child. * * If a child *was* found , `createIfNull` is `false` and you provided the additional arguments then the child * will be reset and/or have a new texture loaded on it. This is handled by `Group.resetChild`. * * @param createIfNull If `true` and no alive children are found a new one is created. * @param x The x coordinate to reset the child to. The value is in relation to the group.x point. * @param y The y coordinate to reset the child to. The value is in relation to the group.y point. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The alive dead child, or `null` if none found and `createIfNull` was false. */ getFirstAlive(createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any; /** * Get the first child that is dead (`child.alive === false`). * * This is handy for checking if everything has been wiped out and adding to the pool as needed. * * You can use the optional argument `createIfNull` to create a new Game Object if no dead ones were found in this Group. * * It works by calling `Group.create` passing it the parameters given to this method, and returning the new child. * * If a child *was* found , `createIfNull` is `false` and you provided the additional arguments then the child * will be reset and/or have a new texture loaded on it. This is handled by `Group.resetChild`. * * @param createIfNull If `true` and no dead children are found a new one is created. * @param x The x coordinate to reset the child to. The value is in relation to the group.x point. * @param y The y coordinate to reset the child to. The value is in relation to the group.y point. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The first dead child, or `null` if none found and `createIfNull` was false. */ getFirstDead(createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any; /** * Get the first display object that exists, or doesn't exist. * * You can use the optional argument `createIfNull` to create a new Game Object if none matching your exists argument were found in this Group. * * It works by calling `Group.create` passing it the parameters given to this method, and returning the new child. * * If a child *was* found , `createIfNull` is `false` and you provided the additional arguments then the child * will be reset and/or have a new texture loaded on it. This is handled by `Group.resetChild`. * * @param exists If true, find the first existing child; otherwise find the first non-existing child. - Default: true * @param createIfNull If `true` and no alive children are found a new one is created. * @param x The x coordinate to reset the child to. The value is in relation to the group.x point. * @param y The y coordinate to reset the child to. The value is in relation to the group.y point. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The first child, or `null` if none found and `createIfNull` was false. */ getFirstExists(exists: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any; /** * Get the child furthest away from the given Object, with optional callback to filter children. * * This can be a Sprite, Group, Image or any object with public x and y properties. * * 'furthest away' is determined by the distance from the objects `x` and `y` properties compared to the childs `x` and `y` properties. * * You can use the optional `callback` argument to apply your own filter to the distance checks. * If the child is closer then the previous child, it will be sent to `callback` as the first argument, * with the distance as the second. The callback should return `true` if it passes your * filtering criteria, otherwise it should return `false`. * * @param object The object used to determine the distance. This can be a Sprite, Group, Image or any object with public x and y properties. * @param callback The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, with the distance as the second. It should return `true` if the child passes the matching criteria. * @param callbackContext The context in which the function should be called (usually 'this'). * @return The child furthest from the given object, or `null` if no child was found. */ getFurthestFrom(object: any, callback?: Function, callbackContext?: any): any; /** * Get the index position of the given child in this group, which should match the child's `z` property. * * @param child The child to get the index for. * @return The index of the child or -1 if it's not a member of this group. */ getIndex(child: any): number; /** * Returns a random child from the group. * * @param startIndex Offset from the front of the group (lowest child). * @param length Restriction on the number of values you want to randomly select from. - Default: (to top) * @return A random child of this Group. */ getRandom(startIndex?: number, length?: number): any; /** * Return the child at the top of this group. * * The top child is the child displayed (rendered) above every other child. * @return The child at the top of the Group. */ getTop(): any; /** * Checks if the child has the given property. * * Will scan up to 4 levels deep only. * * @param child The child to check for the existence of the property on. * @param key An array of strings that make up the property. * @return True if the child has the property, otherwise false. */ hasProperty(child: any, key: string[]): boolean; /** * Iterates over the children of the group performing one of several actions for matched children. * * A child is considered a match when it has a property, named `key`, whose value is equal to `value` * according to a strict equality comparison. * * The result depends on the `returnType`: * * - {@link Phaser.Group.RETURN_TOTAL RETURN_TOTAL}: * The callback, if any, is applied to all matching children. The number of matched children is returned. * - {@link Phaser.Group.RETURN_NONE RETURN_NONE}: * The callback, if any, is applied to all matching children. No value is returned. * - {@link Phaser.Group.RETURN_CHILD RETURN_CHILD}: * The callback, if any, is applied to the *first* matching child and the *first* matched child is returned. * If there is no matching child then null is returned. * * If `args` is specified it must be an array. The matched child will be assigned to the first * element and the entire array will be applied to the callback function. * * @param key The child property to check, i.e. 'exists', 'alive', 'health' * @param value A child matches if `child[key] === value` is true. * @param returnType How to iterate the children and what to return. * @param callback Optional function that will be called on each matching child. The matched child is supplied as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param args The arguments supplied to to the callback; the first array index (argument) will be replaced with the matched child. - Default: (none) * @return Returns either an integer (for RETURN_TOTAL), the first matched child (for RETURN_CHILD), or null. */ iterate(key: string, value: any, returnType: number, callback?: Function, callbackContext?: any, ...args: any[]): any; /** * Sets {@link Phaser.Group#alive alive}, {@link Phaser.Group#exists exists}, and {@link Phaser.Group#visible visible} to false. */ kill(): void; /** * Kills all children having exists=true. */ killAll(): void; /** * Moves all children from this Group to the Group given. * * @param group The new Group to which the children will be moved to. * @param silent If true the children will not dispatch the `onAddedToGroup` event for the new Group. * @return The Group to which all the children were moved. */ moveAll(group: Phaser.Group, silent?: boolean): Phaser.Group; /** * Moves the given child down one place in this group unless it's already at the bottom. * * @param child The child to move down in the group. * @return The child that was moved. */ moveDown(child: any): any; /** * Moves the given child up one place in this group unless it's already at the top. * * @param child The child to move up in the group. * @return The child that was moved. */ moveUp(child: any): any; /** * Multiplies the given property by the amount on all children in this group. * * `Group.multiplyAll('x', 2)` will x2 the child.x value for each child. * * @param property The property to multiply, for example 'body.velocity.x' or 'angle'. * @param amount The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20. * @param checkAlive If true the property will only be changed if the child is alive. * @param checkVisible If true the property will only be changed if the child is visible. */ multiplyAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void; /** * Advances the group cursor to the next (higher) object in the group. * * If the cursor is at the end of the group (top child) it is moved the start of the group (bottom child). * @return The child the cursor now points to. */ next(): any; /** * The core postUpdate - as called by World. */ postUpdate(): void; /** * The core preUpdate - as called by World. */ preUpdate(): void; /** * Moves the group cursor to the previous (lower) child in the group. * * If the cursor is at the start of the group (bottom child) it is moved to the end (top child). * @return The child the cursor now points to. */ previous(): any; /** * Removes the given child from this group. * * This will dispatch an `onRemovedFromGroup` event from the child (if it has one), and optionally destroy the child. * * If the group cursor was referring to the removed child it is updated to refer to the next child. * * @param child The child to remove. * @param destroy If true `destroy` will be invoked on the removed child. * @param silent If true the the child will not dispatch the `onRemovedFromGroup` event. * @return true if the child was removed from this group, otherwise false. */ remove(child: any, destroy?: boolean, silent?: boolean): boolean; /** * Removes all children from this Group, but does not remove the group from its parent. * * The children can be optionally destroyed as they are removed. * * You can also optionally also destroy the BaseTexture the Child is using. Be careful if you've * more than one Game Object sharing the same BaseTexture. * * @param destroy If true `destroy` will be invoked on each removed child. * @param silent If true the children will not dispatch their `onRemovedFromGroup` events. * @param destroyTexture If true, and if the `destroy` argument is also true, the BaseTexture belonging to the Child is also destroyed. Note that if another Game Object is sharing the same BaseTexture it will invalidate it. */ removeAll(destroy?: boolean, silent?: boolean, destroyTexture?: boolean): void; /** * Removes all children from this group whose index falls beteen the given startIndex and endIndex values. * * @param startIndex The index to start removing children from. * @param endIndex The index to stop removing children at. Must be higher than startIndex. If undefined this method will remove all children between startIndex and the end of the group. * @param destroy If true `destroy` will be invoked on each removed child. * @param silent If true the children will not dispatch their `onRemovedFromGroup` events. */ removeBetween(startIndex: number, endIndex?: number, destroy?: boolean, silent?: boolean): void; /** * Removes a child of this Group from the hash array. * This call will return false if the child is not in the hash. * * @param child The display object to remove from this Groups hash. Must be a member of this Group and in the hash. * @return True if the child was successfully removed from the hash, otherwise false. */ removeFromHash(child: PIXI.DisplayObject): boolean; /** * Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group. * * If `Group.enableBody` is set, then a physics body will be created on the object, so long as one does not already exist. * * If `Group.inputEnableChildren` is set, then an Input Handler will be created on the object, so long as one does not already exist. * * @param oldChild The child in this group that will be replaced. * @param newChild The child to be inserted into this group. * @return Returns the oldChild that was replaced within this group. */ replace(oldChild: any, newChild: any): any; /** * Calls {@link Phaser.Group#resetChild resetChild} on each child (or each existing child). * * @param x The x coordinate to reset each child to. The value is in relation to the group.x point. * @param y The y coordinate to reset each child to. The value is in relation to the group.y point. * @param key The image or texture used by the Sprite during rendering. * @param frame The frame of a sprite sheet or texture atlas. * @param checkExists Reset only existing children. */ resetAll(x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, checkExists?: boolean): void; /** * Takes a child and if the `x` and `y` arguments are given it calls `child.reset(x, y)` on it. * * If the `key` and optionally the `frame` arguments are given, it calls `child.loadTexture(key, frame)` on it. * * The two operations are separate. For example if you just wish to load a new texture then pass `null` as the x and y values. * * @param child The child to reset and/or load the texture on. * @param x The x coordinate to reset the child to. The value is in relation to the group.x point. * @param y The y coordinate to reset the child to. The value is in relation to the group.y point. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return The child that was reset: usually a {@link Phaser.Sprite}. */ resetChild(child: any, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any; /** * Sets the group cursor to the first child in the group. * * If the optional index parameter is given it sets the cursor to the object at that index instead. * * @param index Set the cursor to point to a specific index. * @return The child the cursor now points to. */ resetCursor(index?: number): any; /** * Reverses all children in this group. * * This operation applies only to immediate children and does not propagate to subgroups. */ reverse(): void; /** * Sets {@link Phaser.Group#alive alive}, {@link Phaser.Group#exists exists}, and {@link Phaser.Group#visible visible} to true. */ revive(): void; /** * Revives all children having exists=false. */ reviveAll(): void; /** * Places each child at a random position within the given Rectangle (or the {@link Phaser.World#bounds World bounds}). * * @param rect A Rectangle. If omitted {@link Phaser.World#bounds} is used. - Default: this.game.world.bounds * @param checkExists Place only children with exists=true. */ scatter(rect?: Phaser.Rectangle, checkExists?: boolean): void; /** * Sends the given child to the bottom of this group so it renders below all other children. * * @param child The child to send to the bottom of this group. * @return The child that was moved. */ sendToBack(child: any): any; /** * Quickly set a property on a single child of this group to a new value. * * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. * * @param child The child to set the property on. * @param key The property, as a string, to be set. For example: 'body.velocity.x' * @param value The value that will be set. * @param checkAlive If set then the child will only be updated if alive=true. * @param checkVisible If set then the child will only be updated if visible=true. * @param operation Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. * @param force If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set. * @return True if the property was set, false if not. */ set(child: any, key: string[], value: any, operation?: number, force?: boolean): boolean; /** * Quickly set the same property across all children of this group to a new value. * * This call doesn't descend down children, so if you have a Group inside of this group, the property will be set on the group but not its children. * If you need that ability please see `Group.setAllChildren`. * * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. * * @param key The property, as a string, to be set. For example: 'body.velocity.x' * @param value The value that will be set. * @param checkAlive If set then only children with alive=true will be updated. This includes any Groups that are children. * @param checkVisible If set then only children with visible=true will be updated. This includes any Groups that are children. * @param operation Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. * @param force If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set. */ setAll(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean, operation?: number, force?: boolean): void; /** * Quickly set the same property across all children of this group, and any child Groups, to a new value. * * If this group contains other Groups then the same property is set across their children as well, iterating down until it reaches the bottom. * Unlike with `setAll` the property is NOT set on child Groups itself. * * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. * * @param key The property, as a string, to be set. For example: 'body.velocity.x' * @param value The value that will be set. * @param checkAlive If set then only children with alive=true will be updated. This includes any Groups that are children. * @param checkVisible If set then only children with visible=true will be updated. This includes any Groups that are children. * @param operation Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. * @param force If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set. */ setAllChildren(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean, operation?: number, force?: boolean): void; /** * Sets a property to the given value on the child. The operation parameter controls how the value is set. * * The operations are: * - 0: set the existing value to the given value; if force is `true` a new property will be created if needed * - 1: will add the given value to the value already present. * - 2: will subtract the given value from the value already present. * - 3: will multiply the value already present by the given value. * - 4: will divide the value already present by the given value. * * @param child The child to set the property value on. * @param key An array of strings that make up the property that will be set. * @param value The value that will be set. * @param operation Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. * @param force If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set. * @return True if the property was set, false if not. */ setProperty(child: any, key: string[], value: any, operation?: number, force?: boolean): boolean; /** * Orders this Group's children randomly. * * This can be more efficient than calling {@link Phaser.Group#getRandom getRandom} repeatedly. */ shuffle(): void; /** * Sort the children in the group according to a particular key and ordering. * * Call this function to sort the group according to a particular key value and order. * * For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`. * * Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including * alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details. * * @param key The name of the property to sort on. Defaults to the objects z-depth value. - Default: 'z' * @param order Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}). - Default: Phaser.Group.SORT_ASCENDING */ sort(key?: string, order?: number): void; /** * Subtracts the amount from the given property on all children in this group. * * `Group.subAll('x', 10)` will minus 10 from the child.x value for each child. * * @param property The property to decrement, for example 'body.velocity.x' or 'angle'. * @param amount The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10. * @param checkAlive If true the property will only be changed if the child is alive. * @param checkVisible If true the property will only be changed if the child is visible. */ subAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void; /** * Swaps the position of two children in this group. * * Both children must be in this group, a child cannot be swapped with itself, and unparented children cannot be swapped. * * @param child1 The first child to swap. * @param child2 The second child to swap. */ swap(child1: any, child2: any): boolean; /** * The core update - as called by World. * * Children with `exists = false` are updated unless {@link Phaser.Group#updateOnlyExistingChildren updateOnlyExistingChildren} is true. */ update(): void; /** * Internal method that re-applies all of the children's Z values. * * This must be called whenever children ordering is altered so that their `z` indices are correctly updated. */ updateZ(): void; /** * Positions the child found at the given index within this group to the given x and y coordinates. * * @param index The index of the child in the group to set the position of. * @param x The new x position of the child. * @param y The new y position of the child. */ xy(index: number, x: number, y: number): void; } /** * An Image is a light-weight object you can use to display anything that doesn't need health, physics, or complex position monitoring. * * It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics. */ class Image extends PIXI.Sprite { /** * An Image is a light-weight object you can use to display anything that doesn't need health, physics, or complex position monitoring. * * It can still rotate, scale, crop and receive input events. This makes it perfect for logos, backgrounds, simple buttons and other non-Sprite graphics. * * @param game A reference to the currently running game. * @param x The x coordinate of the Image. The coordinate is relative to any parent container this Image may be in. * @param y The y coordinate of the Image. The coordinate is relative to any parent container this Image may be in. * @param key The texture used by the Image during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture. If this argument is omitted, the image will receive {@link Phaser.Cache.DEFAULT the default texture} (as if you had passed '__default'), but its `key` will remain empty. * @param frame If this Image is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ constructor(game: Phaser.Game, x: number, y: number, key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number); /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * The anchor sets the origin point of the texture. * The default (0, 0) is the top left. * (0.5, 0.5) is the center. * (1, 1) is the bottom right. * * You can modify the default values in PIXI.Sprite.defaultAnchor. */ anchor: Phaser.Point; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * The local center x coordinate of the Game Object. * This is the same as `(x - offsetX) + (width / 2)`. */ centerX: number; /** * The local center y coordinate of the Game Object. * This is the same as `(y - offsetY) + (height / 2)`. */ centerY: number; /** * The components this Game Object has installed. */ components: any; /** * The Rectangle used to crop the texture this Game Object uses. * Set this property via `crop`. * If you modify this property directly you must call `updateCrop` in order to have the change take effect. */ cropRect: Phaser.Rectangle; /** * Does this texture require a custom render call? (as set by BitmapData, Video, etc) */ customRender: boolean; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; deltaX: number; deltaY: number; deltaZ: number; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}). * Default: true */ exists: boolean; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * Gets or sets the current frame index of the texture being used to render this Game Object. * * To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use, * for example: `player.frame = 4`. * * If the frame index given doesn't exist it will revert to the first frame found in the texture. * * If you are using a texture atlas then you should use the `frameName` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frame: string | number; /** * Gets or sets the current frame name of the texture being used to render this Game Object. * * To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use, * for example: `player.frameName = "idle"`. * * If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning. * * If you are using a sprite sheet then you should use the `frame` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frameName: string; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; inWorld: boolean; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture; /** * The lifespan allows you to give a Game Object a lifespan in milliseconds. * * Once the Game Object is 'born' you can set this to a positive value. * * It is automatically decremented by `game.time.delta` each frame. * When it reaches zero it will call the `kill` method. * * Very handy for particles, bullets, collectibles, or any other short-lived entity. */ lifespan: number; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject * at its default size. A value of 0.5 would scale this DisplayObject by half, and so on. * * The value of this property does not reflect any scaling happening further up the display list. * To obtain that value please see the `worldScale` property. */ scale: Phaser.Point; /** * The maximum scale this Game Object will scale up to. * * It allows you to prevent a parent from scaling this Game Object higher than the given value. * * Set it to `null` to remove the limit. */ scaleMax: Phaser.Point; /** * The minimum scale this Game Object will scale down to. * * It allows you to prevent a parent from scaling this Game Object lower than the given value. * * Set it to `null` to remove the limit. */ scaleMin: Phaser.Point; /** * Enable or disable texture smoothing for this Game Object. * * It only takes effect if the Game Object is using an image based texture. * * Smoothing is enabled by default. */ smoothed: boolean; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The const type of this object. */ type: number; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Brings this Game Object to the top of its parent's display list (the last position). * Visually this means it will render over the top of all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will bring it to the top of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ bringToTop(): Phaser.Image; /** * Crop allows you to crop the texture being used to display this Game Object. * Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly. * * Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method, * or by modifying `cropRect` property directly and then calling `updateCrop`. * * The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object * so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties. * * A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`, * in which case the values are duplicated to a local object. * * @param rect The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle. * @param copy If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect. */ crop(rect: Phaser.Rectangle, copy?: boolean): void; /** * Destroy this DisplayObject. * * Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask. * * Also iteratively calls `destroy` on any children. */ destroy(destroyChildren?: boolean): void; /** * Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false. * * It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal. * * Note that killing a Game Object is a way for you to quickly recycle it in an object pool, * it doesn't destroy the object or free it up from memory. * * If you don't need this Game Object any more you should call `destroy` instead. * @return This instance. */ kill(): Phaser.Image; /** * Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache. * * If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead. * * You should only use `loadTexture` if you want to replace the base texture entirely. * * Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU. * * You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. * Doing this then sets the key to be the `frame` argument (the frame is set to zero). * * This allows you to create sprites using `load.image` during development, and then change them * to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' * and swapping it to be the key of the atlas data. * * Note: You cannot use a RenderTexture as a texture for a TileSprite. * * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true */ loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void; /** * Resizes the Frame dimensions that the Game Object uses for rendering. * * You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData * it can be useful to adjust the dimensions directly in this way. * * @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object. * @param width The new width of the texture. * @param height The new height of the texture. */ resizeFrame(parent: any, width: number, height: number): void; /** * Moves this Game Object down one place in its parents display list. * This call has no effect if the Game Object is already at the bottom of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveDown(): Phaser.Image; /** * Moves this Game Object up one place in its parent's display list. * This call has no effect if the Game Object is already at the top of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object up within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveUp(): Phaser.Image; /** * Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object, * which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result. * * This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result. * * Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency. * It should be fine for low-volume testing where physics isn't required. * * @param displayObject The display object to check against. * @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object. */ overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean; /** * Plays an Animation. * * The animation should have previously been created via `animations.add`. * * If the animation is already playing calling this again won't do anything. * If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`. * * @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'. * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return A reference to playing Animation. */ play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Internal method called by the World postUpdate cycle. */ postUpdate(): void; /** * Automatically called by World.preUpdate. */ preUpdate(): void; /** * Resets the Game Object. * * This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`, * `visible` and `renderable` to true. * * If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value. * * If this Game Object has a Physics Body it will reset the Body. * * @param x The x coordinate (in world space) to position the Game Object at. * @param y The y coordinate (in world space) to position the Game Object at. * @param health The health to give the Game Object if it has the Health component. - Default: 1 * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.Image; /** * Resets the texture frame dimensions that the Game Object uses for rendering. */ resetFrame(): void; /** * Brings a 'dead' Game Object back to life, optionally resetting its health value in the process. * * A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true. * * It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal. * * @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100 * @return This instance. */ revive(health?: number): Phaser.Image; /** * Sends this Game Object to the bottom of its parent's display list (the first position). * Visually this means it will render below all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will send it to the bottom of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ sendToBack(): Phaser.Image; /** * Sets the texture frame the Game Object uses for rendering. * * This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes. * * @param frame The Frame to be used by the texture. */ setFrame(frame: Phaser.Frame): void; /** * Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent. * * For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored * and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to. * * By setting these values you can carefully control how Game Objects deal with responsive scaling. * * If only one parameter is given then that value will be used for both scaleMin and scaleMax: * `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1 * * If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y: * `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2 * * If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly, * or pass `null` for the `maxX` and `maxY` parameters. * * Call `setScaleMinMax(null)` to clear all previously set values. * * @param minX The minimum horizontal scale value this Game Object can scale down to. * @param minY The minimum vertical scale value this Game Object can scale down to. * @param maxX The maximum horizontal scale value this Game Object can scale up to. * @param maxY The maximum vertical scale value this Game Object can scale up to. */ setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void; // minX: null | number /** * Override this method in your own custom objects to handle any update requirements. * It is called immediately after `preUpdate` and before `postUpdate`. * Remember if this Game Object has any children you should call update on those too. */ update(): void; /** * If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property, * or the rectangle it references, then you need to update the crop frame by calling this method. */ updateCrop(): void; } /** * An Image Collection is a special tileset containing mulitple images, with no slicing into each image. * * Image Collections are normally created automatically when Tiled data is loaded. */ class ImageCollection { /** * An Image Collection is a special tileset containing mulitple images, with no slicing into each image. * * Image Collections are normally created automatically when Tiled data is loaded. * * @param name The name of the image collection in the map data. * @param firstgid The first image index this image collection contains. * @param width Width of widest image (in pixels). - Default: 32 * @param height Height of tallest image (in pixels). - Default: 32 * @param margin The margin around all images in the collection (in pixels). * @param spacing The spacing between each image in the collection (in pixels). * @param properties Custom Image Collection properties. - Default: {} */ constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: any); /** * The name of the Image Collection. */ name: string; /** * The Tiled firstgid value. * This is the starting index of the first image index this Image Collection contains. */ firstgid: number; /** * The width of the widest image (in pixels). */ imageWidth: number; /** * The height of the tallest image (in pixels). */ imageHeight: number; /** * The margin around the images in the collection (in pixels). * Use `setSpacing` to change. */ imageMargin: number; /** * The spacing between each image in the collection (in pixels). * Use `setSpacing` to change. */ imageSpacing: number; /** * Image Collection-specific properties that are typically defined in the Tiled editor. */ properties: any; /** * The cached images that are a part of this collection. */ images: any[]; /** * The total number of images in the image collection. */ total: number; /** * 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: number, image: string): void; /** * Returns true if and only if this image collection contains the given image index. * * @param imageIndex The image index to search for. * @return True if this Image Collection contains the given index. */ containsImageIndex(imageIndex: number): boolean; } /** * Phaser.Input is the Input Manager for all types of Input across Phaser, including mouse, keyboard, touch and MSPointer. * The Input manager is updated automatically by the core game loop. */ class Input { /** * Phaser.Input is the Input Manager for all types of Input across Phaser, including mouse, keyboard, touch and MSPointer. * The Input manager is updated automatically by the core game loop. * * @param game Current game instance. */ constructor(game: Phaser.Game); /** * The maximum number of pointers that can be added. This excludes the mouse pointer. */ static MAX_POINTERS: number; static MOUSE_OVERRIDES_TOUCH: number; static MOUSE_TOUCH_COMBINE: number; static TOUCH_OVERRIDES_MOUSE: number; /** * The most recently active Pointer object. * * When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse. */ activePointer: Phaser.Pointer; /** * A Circle object centered on the x/y screen coordinates of the Input. * Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything. */ circle: Phaser.Circle; /** * When enabled, input (eg. Keyboard, Mouse, Touch) will be processed - as long as the individual sources are enabled themselves. * * When not enabled, _all_ input sources are ignored. To disable just one type of input; for example, the Mouse, use `input.mouse.enabled = false`. * Default: true */ enabled: boolean; /** * The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click. * Default: 300 */ doubleTapRate: number; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The Gamepad Input manager. */ gamepad: Phaser.Gamepad; /** * The canvas to which single pixels are drawn in order to perform pixel-perfect hit detection. */ hitCanvas: HTMLCanvasElement; /** * The context of the pixel perfect hit canvas. */ hitContext: CanvasRenderingContext2D; /** * The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event. * Default: 2000 */ holdRate: number; /** * A list of interactive objects. The InputHandler components add and remove themselves from this list. */ interactiveItems: Phaser.ArraySet; /** * The number of milliseconds below which the Pointer is considered justPressed. * Default: 200 */ justPressedRate: number; /** * The number of milliseconds below which the Pointer is considered justReleased . * Default: 200 */ justReleasedRate: number; /** * The Keyboard Input manager. */ keyboard: Phaser.Keyboard; /** * The maximum number of Pointers allowed to be *active* at any one time. * A value of -1 is only limited by the total number of pointers (MAX_POINTERS). For lots of games it's useful to set this to 1. * At least 2 Pointers will always be *created*, unless MAX_POINTERS is smaller. * Default: -1 (Limited by total pointers.) */ maxPointers: number; /** * You can tell all Pointers to ignore any Game Object with a `priorityID` lower than this value. * This is useful when stacking UI layers. Set to zero to disable. */ minPriorityID: number; /** * The Mouse Input manager. * * You should not usually access this manager directly, but instead use Input.mousePointer or Input.activePointer * which normalizes all the input values for you, regardless of browser. */ mouse: Phaser.Mouse; /** * The mouse has its own unique Phaser.Pointer object which you can use if making a desktop specific game. * * The mouse pointer is updated by {@link Phaser.Input#mouse} and {@link Phaser.Input#mspointer}. */ mousePointer: Phaser.Pointer; /** * An array of callbacks that will be fired every time the activePointer receives a move event from the DOM. * To add a callback to this array please use `Input.addMoveCallback`. */ moveCallbacks: (pointer: Phaser.Pointer, x: number, y: number) => void[]; /** * The MSPointer Input manager. * * You should not usually access this manager directly, but instead use Input.activePointer * which normalizes all the input values for you, regardless of browser. */ mspointer: Phaser.MSPointer; /** * Controls the expected behavior when using a mouse and touch together on a multi-input device. */ multiInputOverride: number; /** * A Signal that is dispatched each time a {@link Phaser.Pointer pointer} is pressed down. * It is sent two arguments: * * - {Phaser.Pointer} The pointer that caused the event. * - {Event} The original DOM event. */ onDown: Phaser.Signal; /** * A Signal that is dispatched each time a {@link Phaser.Pointer pointer} is held down. * It is sent one argument: * * - {Phaser.Pointer} The pointer that caused the event. */ onHold: Phaser.Signal; /** * A Signal that is dispatched each time a {@link Phaser.Pointer pointer} is tapped. * It is sent two arguments: * * - {Phaser.Pointer} The pointer that caused the event. * - {boolean} True if this was a double tap. */ onTap: Phaser.Signal; /** * A Signal that is dispatched each time a {@link Phaser.Pointer pointer} is released. * It is sent two arguments: * * - {Phaser.Pointer} The pointer that caused the event. * - {Event} The original DOM event. */ onUp: Phaser.Signal; /** * A Pointer object. */ pointer1: Phaser.Pointer; /** * A Pointer object. */ pointer2: Phaser.Pointer; /** * A Pointer object. */ pointer3: Phaser.Pointer; /** * A Pointer object. */ pointer4: Phaser.Pointer; /** * A Pointer object. */ pointer5: Phaser.Pointer; /** * A Pointer object. */ pointer6: Phaser.Pointer; /** * A Pointer object. */ pointer7: Phaser.Pointer; /** * A Pointer object. */ pointer8: Phaser.Pointer; /** * A Pointer object. */ pointer9: Phaser.Pointer; /** * A Pointer object. */ pointer10: Phaser.Pointer; /** * True if the Input is currently poll rate locked. */ pollLocked: boolean; /** * How often should the input pointers be checked for updates? A value of 0 means every single frame (60fps); a value of 1 means every other frame (30fps) and so on. */ pollRate: number; /** * A point object representing the current position of the Pointer. */ position: Phaser.Point; /** * A pool of non-mouse (contact) pointers that have been added to the game. * They're activated and updated by {@link Phaser.Input#mspointer} and {@link Phaser.Input#touch}. * The properties `pointer1..10` are aliases for `pointers[0..9]`. */ pointers: Phaser.Pointer[]; /** * The total number of entries that can be recorded into the Pointer objects tracking history. * If the Pointer is tracking one event every 100ms; then a trackLimit of 100 would store the last 10 seconds worth of history. * Default: 100 */ recordLimit: number; /** * Sets if the Pointer objects should record a history of x/y coordinates they have passed through. * The history is cleared each time the Pointer is pressed down. * The history is updated at the rate specified in Input.pollRate */ recordPointerHistory: boolean; /** * The rate in milliseconds at which the Pointer objects should update their tracking history. * Default: 100 */ recordRate: number; /** * If the Input Manager has been reset locked then all calls made to InputManager.reset, * such as from a State change, are ignored. */ resetLocked: boolean; /** * The scale by which all input coordinates are multiplied; calculated by the ScaleManager. In an un-scaled game the values will be x = 1 and y = 1. */ scale: Phaser.Point; /** * A point object representing the speed of the Pointer. Only really useful in single Pointer games; otherwise see the Pointer objects directly. */ speed: Phaser.Point; /** * The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click. * Default: 200 */ tapRate: number; /** * The total number of active Pointers, not counting the mouse pointer. */ totalActivePointers: number; /** * The total number of inactive Pointers. */ totalInactivePointers: number; /** * The Touch Input manager. * * You should not usually access this manager directly, but instead use Input.activePointer * which normalizes all the input values for you, regardless of browser. */ touch: Phaser.Touch; /** * The world X coordinate of the most recently active pointer. */ worldX: number; /** * The world Y coordinate of the most recently active pointer. */ worldY: number; /** * The X coordinate of the most recently active pointer. * This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values. */ x: number; /** * The Y coordinate of the most recently active pointer. * This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values. */ y: number; /** * Add a new Pointer object to the Input Manager. * By default Input creates 3 pointer objects: `mousePointer` (not include in part of general pointer pool), `pointer1` and `pointer2`. * This method adds an additional pointer, up to a maximum of Phaser.Input.MAX_POINTERS (default of 10). * @return The new Pointer object that was created; null if a new pointer could not be added. */ addPointer(): Phaser.Pointer; /** * Adds a callback that is fired every time the activePointer receives a DOM move event such as a mousemove or touchmove. * * The callback will be sent 5 parameters: * * - A reference to the Phaser.Pointer object that moved * - The x position of the pointer * - The y position * - A boolean indicating if the movement was the result of a 'click' event (such as a mouse click or touch down) * - The DOM move event * * It will be called every time the activePointer moves, which in a multi-touch game can be a lot of times, so this is best * to only use if you've limited input to a single pointer (i.e. mouse or touch). * * The callback is added to the Phaser.Input.moveCallbacks array and should be removed with Phaser.Input.deleteMoveCallback. * * @param callback The callback that will be called each time the activePointer receives a DOM move event. * @param context The context in which the callback will be called. */ addMoveCallback(callback: Function, context: any): number; /** * Starts the Input Manager running. * * @param config */ boot(config: InputConfig): void; countActivePointers(limit?: number): number; /** * Removes the callback from the Phaser.Input.moveCallbacks array. * * @param callback The callback to be removed. * @param context The context in which the callback exists. */ deleteMoveCallback(callback: Function, context?: any): void; /** * Stops all of the Input Managers from running. */ destroy(): void; /** * This will return the local coordinates of the specified displayObject based on the given Pointer. * * @param displayObject The DisplayObject to get the local coordinates for. * @param pointer The Pointer to use in the check against the displayObject. * @return A point containing the coordinates of the Pointer position relative to the DisplayObject. */ getLocalPosition(displayObject: any, pointer: Phaser.Pointer): Phaser.Point; /** * Get the first Pointer with the given active state. * * @param isActive The state the Pointer should be in - active or inactive? * @return A Pointer object or null if no Pointer object matches the requested state. */ getPointer(isActive?: boolean): Phaser.Pointer; /** * Get the Pointer object whos `pointerId` property matches the given value. * * The pointerId property is not set until the Pointer has been used at least once, as its populated by the DOM event. * Also it can change every time you press the pointer down if the browser recycles it. * * @param pointerId The `pointerId` (not 'id') value to search for. * @return A Pointer object or null if no Pointer object matches the requested identifier. */ getPointerFromId(pointerID: number): Phaser.Pointer; /** * Get the Pointer object whos `identifier` property matches the given identifier value. * * The identifier property is not set until the Pointer has been used at least once, as its populated by the DOM event. * Also it can change every time you press the pointer down, and is not fixed once set. * Note: Not all browsers set the identifier property and it's not part of the W3C spec, so you may need getPointerFromId instead. * * @param identifier The Pointer.identifier value to search for. * @return A Pointer object or null if no Pointer object matches the requested identifier. */ getPointerFromIdentifier(identifier: number): Phaser.Pointer; /** * Tests if the pointer hits the given object. * * @param displayObject The displayObject to test for a hit. * @param pointer The pointer to use for the test. * @param localPoint The local translated point. */ hitTest(displayObject: PIXI.DisplayObject, pointer: Phaser.Pointer, localPoint: Phaser.Point): void; /** * Reset all of the Pointers and Input states. * * The optional `hard` parameter will reset any events or callbacks that may be bound. * Input.reset is called automatically during a State change or if a game loses focus / visibility. * To control control the reset manually set {@link Phaser.InputManager.resetLocked} to `true`. * * @param hard A soft reset won't reset any events or callbacks that are bound. A hard reset will. */ reset(hard?: boolean): void; /** * Resets the speed and old position properties. * * @param x Sets the oldPosition.x value. * @param y Sets the oldPosition.y value. */ resetSpeed(x: number, y: number): void; /** * Adds a callback that is fired every time `Pointer.processInteractiveObjects` is called. * The purpose of `processInteractiveObjects` is to work out which Game Object the Pointer is going to * interact with. It works by polling all of the valid game objects, and then slowly discounting those * that don't meet the criteria (i.e. they aren't under the Pointer, are disabled, invisible, etc). * * Eventually a short-list of 'candidates' is created. These are all of the Game Objects which are valid * for input and overlap with the Pointer. If you need fine-grained control over which of the items is * selected then you can use this callback to do so. * * The callback will be sent 3 parameters: * * 1) A reference to the Phaser.Pointer object that is processing the Items. * 2) An array containing all potential interactive candidates. This is an array of `InputHandler` objects, not Sprites. * 3) The current 'favorite' candidate, based on its priorityID and position in the display list. * * Your callback MUST return one of the candidates sent to it. * * @param callback The callback that will be called each time `Pointer.processInteractiveObjects` is called. Set to `null` to disable. * @param context The context in which the callback will be called. */ setInteractiveCandidateHandler(callback: Function, context?: any): void; /** * Find the first free Pointer object and start it, passing in the event data. * This is called automatically by Phaser.Touch and Phaser.MSPointer. * * @param event The event data from the Touch event. * @return The Pointer object that was started or null if no Pointer object is available. */ startPointer(event: any): Phaser.Pointer; /** * Stops the matching Pointer object, passing in the event data. * * @param event The event data from the Touch event. * @return The Pointer object that was stopped or null if no Pointer object is available. */ stopPointer(event: any): Phaser.Pointer; /** * Updates the Input Manager. Called by the core Game loop. */ update(): void; /** * Updates the matching Pointer object, passing in the event data. * This is called automatically and should not normally need to be invoked. * * @param event The event data from the Touch event. * @return The Pointer object that was updated; null if no pointer was updated. */ updatePointer(event: any): Phaser.Pointer; } /** * The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite. */ class InputHandler { /** * The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite. * * @param sprite The Sprite object to which this Input Handler belongs. */ constructor(sprite: Phaser.Sprite); /** * Controls if the Sprite is allowed to be dragged horizontally. * Default: true */ allowHorizontalDrag: boolean; /** * Controls if the Sprite is allowed to be dragged vertically. * Default: true */ allowVerticalDrag: boolean; /** * A region of the game world within which the sprite is restricted during drag. */ boundsRect: Phaser.Rectangle; /** * A Sprite the bounds of which this sprite is restricted during drag. */ boundsSprite: Phaser.Sprite; /** * If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within. */ bringToTop: boolean; /** * A Point object containing the coordinates of the Pointer when it was first pressed down onto this Sprite. */ downPoint: Phaser.Point; /** * The distance, in pixels, the pointer has to move while being held down, before the Sprite thinks it is being dragged. */ dragDistanceThreshold: number; /** * The offset from the Sprites position that dragging takes place from. */ dragOffset: Phaser.Point; /** * Is the Sprite dragged from its center, or the point at which the Pointer was pressed down upon it? */ dragFromCenter: boolean; /** * Is this sprite allowed to be dragged by the mouse? true = yes, false = no */ draggable: boolean; /** * The Point from which the most recent drag started from. Useful if you need to return an object to its starting position. */ dragStartPoint: Phaser.Point; /** * If enabled, when the Sprite stops being dragged, it will only dispatch the `onDragStop` event, and not the `onInputUp` event. If set to `false` it will dispatch both events. */ dragStopBlocksInputUp: boolean; /** * The amount of time, in ms, the pointer has to be held down over the Sprite before it thinks it is being dragged. */ dragTimeThreshold: number; /** * If enabled the Input Handler will process input requests and monitor pointer activity. */ enabled: boolean; /** * A reference to the currently running game. */ game: Phaser.Game; /** * Warning: EXPERIMENTAL * * @param x */ globalToLocalX(x: number): number; /** * Warning: EXPERIMENTAL * * @param y */ globalToLocalY(y: number): number; /** * true if the Sprite is being currently dragged. */ isDragged: boolean; /** * The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit. * Default: 255 */ pixelPerfectAlpha: number; /** * Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite when it's clicked or touched. * The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value. * This feature only works for display objects with image based textures such as Sprites. It won't work on BitmapText or Rope. * Warning: This is expensive so only enable if you really need it. Use a pixel perfect check when testing for clicks or touches on the Sprite. */ pixelPerfectClick: boolean; /** * Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite. * The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value. * This feature only works for display objects with image based textures such as Sprites. It won't work on BitmapText or Rope. * Warning: This is expensive, especially on mobile (where it's not even needed!) so only enable if required. Also see the less-expensive InputHandler.pixelPerfectClick. Use a pixel perfect check when testing for pointer over. */ pixelPerfectOver: boolean; /** * The priorityID is used to determine which game objects should get priority when input events occur. For example if you have * several Sprites that overlap, by default the one at the top of the display list is given priority for input events. You can * stop this from happening by controlling the priorityID value. The higher the value, the more important they are considered to the Input events. */ priorityID: number; /** * EXPERIMENTAL: Please do not use this property unless you know what it does. Likely to change in the future. */ scaleLayer: boolean; /** * A Point object that contains by how far the Sprite snap is offset. */ snapOffset: Phaser.Point; /** * This defines the top-left X coordinate of the snap grid. */ snapOffsetX: number; /** * This defines the top-left Y coordinate of the snap grid.. */ snapOffsetY: number; /** * When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not. */ snapOnDrag: boolean; /** * When the Sprite is dragged this controls if the Sprite will be snapped on release. */ snapOnRelease: boolean; /** * If the sprite is set to snap while dragging this holds the point of the most recent 'snap' event. */ snapPoint: Phaser.Point; /** * When a Sprite has snapping enabled this holds the width of the snap grid. */ snapX: number; /** * When a Sprite has snapping enabled this holds the height of the snap grid. */ snapY: number; /** * The Sprite object to which this Input Handler belongs. */ sprite: Phaser.Sprite; /** * On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite. */ useHandCursor: boolean; /** * Bounds Rect check for the sprite drag */ checkBoundsRect(): void; /** * Parent Sprite Bounds check for the sprite drag. */ checkBoundsSprite(): void; /** * Runs a pixel perfect check against the given x/y coordinates of the Sprite this InputHandler is bound to. * It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true. * * @param x The x coordinate to check. * @param y The y coordinate to check. * @param pointer The pointer to get the x/y coordinate from if not passed as the first two parameters. * @return true if there is the alpha of the pixel is >= InputHandler.pixelPerfectAlpha */ checkPixel(x: number, y: number, pointer?: Phaser.Pointer): boolean; /** * Checks if the given pointer is both down and over the Sprite this InputHandler belongs to. * Use the `fastTest` flag is to quickly check just the bounding hit area even if `InputHandler.pixelPerfectOver` is `true`. * * @param pointer * @param fastTest Force a simple hit area check even if `pixelPerfectOver` is true for this object? * @return True if the pointer is down, otherwise false. */ checkPointerDown(pointer: Phaser.Pointer, fastTest?: boolean): boolean; /** * Checks if the given pointer is over the Sprite this InputHandler belongs to. * Use the `fastTest` flag is to quickly check just the bounding hit area even if `InputHandler.pixelPerfectOver` is `true`. * * @param pointer * @param fastTest Force a simple hit area check even if `pixelPerfectOver` is true for this object? */ checkPointerOver(pointer: Phaser.Pointer, fastTest?: boolean): boolean; /** * Clean up memory. */ destroy(): void; /** * Stops this sprite from being able to be dragged. * If it is currently the target of an active drag it will be stopped immediately; also disables any set callbacks. */ disableDrag(): void; /** * Stops the sprite from snapping to a grid during drag or release. */ disableSnap(): void; /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. * * @param pointerId * @return The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over. */ downDuration(pointerId?: number): number; /** * Allow this Sprite to be dragged by any valid pointer. * * When the drag begins the Sprite.events.onDragStart event will be dispatched. * * When the drag completes by way of the user letting go of the pointer that was dragging the sprite, the Sprite.events.onDragStop event is dispatched. * * You can control the thresholds over when a drag starts via the properties: * * `Pointer.dragDistanceThreshold` the distance, in pixels, that the pointer has to move * before the drag will start. * * `Pointer.dragTimeThreshold` the time, in ms, that the pointer must be held down on * the Sprite before the drag will start. * * You can set either (or both) of these properties after enabling a Sprite for drag. * * For the duration of the drag the Sprite.events.onDragUpdate event is dispatched. This event is only dispatched when the pointer actually * changes position and moves. The event sends 8 parameters: `sprite`, `pointer`, `dragX`, `dragY`, `snapPoint`, `fromStart`, `deltaX`, and `deltaY`. * * @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer. * @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group. * @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box. * @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed. - Default: 255 * @param boundsRect If you want to restrict the drag of this sprite to a specific Rectangle, pass the Phaser.Rectangle here, otherwise it's free to drag anywhere. * @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here. */ enableDrag(lockCenter?: boolean, bringToTop?: boolean, pixelPerfect?: boolean, alphaThreshold?: number, boundsRect?: Phaser.Rectangle, boundsSprite?: Phaser.Sprite): void; /** * Make this Sprite snap to the given grid either during drag or when it's released. * For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels. * * @param snapX The width of the grid cell to snap to. * @param snapY The height of the grid cell to snap to. * @param onDrag If true the sprite will snap to the grid while being dragged. - Default: true * @param onRelease If true the sprite will snap to the grid when released. * @param snapOffsetX Used to offset the top-left starting point of the snap grid. * @param snapOffsetY Used to offset the top-left starting point of the snap grid. */ enableSnap(snapX: number, snapY: number, onDrag?: boolean, onRelease?: boolean, snapOffsetX?: number, snapOffsetY?: number): void; /** * Is this object using pixel perfect checking? * @return True if the this InputHandler has either `pixelPerfectClick` or `pixelPerfectOver` set to `true`. */ isPixelPerfect(): boolean; /** * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) * * @param pointerId * @param delay The time below which the pointer is considered as just out. */ justOut(pointerId?: number, delay?: number): boolean; /** * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) * * @param pointerId * @param delay The time below which the pointer is considered as just over. */ justOver(pointerId?: number, delay?: number): boolean; /** * Returns true if the pointer has touched or clicked on the Sprite within the specified delay time (defaults to 500ms, half a second) * * @param pointerId * @param delay The time below which the pointer is considered as just over. */ justPressed(pointerId?: number, delay?: number): boolean; /** * Returns true if the pointer was touching this Sprite, but has been released within the specified delay time (defaults to 500ms, half a second) * * @param pointerId * @param delay The time below which the pointer is considered as just out. */ justReleased(pointerId?: number, delay?: number): boolean; /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. * * @param pointerId * @return The number of milliseconds the pointer has been over the Sprite, or -1 if not over. */ overDuration(pointerId?: number): number; /** * If the Pointer is down this returns true. * This *only* checks if the Pointer is down, not if it's down over any specific Sprite. * * @param pointerId * @return - True if the given pointer is down, otherwise false. */ pointerDown(pointerId?: number): boolean; /** * Is this sprite being dragged by the mouse or not? * * @param pointerId * @return True if the pointer is dragging an object, otherwise false. */ pointerDragged(pointerId?: number): boolean; /** * Is the Pointer outside of this Sprite? * * @param pointerId The ID number of a Pointer to check. If you don't provide a number it will check all Pointers. - Default: (check all) * @return True if the given pointer (if a index was given, or any pointer if not) is out of this object. */ pointerOut(pointerId?: number): boolean; /** * Is the Pointer over this Sprite? * * @param pointerId The ID number of a Pointer to check. If you don't provide a number it will check all Pointers. - Default: (check all) * @return - True if the given pointer (if a index was given, or any pointer if not) is over this object. */ pointerOver(pointerId?: number): boolean; /** * A timestamp representing when the Pointer first touched the touchscreen. * * @param pointerId - Default: (check all) */ pointerTimeDown(pointerId?: number): number; /** * A timestamp representing when the Pointer left the touchscreen. * * @param pointerId */ pointerTimeOut(pointerId?: number): number; /** * A timestamp representing when the Pointer first touched the touchscreen. * * @param pointerId */ pointerTimeOver(pointerId?: number): number; /** * A timestamp representing when the Pointer left the touchscreen. * * @param pointerId */ pointerTimeUp(pointerId?: number): number; /** * If the Pointer is up this returns true. * This *only* checks if the Pointer is up, not if it's up over any specific Sprite. * * @param pointerId * @return - True if the given pointer is up, otherwise false. */ pointerUp(pointerId?: number): boolean; /** * The x coordinate of the Input pointer, relative to the top-left of the parent Sprite. * This value is only set when the pointer is over this Sprite. * * @param pointerId * @return The x coordinate of the Input pointer. */ pointerX(pointerId?: number): number; /** * The y coordinate of the Input pointer, relative to the top-left of the parent Sprite * This value is only set when the pointer is over this Sprite. * * @param pointerId * @return The y coordinate of the Input pointer. */ pointerY(pointerId?: number): number; /** * Resets the Input Handler and disables it. */ reset(): void; /** * Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! * * @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false. - Default: true * @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false. - Default: true */ setDragLock(allowHorizontal?: boolean, allowVertical?: boolean): void; /** * Starts the Input Handler running. This is called automatically when you enable input on a Sprite, or can be called directly if you need to set a specific priority. * * @param priority Higher priority sprites take click priority over low-priority sprites when they are stacked on-top of each other. * @param useHandCursor If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers) * @return The Sprite object to which the Input Handler is bound. */ start(priority?: number, useHandCursor?: boolean): Phaser.Sprite; /** * Called by Pointer when drag starts on this Sprite. Should not usually be called directly. * * @param pointer */ startDrag(pointer: Phaser.Pointer): void; /** * Stops the Input Handler from running. */ stop(): void; /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. * * @param pointer */ stopDrag(pointer: Phaser.Pointer): void; /** * Internal Update method. This is called automatically and handles the Pointer * and drag update loops. * * @param pointer * @return True if the pointer is still active, otherwise false. */ update(pointer: Phaser.Pointer): void; /** * Called as a Pointer actively drags this Game Object. * * @param pointer The Pointer causing the drag update. * @param fromStart True if this is the first update, immediately after the drag has started. */ updateDrag(pointer: Phaser.Pointer): boolean; /** * Checks if the object this InputHandler is bound to is valid for consideration in the Pointer move event. * This is called by Phaser.Pointer and shouldn't typically be called directly. * * @param highestID The highest ID currently processed by the Pointer. * @param highestRenderID The highest Render Order ID currently processed by the Pointer. * @param includePixelPerfect If this object has `pixelPerfectClick` or `pixelPerfectOver` set should it be considered as valid? - Default: true * @return True if the object this InputHandler is bound to should be considered as valid for input detection. */ validForInput(highestID: number, highestRenderID: number, includePixelPerfect?: boolean): boolean; } /** * If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects. */ class Key { /** * If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects. * * @param game Current game instance. * @param keycode The key code this Key is responsible for. See {@link Phaser.KeyCode}. */ constructor(game: Phaser.Game, keycode: number); /** * The down state of the ALT key, if pressed at the same time as this key. */ altKey: boolean; /** * The down state of the CTRL key, if pressed at the same time as this key. */ ctrlKey: boolean; /** * If the key is down this value holds the duration of that key press and is constantly updated. * If the key is up it holds the duration of the previous down session. The number of milliseconds this key has been held down for. */ duration: number; /** * An enabled key processes its update and dispatches events. * A key can be disabled momentarily at runtime instead of deleting it. * Default: true */ enabled: boolean; /** * Stores the most recent DOM event. */ event: any; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down. */ isDown: boolean; /** * The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up. * Default: true */ isUp: boolean; /** * True if the key has just been pressed (NOTE: requires to be reset, see justDown getter) */ _justDown: boolean; /** * The justDown value allows you to test if this Key has just been pressed down or not. * When you check this value it will return `true` if the Key is down, otherwise `false`. * 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 a Signal, such as in a core game loop. * Default: false */ justDown: boolean; /** * True if the key has just been pressed (NOTE: requires to be reset, see justDown getter) */ _justUp: 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 a Signal, such as in a core game loop. * Default: false */ justUp: boolean; /** * The keycode of this key. */ keyCode: number; /** * This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again). */ onDown: Phaser.Signal; /** * A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second. */ onHoldCallback: Function; /** * The context under which the onHoldCallback will be called. */ onHoldContext: any; /** * This Signal is dispatched every time this Key is released. It is only dispatched once (until the key is pressed and released again). */ onUp: Phaser.Signal; /** * If a key is held down this holds down the number of times the key has 'repeated'. */ repeats: number; /** * The down state of the SHIFT key, if pressed at the same time as this key. */ shiftKey: boolean; /** * The timestamp when the key was last pressed down. This is based on Game.time.now. */ timeDown: number; /** * The timestamp when the key was last released. This is based on Game.time.now. */ timeUp: number; /** * Returns `true` if the Key was pressed down within the `duration` value given, or `false` if it either isn't down, * or was pressed down longer ago than then given duration. * * @param duration The duration within which the key is considered as being just pressed. Given in ms. - Default: 50 * @return True if the key was pressed down within the given duration. */ downDuration(duration?: number): boolean; /** * Called automatically by Phaser.Keyboard. * * @param event The DOM event that triggered this. */ processKeyDown(event: KeyboardEvent): void; /** * Called automatically by Phaser.Keyboard. * * @param event The DOM event that triggered this. */ processKeyUp(event: KeyboardEvent): void; /** * Resets the state of this Key. * * This sets isDown to false, isUp to true, resets the time to be the current time, and _enables_ the key. * In addition, if it is a "hard reset", it clears clears any callbacks associated with the onDown and onUp events and removes the onHoldCallback. * * @param hard A soft reset won't reset any events or callbacks; a hard reset will. - Default: true */ reset(hard?: boolean): void; /** * Called automatically by Phaser.Keyboard. */ update(): void; /** * Returns `true` if the Key has been up *only* within the `duration` value given, or `false` if it either isn't up, * or was has been up longer than the given duration. * * @param duration The duration within which the key is considered as being just released. Given in ms. - Default: 50 * @return True if the key was released within the given duration. */ upDuration(duration?: number): boolean; } /** * The Keyboard class monitors keyboard input and dispatches keyboard events. * * _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. * * 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. And there are others. * So please check your extensions before opening Phaser issues. */ class Keyboard { /** * The Keyboard class monitors keyboard input and dispatches keyboard events. * * _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. * * 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. And there are others. * So please check your extensions before opening Phaser issues. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); static A: number; static B: number; static C: number; static D: number; static E: number; static F: number; static G: number; static H: number; static I: number; static J: number; static K: number; static L: number; static M: number; static N: number; static O: number; static P: number; static Q: number; static R: number; static S: number; static T: number; static U: number; static V: number; static W: number; static X: number; static Y: number; static Z: number; static ZERO: number; static ONE: number; static TWO: number; static THREE: number; static FOUR: number; static FIVE: number; static SIX: number; static SEVEN: number; static EIGHT: number; static NINE: number; static NUMPAD_0: number; static NUMPAD_1: number; static NUMPAD_2: number; static NUMPAD_3: number; static NUMPAD_4: number; static NUMPAD_5: number; static NUMPAD_6: number; static NUMPAD_7: number; static NUMPAD_8: number; static NUMPAD_9: number; static NUMPAD_MULTIPLY: number; static NUMPAD_ADD: number; static NUMPAD_ENTER: number; static NUMPAD_SUBTRACT: number; static NUMPAD_DECIMAL: number; static NUMPAD_DIVIDE: number; static F1: number; static F2: number; static F3: number; static F4: number; static F5: number; static F6: number; static F7: number; static F8: number; static F9: number; static F10: number; static F11: number; static F12: number; static F13: number; static F14: number; static F15: number; static COLON: number; static EQUALS: number; static COMMA: number; static UNDERSCORE: number; static PERIOD: number; static QUESTION_MARK: number; static TILDE: number; static OPEN_BRACKET: number; static BACKWARD_SLASH: number; static CLOSED_BRACKET: number; static QUOTES: number; static BACKSPACE: number; static TAB: number; static CLEAR: number; static ENTER: number; static SHIFT: number; static CONTROL: number; static ALT: number; static CAPS_LOCK: number; static ESC: number; static SPACEBAR: number; static PAGE_UP: number; static PAGE_DOWN: number; static END: number; static HOME: number; static LEFT: number; static UP: number; static RIGHT: number; static DOWN: number; static INSERT: number; static DELETE: number; static HELP: number; static NUM_LOCK: number; static PLUS: number; static MINUS: number; /** * Whether the handler has started. */ active: boolean; /** * The context under which the callbacks are run. */ callbackContext: any; /** * Keyboard input will only be processed if enabled. * Default: true */ enabled: boolean; /** * The most recent DOM event from keydown or keyup. This is updated every time a new key is pressed or released. */ event: any; /** * Local reference to game. */ game: Phaser.Game; /** * Returns the string value of the most recently pressed key. */ lastChar: string; /** * Returns the most recently pressed Key. This is a Phaser.Key object and it changes every time a key is pressed. */ lastKey: Phaser.Key; /** * This callback is invoked every time a key is pressed down, including key repeats when a key is held down. One argument is passed: {KeyboardEvent} event. */ onDownCallback: Function; /** * This callback is invoked every time a DOM onkeypress event is raised, which is only for printable keys. Two arguments are passed: {string} `String.fromCharCode(event.charCode)` and {KeyboardEvent} event. */ onPressCallback: Function; /** * This callback is invoked every time a key is released. One argument is passed: {KeyboardEvent} event. */ onUpCallback: Function; /** * The most recent DOM event from keypress. */ pressEvent: any; /** * Add callbacks to the Keyboard handler so that each time a key is pressed down or released the callbacks are activated. * * @param context The context under which the callbacks are run. * @param onDown This callback is invoked every time a key is pressed down. * @param onUp This callback is invoked every time a key is released. * @param onPress This callback is invoked every time the onkeypress event is raised. */ addCallbacks(context: any, onDown?: Function, onUp?: Function, onPress?: Function): void; /** * If you need more fine-grained control over a Key you can create a new Phaser.Key object via this method. * The Key object can then be polled, have events attached to it, etc. * * @param keycode The {@link Phaser.KeyCode keycode} of the key. * @return The Key object which you can store locally and reference directly. */ addKey(keycode: number): Phaser.Key; /** * A practical way to create an object containing user selected hotkeys. * * For example, * * addKeys( { 'up': Phaser.KeyCode.W, 'down': Phaser.KeyCode.S, 'left': Phaser.KeyCode.A, 'right': Phaser.KeyCode.D } ); * * would return an object containing properties (`up`, `down`, `left` and `right`) referring to {@link Phaser.Key} object. * * @param keys A key mapping object, i.e. `{ 'up': Phaser.KeyCode.W, 'down': Phaser.KeyCode.S }` or `{ 'up': 52, 'down': 53 }`. * @return An object containing the properties mapped to {@link Phaser.Key} values. */ addKeys(keys: any): 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. * * The `addKeyCapture` method enables consuming keyboard event for specific keys so it doesn't bubble up to the the browser * and cause the default browser behavior. * * Pass in either a single keycode or an array/hash of keycodes. * * @param keycode Either a single {@link Phaser.KeyCode keycode} or an array/hash of keycodes such as `[65, 67, 68]`. */ addKeyCapture(keycode: any): void; /** * Creates and returns an object containing 4 hotkeys for Up, Down, Left and Right. * @return An object containing properties: `up`, `down`, `left` and `right` of {@link Phaser.Key} objects. */ createCursorKeys(): Phaser.CursorKeys; /** * Clear all set key captures. */ clearCaptures(): void; /** * Stops the Keyboard event listeners from running (keydown and keyup). They are removed from the window. * Also clears all key captures and currently created Key objects. */ destroy(): void; /** * Returns `true` if the Key was pressed down within the `duration` value given, or `false` if it either isn't down, * or was pressed down longer ago than then given duration. * * @param keycode The {@link Phaser.KeyCode keycode} of the key to check: i.e. Phaser.KeyCode.UP or Phaser.KeyCode.SPACEBAR. * @param duration The duration within which the key is considered as being just pressed. Given in ms. - Default: 50 * @return True if the key was pressed down within the given duration, false if not or null if the Key wasn't found. */ downDuration(keycode: number, duration?: number): boolean; /** * Returns true of the key is currently pressed down. Note that it can only detect key presses on the web browser. * * @param keycode The {@link Phaser.KeyCode keycode} of the key to check: i.e. Phaser.KeyCode.UP or Phaser.KeyCode.SPACEBAR. * @return True if the key is currently down, false if not or null if the Key wasn't found. */ isDown(keycode: number): boolean; /** * Process the keydown event. * * @param event */ processKeyDown(event: KeyboardEvent): void; /** * Process the keypress event. * * @param event */ processKeyPress(event: KeyboardEvent): void; /** * Process the keyup event. * * @param event */ processKeyUp(event: KeyboardEvent): void; /** * Removes callbacks added by {@link Phaser.Keyboard#addCallbacks addCallbacks} and restores {@link Phaser.Keyboard#callbackContext callbackContext}. */ removeCallbacks(): void; /** * Removes a Key object from the Keyboard manager. * * @param keycode The {@link Phaser.KeyCode keycode} of the key to remove. */ removeKey(keycode: number): void; /** * Removes an existing key capture. * * @param keycode The {@link Phaser.KeyCode keycode} to remove capturing of. */ removeKeyCapture(keycode: number): void; /** * Resets all Keys. * * @param hard A soft reset won't reset any events or callbacks that are bound to the Keys. A hard reset will. - Default: true */ reset(hard?: boolean): void; /** * Starts the Keyboard event listeners running (keydown, keyup and keypress). They are attached to the window. * This is called automatically by Phaser.Input and should not normally be invoked directly. */ start(): void; /** * Stops the Keyboard event listeners from running (keydown, keyup and keypress). They are removed from the window. */ stop(): void; /** * Updates all currently defined keys. */ update(): void; /** * Returns `true` if the Key has been up *only* within the `duration` value given, or `false` if it either isn't up, * or was has been up longer than the given duration. * * @param keycode The keycode of the key to check, i.e. Phaser.KeyCode.UP or Phaser.KeyCode.SPACEBAR. * @param duration The duration within which the key is considered as being just released. Given in ms. - Default: 50 * @return True if the key was released within the given duration, false if not or null if the Key wasn't found. */ upDuration(keycode: number, duration?: number): boolean; } /** * A key code represents a physical key on a keyboard. * * The KeyCode class contains commonly supported keyboard key codes which can be used * as keycode`-parameters in several {@link Phaser.Keyboard} and {@link Phaser.Key} methods. * * _Note_: These values should only be used indirectly, eg. as `Phaser.KeyCode.KEY`. * Future versions may replace the actual values, such that they remain compatible with `keycode`-parameters. * The current implementation maps to the {@link https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode KeyboardEvent.keyCode} property. * * _Note_: Use `Phaser.KeyCode.KEY` instead of `Phaser.Keyboard.KEY` to refer to a key code; * the latter approach is supported for compatibility. */ class KeyCode { static A: number; static B: number; static C: number; static D: number; static E: number; static F: number; static G: number; static H: number; static I: number; static J: number; static K: number; static L: number; static M: number; static N: number; static O: number; static P: number; static Q: number; static R: number; static S: number; static T: number; static U: number; static V: number; static W: number; static X: number; static Y: number; static Z: number; static ZERO: number; static ONE: number; static TWO: number; static THREE: number; static FOUR: number; static FIVE: number; static SIX: number; static SEVEN: number; static EIGHT: number; static NINE: number; static NUMPAD_0: number; static NUMPAD_1: number; static NUMPAD_2: number; static NUMPAD_3: number; static NUMPAD_4: number; static NUMPAD_5: number; static NUMPAD_6: number; static NUMPAD_7: number; static NUMPAD_8: number; static NUMPAD_9: number; static NUMPAD_MULTIPLY: number; static NUMPAD_ADD: number; static NUMPAD_ENTER: number; static NUMPAD_SUBTRACT: number; static NUMPAD_DECIMAL: number; static NUMPAD_DIVIDE: number; static F1: number; static F2: number; static F3: number; static F4: number; static F5: number; static F6: number; static F7: number; static F8: number; static F9: number; static F10: number; static F11: number; static F12: number; static F13: number; static F14: number; static F15: number; static COLON: number; static EQUALS: number; static COMMA: number; static UNDERSCORE: number; static PERIOD: number; static QUESTION_MARK: number; static TILDE: number; static OPEN_BRACKET: number; static BACKWARD_SLASH: number; static CLOSED_BRACKET: number; static QUOTES: number; static BACKSPACE: number; static TAB: number; static CLEAR: number; static ENTER: number; static SHIFT: number; static CONTROL: number; static ALT: number; static CAPS_LOCK: number; static ESC: number; static SPACEBAR: number; static PAGE_UP: number; static PAGE_DOWN: number; static END: number; static HOME: number; static LEFT: number; static UP: number; static RIGHT: number; static DOWN: number; static INSERT: number; static DELETE: number; static HELP: number; static NUM_LOCK: number; static PLUS: number; static MINUS: number; } /** * Creates a new Line object with a start and an end point. */ class Line { /** * Creates a new Line object with a start and an end point. * * @param x1 The x coordinate of the start of the line. * @param y1 The y coordinate of the start of the line. * @param x2 The x coordinate of the end of the line. * @param y2 The y coordinate of the end of the line. */ constructor(x1?: number, y1?: number, x2?: number, y2?: number); /** * Gets the angle of the line in radians. */ angle: number; /** * The end point of the line. */ end: Phaser.Point; /** * Gets the height of this bounds of this line. */ height: number; /** * Gets the left-most point of this line. */ left: number; /** * Gets the length of the line segment. */ length: number; /** * Gets the angle in radians of the normal of this line (line.angle - 90 degrees.) */ normalAngle: number; /** * Gets the x component of the left-hand normal of this line. */ normalX: number; /** * Gets the y component of the left-hand normal of this line. */ normalY: number; /** * Gets the perpendicular slope of the line (x/y). */ perpSlope: number; /** * Gets the right-most point of this line. */ right: number; /** * Gets the slope of the line (y/x). */ slope: number; /** * The start point of the line. */ start: Phaser.Point; /** * Gets the top-most point of this line. */ top: number; /** * The const type of this object. */ type: number; /** * Gets the width of this bounds of this line. */ width: number; /** * Gets the x coordinate of the top left of the bounds around this line. */ x: number; /** * Gets the y coordinate of the top left of the bounds around this line. */ y: number; /** * Finds the closest intersection between the Line and a Rectangle shape, or a rectangle-like * object, such as a Sprite or Body. * * @param line The line to check for intersection with. * @param rect The rectangle, or rectangle-like object, to check for intersection with. * @param result A Point object to store the result in. * @return - The intersection closest to the Line's start, or null if there is no intersection. */ static intersectionWithRectangle(line: Phaser.Line, rect: Phaser.Rectangle, result?: Phaser.Point): Phaser.Point; /** * Checks for intersection between two lines as defined by the given start and end points. * If asSegment is true it will check for line segment intersection. If asSegment is false it will check for line intersection. * Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. * Adapted from code by Keith Hair * * @param a The start of the first Line to be checked. * @param b The end of the first line to be checked. * @param e The start of the second Line to be checked. * @param f The end of the second line to be checked. * @param asSegment If true it will check for segment intersection, otherwise full line intersection. - Default: true * @param result A Point object to store the result in, if not given a new one will be created. * @return The intersection segment of the two lines as a Point, or null if there is no intersection. */ static intersectsPoints(a: Phaser.Point, b: Phaser.Point, e: Phaser.Point, f: Phaser.Point, asSegment?: boolean, result?: Phaser.Point): Phaser.Point; /** * Checks for intersection between this line and another Line. * If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection. * Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. * * @param line The line to check against this one. * @param asSegment If true it will check for segment intersection, otherwise full line intersection. - Default: true * @param result A Point object to store the result in, if not given a new one will be created. * @return The intersection segment of the two lines as a Point, or null if there is no intersection. */ static intersects(a: Phaser.Line, b: Phaser.Line, asSegment?: boolean, result?: Phaser.Point): Phaser.Point; /** * 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; or * The line segment intersects one of the 4 rectangle edges; and * The line has a non-zero length; and * The rectangle is not empty. * * For the purposes of this function rectangles are considered 'solid'. * * @param line The line to check for intersection with. * @param rect The rectangle, or rectangle-like object, to check for intersection with. * @return True if the line intersects with the rectangle edges, or starts or ends within the rectangle. */ static intersectsRectangle(line: Phaser.Line, rect: Phaser.Rectangle): boolean; /** * Returns the reflected angle between two lines. * This is the outgoing angle based on the angle of this line and the normalAngle of the given line. * * @param line The line to reflect off this line. * @return The reflected angle in radians. */ static reflect(a: Phaser.Line, b: Phaser.Line): number; /** * Centers this Line on the given coordinates. * * The line is centered by positioning the start and end points so that the lines midpoint matches * the coordinates given. * * @param x The x position to center the line on. * @param y The y position to center the line on. * @return This line object */ centerOn(x: number, y: number): Phaser.Line; /** * Returns a new Line object with the same values for the start and end properties as this Line object. * * @param output Optional Line object. If given the values will be set into the object, otherwise a brand new Line object will be created and returned. * @return The cloned Line object. */ clone(output?: Phaser.Line): Phaser.Line; /** * 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 stepRate How many steps will we return? 1 = every coordinate on the line, 2 = every other coordinate, etc. - Default: 1 * @param results The array to store the results in. If not provided a new one will be generated. * @return An array of coordinates. */ coordinatesOnLine(stepRate: number, results: any[]): any[]; /** * Sets this line to start at the given `x` and `y` coordinates and for the segment to extend at `angle` for the given `length`. * * @param x The x coordinate of the start of the line. * @param y The y coordinate of the start of the line. * @param angle The angle of the line in radians. * @param length The length of the line in pixels. * @return This line object */ fromAngle(x: number, y: number, angle: number, length: number): Phaser.Line; /** * Sets the line to match the x/y coordinates of the two given points. * * @param start A {@link Phaser.Point} or point-like object. * @param end A {@link Phaser.Point} or point-like object. * @return - This line object. */ fromPoints(start: any, end: any): Phaser.Line; /** * Sets the line to match the x/y coordinates of the two given sprites. * Can optionally be calculated from their center coordinates. * * @param startSprite The coordinates of this Sprite will be set to the Line.start point. * @param endSprite The coordinates of this Sprite will be set to the Line.start point. * @param useCenter If true it will use startSprite.centerX, if false startSprite.x. * @return This line object */ fromSprite(startSprite: Phaser.Sprite, endSprite: Phaser.Sprite, useCenter?: boolean): Phaser.Line; /** * Checks for intersection between this line and another Line. * If asSegment is true it will check for segment intersection. If asSegment is false it will check for line intersection. * Returns the intersection segment of AB and EF as a Point, or null if there is no intersection. * * @param line The line to check against this one. * @param asSegment If true it will check for segment intersection, otherwise full line intersection. - Default: true * @param result A Point object to store the result in, if not given a new one will be created. * @return The intersection segment of the two lines as a Point, or null if there is no intersection. */ intersects(line: Phaser.Line, asSegment?: boolean, result?: Phaser.Point): Phaser.Point; /** * Returns a Point object where the x and y values correspond to the center (or midpoint) of the Line segment. * * @param out A Phaser.Point object into which the result will be populated. If not given a new Point object is created. * @return A Phaser.Point object with the x and y values set to the center of the line segment. */ midPoint(out?: Phaser.Point): Phaser.Point; /** * Tests if the given coordinates fall on this line. See {@link Phaser.Line#pointOnSegment pointOnSegment} to test against just the line segment. * * @param x The line to check against this one. * @param y The line to check against this one. * @param epsilon Range for a fuzzy comparison, e.g., 0.0001. * @return True if the point is on the line, false if not. */ pointOnLine(x: number, y: number, epsilon?: number): boolean; /** * Tests if the given coordinates fall on this line and within the segment. See {@link Phaser.Line#pointOnLine pointOnLine} to test against just the line. * * @param x The line to check against this one. * @param y The line to check against this one. * @param epsilon Range for a fuzzy comparison, e.g., 0.0001. * @return True if the point is on the line and segment, false if not. */ pointOnSegment(x: number, y: number, epsilon?: number): boolean; /** * Picks a random point from anywhere on the Line segment and returns it. * * @param out A Phaser.Point, or any object with public x/y properties, that the values will be set in. * If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an object. * @return An object containing the random point in its `x` and `y` properties. */ random(out?: Phaser.Point): Phaser.Point; /** * Returns the reflected angle between two lines. * This is the outgoing angle based on the angle of this line and the normalAngle of the given line. * * @param line The line to reflect off this line. * @return The reflected angle in radians. */ reflect(line: Phaser.Line): number; /** * Rotates the line by the amount specified in `angle`. * * Rotation takes place from the center of the line. * If you wish to rotate around a different point see Line.rotateAround. * * If you wish to rotate the ends of the Line then see Line.start.rotate or Line.end.rotate. * * @param angle The angle in radians (unless asDegrees is true) to rotate the line by. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @return This line object */ rotate(angle: number, asDegrees?: boolean): Phaser.Line; /** * Rotates the line by the amount specified in `angle`. * * Rotation takes place around the coordinates given. * * @param x The x coordinate to offset the rotation from. * @param y The y coordinate to offset the rotation from. * @param angle The angle in radians (unless asDegrees is true) to rotate the line by. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @return This line object */ rotateAround(x: number, y: number, angle: number, asDegrees?: boolean): Phaser.Line; /** * Sets the components of the Line to the specified values. * * @param x1 The x coordinate of the start of the line. * @param y1 The y coordinate of the start of the line. * @param x2 The x coordinate of the end of the line. * @param y2 The y coordinate of the end of the line. * @return This line object */ setTo(x1?: number, y1?: number, x2?: number, y2?: number): Phaser.Line; } /** * A basic Linked List data structure. * * This implementation _modifies_ the `prev` and `next` properties of each item added: * - The `prev` and `next` properties must be writable and should not be used for any other purpose. * - Items _cannot_ be added to multiple LinkedLists at the same time. * - Only objects can be added. */ class LinkedList { /** * First element in the list. */ first: any; /** * Last element in the list. */ last: any; /** * Next element in the list. */ next: any; /** * Previous element in the list. */ prev: any; /** * Number of elements in the list. */ total: number; /** * Adds a new element to this linked list. * * @param item The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through. * @return The item that was added. */ add(item: any): any; /** * Calls a function on all members of this list, using the member as the context for the callback. * The function must exist on the member. * * @param callback The function to call. */ callAll(callback: Function): void; /** * Removes the given element from this linked list if it exists. * * @param item The item to be removed from the list. */ remove(item: any): void; /** * Resets the first, last, next and previous node pointers in this list. */ reset(): void; } /** * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. * * The loader uses a combination of tag loading (eg. Image elements) and XHR and provides progress and completion callbacks. * * Parallel loading (see {@link Phaser.Loader#enableParallel enableParallel}) is supported and enabled by default. * Load-before behavior of parallel resources is controlled by synchronization points as discussed in {@link Phaser.Loader#withSyncPoint withSyncPoint}. * * Texture Atlases can be created with tools such as [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) and * [Shoebox](http://renderhjs.net/shoebox/) */ class Loader { /** * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. * * The loader uses a combination of tag loading (eg. Image elements) and XHR and provides progress and completion callbacks. * * Parallel loading (see {@link Phaser.Loader#enableParallel enableParallel}) is supported and enabled by default. * Load-before behavior of parallel resources is controlled by synchronization points as discussed in {@link Phaser.Loader#withSyncPoint withSyncPoint}. * * Texture Atlases can be created with tools such as [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) and * [Shoebox](http://renderhjs.net/shoebox/) * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); static PHYSICS_LIME_CORONA_JSON: number; static PHYSICS_PHASER_JSON: number; static TEXTURE_ATLAS_JSON_ARRAY: number; static TEXTURE_ATLAS_JSON_HASH: number; static TEXTURE_ATLAS_XML_STARLING: number; static TEXTURE_ATLAS_JSON_PYXEL: number; /** * 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. * The string _must_ end with a "/". */ baseURL: string; /** * Local reference to the Phaser.Cache. */ cache: Phaser.Cache; /** * The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'. */ crossOrigin: boolean | string; /** * If true (the default) then parallel downloading will be enabled. * * To disable all parallel downloads this must be set to false prior to any resource being loaded. */ enableParallel: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * True if all assets in the queue have finished loading. */ hasLoaded: boolean; /** * Used to map the application mime-types to to the Accept header in XHR requests. * If you don't require these mappings, or they cause problems on your server, then * remove them from the headers object and the XHR request will not try to use them. * * This object can also be used to set the `X-Requested-With` header to * `XMLHttpRequest` (or any other value you need). To enable this do: * * ```javascript * this.load.headers.requestedWith = 'XMLHttpRequest' * ``` * * before adding anything to the Loader. The XHR loader will then call: * * ```javascript * setRequestHeader('X-Requested-With', this.headers['requestedWith']) * ``` * Default: {"requestedWith":false,"json":"application/json","xml":"application/xml"} */ headers: any; /** * True if the Loader is in the process of loading the queue. */ isLoading: boolean; /** * The number of concurrent / parallel resources to try and fetch at once. * * Many current browsers limit 6 requests per domain; this is slightly conservative. * * This should generally be left at the default, but can be set to a higher limit for specific use-cases. Just be careful when setting large values as different browsers could behave differently. */ maxParallelDownloads: number; /** * This event is dispatched when the final file in the load queue has either loaded or failed, * before {@link Phaser.Loader#onLoadComplete onLoadComplete} and before the loader is {@link Phaser.Loader#reset reset}. */ onBeforeLoadComplete: Phaser.Signal; /** * This event is dispatched immediately before a file starts loading. * It's possible the file may fail (eg. download error, invalid format) after this event is sent. * * Params: `(progress, file key, file url)` */ onFileStart: Phaser.Signal; /** * This event is dispatched when a file has either loaded or failed to load. * * Any function bound to this will receive the following parameters: * * progress, file key, success?, total loaded files, total files * * Where progress is a number between 1 and 100 (inclusive) representing the percentage of the load. */ onFileComplete: Phaser.Signal; /** * This event is dispatched when a file (or pack) errors as a result of the load request. * * For files it will be triggered before `onFileComplete`. For packs it will be triggered before `onPackComplete`. * * Params: `(file key, file)` */ onFileError: Phaser.Signal; /** * This event is dispatched when the final file in the load queue has either loaded or failed, * after the loader is {@link Phaser.Loader#reset reset}. */ onLoadComplete: Phaser.Signal; /** * This event is dispatched when the loading process starts: before the first file has been requested, * but after all the initial packs have been loaded. */ onLoadStart: Phaser.Signal; /** * This event is dispatched when an asset pack has either loaded or failed to load. * * This is called when the asset pack manifest file has loaded and successfully added its contents to the loader queue. * * Params: `(pack key, success?, total packs loaded, total packs)` */ onPackComplete: Phaser.Signal; /** * The value of `path`, if set, is placed before any _relative_ file path given. For example: * * ```javascript * load.path = "images/sprites/"; * load.image("ball", "ball.png"); * load.image("tree", "level1/oaktree.png"); * 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.) * * The string _must_ end with a "/". */ path: string; /** * You can optionally link a progress sprite with {@link Phaser.Loader#setPreloadSprite setPreloadSprite}. * * This property is an object containing: sprite, rect, direction, width and height */ preloadSprite: any; /** * The rounded load progress percentage value (from 0 to 100). See {@link Phaser.Loader#progressFloat}. */ progress: number; /** * The non-rounded load progress value (from 0.0 to 100.0). * * A general indicator of the progress. * It is possible for the progress to decrease, after `onLoadStart`, if more files are dynamically added. */ progressFloat: number; /** * If true all calls to Loader.reset will be ignored. Useful if you need to create a load queue before swapping to a preloader state. */ resetLocked: boolean; useXDomainRequest: boolean; /** * Informs the loader that the given file resource has been fetched and processed; * or such a request has failed. * * @param file * @param error The error message, if any. No message implies no error. - Default: '' */ asyncComplete(file: any, errorMessage?: string): void; /** * Add a synchronization point to a specific file/asset in the load queue. * * This has no effect on already loaded assets. * * @param type The type of resource to turn into a sync point (image, audio, xml, etc). * @param key Key of the file you want to turn into a sync point. * @return This Loader instance. */ addSyncPoint(type: string, key: string): Phaser.Loader; /** * Internal function that adds a new entry to the file list. Do not call directly. * * @param type The type of resource to add to the list (image, audio, xml, etc). * @param key The unique Cache ID key of this resource. * @param url The URL the asset will be loaded from. * @param properties Any additional properties needed to load the file. These are added directly to the added file object and overwrite any defaults. - Default: (none) * @param overwrite If true then this will overwrite a file asset of the same type/key. Otherwise it will only add a new asset. If overwrite is true, and the asset is already being loaded (or has been loaded), then it is appended instead. * @param extension If no URL is given the Loader will sometimes auto-generate the URL based on the key, using this as the extension. * @return This instance of the Phaser Loader. */ addToFileList(type: string, key: string, url?: string, properties?: any, overwrite?: boolean, extension?: string): Phaser.Loader; /** * Adds a Texture Atlas file to the current load queue. * * To create the Texture Atlas you can use tools such as: * * [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) * [Shoebox](http://renderhjs.net/shoebox/) * * If using Texture Packer we recommend you enable "Trim sprite names". * If your atlas software has an option to "rotate" the resulting frames, you must disable it. * * You can choose to either load the data externally, by providing a URL to a json file. * Or you can pass in a JSON object or String via the `atlasData` parameter. * If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache. * * If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed. * * The URLs can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the textureURL isn't specified then the Loader will take the key and create a filename from that. * For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png". * The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will * set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json". * * If you do not desire this action then provide URLs and / or a data object. * * @param key Unique asset key of the texture atlas file. * @param textureURL URL of the texture atlas image file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param atlasURL URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param atlasData A JSON or XML data object. You don't need this if the data is being loaded from a URL. * @param format The format of the data. Can be Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY (the default), Phaser.Loader.TEXTURE_ATLAS_JSON_HASH or Phaser.Loader.TEXTURE_ATLAS_XML_STARLING. * @return This Loader instance. */ atlas(key: string, textureURL?: string, atlasURL?: string, atlasData?: any, format?: number): Phaser.Loader; /** * Adds a Texture Atlas file to the current load queue. * * Unlike `Loader.atlasJSONHash` this call expects the atlas data to be in a JSON Array format. * * To create the Texture Atlas you can use tools such as: * * [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) * [Shoebox](http://renderhjs.net/shoebox/) * * If using Texture Packer we recommend you enable "Trim sprite names". * If your atlas software has an option to "rotate" the resulting frames, you must disable it. * * You can choose to either load the data externally, by providing a URL to a json file. * Or you can pass in a JSON object or String via the `atlasData` parameter. * If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache. * * If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed. * * The URLs can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the textureURL isn't specified then the Loader will take the key and create a filename from that. * For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png". * The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will * set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json". * * If you do not desire this action then provide URLs and / or a data object. * * @param key Unique asset key of the texture atlas file. * @param textureURL URL of the texture atlas image file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param atlasURL URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param atlasData A JSON data object. You don't need this if the data is being loaded from a URL. * @return This Loader instance. */ atlasJSONArray(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader; /** * Adds a Texture Atlas file to the current load queue. * * Unlike `Loader.atlas` this call expects the atlas data to be in a JSON Hash format. * * To create the Texture Atlas you can use tools such as: * * [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) * [Shoebox](http://renderhjs.net/shoebox/) * * If using Texture Packer we recommend you enable "Trim sprite names". * If your atlas software has an option to "rotate" the resulting frames, you must disable it. * * You can choose to either load the data externally, by providing a URL to a json file. * Or you can pass in a JSON object or String via the `atlasData` parameter. * If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache. * * If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getImage(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the JSON file as needed. * * The URLs can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the textureURL isn't specified then the Loader will take the key and create a filename from that. * For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png". * The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will * set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.json". * * If you do not desire this action then provide URLs and / or a data object. * * @param key Unique asset key of the texture atlas file. * @param textureURL URL of the texture atlas image file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param atlasURL URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param atlasData A JSON data object. You don't need this if the data is being loaded from a URL. * @return This Loader instance. */ atlasJSONHash(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader; /** * Adds a Texture Atlas file to the current load queue. * * This call expects the atlas data to be in the Starling XML data format. * * To create the Texture Atlas you can use tools such as: * * [Texture Packer](https://www.codeandweb.com/texturepacker/phaser) * [Shoebox](http://renderhjs.net/shoebox/) * * If using Texture Packer we recommend you enable "Trim sprite names". * If your atlas software has an option to "rotate" the resulting frames, you must disable it. * * You can choose to either load the data externally, by providing a URL to an xml file. * Or you can pass in an XML object or String via the `atlasData` parameter. * If you pass a String the data is automatically run through `Loader.parseXML` and then immediately added to the Phaser.Cache. * * If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getImage(key)`. XML files are automatically parsed upon load. * If you need to control when the XML is parsed then use `Loader.text` instead and parse the XML file as needed. * * The URLs can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the textureURL isn't specified then the Loader will take the key and create a filename from that. * For example if the key is "player" and textureURL is null then the Loader will set the URL to be "player.png". * The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will * set the atlasURL to be the key. For example if the key is "player" the atlasURL will be set to "player.xml". * * If you do not desire this action then provide URLs and / or a data object. * * @param key Unique asset key of the texture atlas file. * @param textureURL URL of the texture atlas image file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param atlasURL URL of the texture atlas data file. If undefined or `null` and no atlasData is given, the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.xml". * @param atlasData An XML data object. You don't need this if the data is being loaded from a URL. * @return This Loader instance. */ atlasXML(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader; /** * Adds an audio file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getSound(key)`. * * The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio. * When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system. * The solution is to use a lower encoding rate such as 44100 Hz. * * @param key Unique asset key of the audio file. * @param urls Either a single string or an array of URIs or pairs of `{uri: .., type: ..}`. * If an array is specified then the first URI (or URI + mime pair) that is device-compatible will be selected. * For example: `"jump.mp3"`, `['jump.mp3', 'jump.ogg', 'jump.m4a']`, or `[{uri: "data:", type: 'opus'}, 'fallback.mp3']`. * BLOB and DATA URIs can be used but only support automatic detection when used in the pair form; otherwise the format must be manually checked before adding the resource. * @param autoDecode When using Web Audio the audio files can either be decoded at load time or run-time. * Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially. - Default: true * @return This Loader instance. */ audio(key: string, urls: string | string[] | any, autoDecode?: boolean): Phaser.Loader; /** * A legacy alias for Loader.audioSprite. Please see that method for documentation. * * @param key Unique asset key of the audio file. * @param urls An array containing the URLs of the audio files, i.e.: [ 'audiosprite.mp3', 'audiosprite.ogg', 'audiosprite.m4a' ] or a single string containing just one URL. * @param jsonURL The URL of the audiosprite configuration JSON object. If you wish to pass the data directly set this parameter to null. * @param jsonData A JSON object or string containing the audiosprite configuration data. This is ignored if jsonURL is not null. * @param autoDecode When using Web Audio the audio files can either be decoded at load time or run-time. * Audio files can't be played until they are decoded and, if specified, this enables immediate decoding. Decoding is a non-blocking async process, however it consumes huge amounts of CPU time on mobiles especially. - Default: true * @return This Loader instance. */ audiosprite(key: string, urls: string[], jsonURL?: string, jsonData?: string | any, autoDecode?: boolean): Phaser.Loader; /** * Adds a binary file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getBinary(key)`. * * 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.bin". It will always add `.bin` as the extension. * If you do not desire this action then provide a URL. * * It will be loaded via xhr with a responseType of "arraybuffer". You can specify an optional callback to process the file after load. * When the callback is called it will be passed 2 parameters: the key of the file and the file data. * * WARNING: If a callback is specified the data will be set to whatever it returns. Always return the data object, even if you didn't modify it. * * @param key Unique asset key of the binary file. * @param url URL of the binary file. If undefined or `null` the url will be set to `.bin`, i.e. if `key` was "alien" then the URL will be "alien.bin". * @param callback Optional callback that will be passed the file after loading, so you can perform additional processing on it. - Default: (none) * @param callbackContext The context under which the callback will be applied. If not specified it will use the callback itself as the context. * @return This Loader instance. */ binary(key: string, url?: string, callback?: Function, callbackContext?: any): Phaser.Loader; /** * Adds Bitmap Font files to the current load queue. * * To create the Bitmap Font files you can use: * * 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/ * * You can choose to either load the data externally, by providing a URL to an xml file. * Or you can pass in an XML object or String via the `xmlData` parameter. * If you pass a String the data is automatically run through `Loader.parseXML` and then immediately added to the Phaser.Cache. * * If URLs are provided the files are **not** loaded immediately after calling this method, but are added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getBitmapFont(key)`. XML files are automatically parsed upon load. * If you need to control when the XML is parsed then use `Loader.text` instead and parse the XML file as needed. * * The URLs can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * If the textureURL isn't specified then the Loader will take the key and create a filename from that. * For example if the key is "megaFont" and textureURL is null then the Loader will set the URL to be "megaFont.png". * The same is true for the atlasURL. If atlasURL isn't specified and no atlasData has been provided then the Loader will * set the atlasURL to be the key. For example if the key is "megaFont" the atlasURL will be set to "megaFont.xml". * * If you do not desire this action then provide URLs and / or a data object. * * @param key Unique asset key of the bitmap font. * @param textureURL URL of the Bitmap Font texture file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "megaFont" then the URL will be "megaFont.png". * @param atlasURL URL of the Bitmap Font atlas file (xml/json). If undefined or `null` AND `atlasData` is null, the url will be set to `.xml`, i.e. if `key` was "megaFont" then the URL will be "megaFont.xml". * @param atlasData An optional Bitmap Font atlas in string form (stringified xml/json). * @param xSpacing If you'd like to add additional horizontal spacing between the characters then set the pixel value here. * @param ySpacing If you'd like to add additional vertical spacing between the lines then set the pixel value here. * @return This Loader instance. */ bitmapFont(key: string, textureURL?: string, atlasURL?: string, atlasData?: any, xSpacing?: number, ySpacing?: number): Phaser.Loader; /** * Check whether a file/asset with a specific key is queued to be loaded. * * To access a loaded asset use Phaser.Cache, eg. {@link Phaser.Cache#checkImageKey} * * @param type The type asset you want to check. * @param key Key of the asset you want to check. * @return Return true if exists, otherwise return false. */ checkKeyExists(type: string, key: string): boolean; /** * Successfully loaded a CSV file - only used for certain types. * * @param file File associated with this request * @param xhr */ csvLoadComplete(file: any, xhr: XMLHttpRequest): void; /** * Called when a file has been downloaded and needs to be processed further. * * @param file File loaded * @param xhr XHR request, unspecified if loaded via other means (eg. tags) */ fileComplete(file: any, xhr: XMLHttpRequest): void; /** * Error occurred when loading a file. * * @param file * @param xhr XHR request, unspecified if loaded via other means (eg. tags) * @param reason */ fileError(file: any, xhr: XMLHttpRequest, reason: string): void; /** * The loading is all finished. * * @param abnormal True if the loading finished abnormally. - Default: true */ finishedLoading(abnormal?: boolean): void; /** * Find a file/asset with a specific key. * * Only assets in the download file queue will be found. * * @param type The type asset you want to check. * @param key Key of the asset you want to check. * @return Returns an object if found that has 2 properties: `index` and `file`; otherwise a non-true value is returned. * The index may change and should only be used immediately following this call. */ getAsset(type: string, key: string): any; /** * Get the queue-index of the file/asset with a specific key. * * Only assets in the download file queue will be found. * * @param type The type asset you want to check. * @param key Key of the asset you want to check. * @return The index of this key in the filelist, or -1 if not found. * The index may change and should only be used immediately following this call */ getAssetIndex(type: string, key: string): number; /** * Give a bunch of URLs, return the first URL that has an extension this device thinks it can play. * * It is assumed that the device can play "blob:" or "data:" URIs - There is no mime-type checking on data URIs. * * @param urls See {@link #audio} for format. * @return The URL to try and fetch; or null. */ getAudioURL(urls: any[]): void; /** * Adds an Image to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * 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 Phaser.Cache upon successful load. * * Retrieve the image via `Cache.getImage(key)`. * * 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. * If you do not desire this action then provide a URL. * * ##### Compressed Textures * * This method also supports passing in a texture object as the `url` argument. This allows you to load * compressed textures into Phaser. You can also use `Loader.texture` to do this. * * Compressed Textures are a WebGL only feature, and require 3rd party tools to create. * Available tools include Texture Packer, PVRTexTool, DirectX Texture Tool and Mali Texture Compression Tool. * * Supported texture compression formats are: PVRTC, S3TC and ETC1. * Supported file formats are: PVR, DDS, KTX and PKM. * * The formats that support all 3 compression algorithms are PVR and KTX. * PKM only supports ETC1, and DDS only S3TC for now. * * The texture path object looks like this: * * ```javascript * load.image('factory', { * etc1: 'assets/factory_etc1.pkm', * s3tc: 'assets/factory_dxt1.pvr', * pvrtc: 'assets/factory_pvrtc.pvr', * truecolor: 'assets/factory.png' * }); * ``` * * The `truecolor` property points to a standard PNG file, that will be used if none of the * compressed formats are supported by the browser / GPU. * * ##### Multiple Image Sources * * You can pass an array `url` argument to load one of several alternative image sources. * The browser will choose its preferred source. You can also use `Loader.imageset` to do this. * * ```javascript * load.image('flower', [ * 'flower.avif', * 'flower.webp', * 'flower.png' * ]); * ``` * * You can also describe the media types explicitly: * * ```javascript * load.image('flower', [ * { url: 'flower.avif', type: 'image/avif' }, * { url: 'flower.webp', type: 'image/webp' }, * { url: 'flower.png', type: 'image/png' } * ]); * ``` * * @param key Unique asset key of this image file. * @param url URL of an image file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". Can also be a texture data object or a source array. * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ image(key: string, url?: string | any, overwrite?: boolean): Phaser.Loader; /** * Generate an image from a BitmapData object and add it to the current load queue. * * @param key Unique asset key for the generated image. * @param bitmapData * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ imageFromBitmapData(key: string, bitmapData: Phaser.BitmapData, overwrite?: boolean): Phaser.Loader; /** * Generate a grid image and add it to the current load queue. */ imageFromGrid(key: string, width: number, height: number, cellWidth: number, cellHeight: number, color?: string): Phaser.Loader; /** * Generate a texture image and add it to the current load queue. */ imageFromTexture(key: string, data: any, pixelWidth: number, pixelHeight: number, palette?: number): Phaser.Loader; /** * Adds an array of images to the current load queue. * * It works by passing each element of the array to the Loader.image method. * * The files are **not** loaded immediately after calling this method. The files are added to the queue ready to be loaded when the loader starts. * * Phaser can load all common image types: png, jpg, gif and any other format the browser can natively handle. * * The keys must be unique Strings. They are used to add the files to the Phaser.Cache upon successful load. * * Retrieve the images via `Cache.getImage(key)` * * 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. * If you do not desire this action then provide a URL. * * @param keys An array of unique asset keys of the image files. * @param urls Optional array of URLs. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". If provided the URLs array length must match the keys array length. * @return This Loader instance. */ images(keys: string[], urls?: string[]): Phaser.Loader; /** * Adds a JSON file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getJSON(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed. * * 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.json". It will always add `.json` as the extension. * If you do not desire this action then provide a URL. * * @param key Unique asset key of the json file. * @param url URL of the JSON file. If undefined or `null` the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ json(key: string, url?: string, overwrite?: boolean): Phaser.Loader; /** * Successfully loaded a JSON file - only used for certain types. * * @param file File associated with this request * @param xhr */ jsonLoadComplete(file: any, xhr: XMLHttpRequest): void; /** * Continue async loading through an Audio tag. */ loadAudioTag(file: any): void; /** * Start fetching a resource. * * All code paths, async or otherwise, from this function must return to `asyncComplete`. * * @param file */ loadFile(file: any): void; /** * Continue async loading through an Image tag. */ loadImageTag(file: any): void; /** * Add a JSON resource pack ('packfile') to the Loader. * * A packfile is a JSON file that contains a list of assets to the be loaded. * Please see the example 'loader/asset pack' in the Phaser Examples repository. * * Packs are always put before the first non-pack file that is not loaded / loading. * * This means that all packs added before any loading has started are added to the front * of the file queue, in the order added. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * The URL of the packfile can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it. * * @param key Unique asset key of this resource pack. * @param url URL of the Asset Pack JSON file. If you wish to pass a json object instead set this to null and pass the object as the data parameter. * @param data The Asset Pack JSON data. Use this to pass in a json data object rather than loading it from a URL. TODO * @param callbackContext Some Loader operations, like Binary and Script require a context for their callbacks. Pass the context here. - Default: (loader) * @return This Loader instance. */ pack(key: string, url?: string, data?: any, callbackContext?: any): Phaser.Loader; /** * Parses string data as XML. * * @param data The XML text to parse * @return Returns the xml document, or null if such could not parsed to a valid document. */ parseXml(data: string): XMLDocument; /** * Adds a physics data file to the current load queue. * * The data must be in `Lime + Corona` JSON format. [Physics Editor](https://www.codeandweb.com) by code'n'web exports in this format natively. * * You can choose to either load the data externally, by providing a URL to a json file. * Or you can pass in a JSON object or String via the `data` parameter. * If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache. * * If a URL is provided the file is **not** loaded immediately after calling this method, but is added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getJSON(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed. * * 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 and no data is given then the Loader will take the key and create a filename from that. * For example if the key is "alien" and no URL or data is given then the Loader will set the URL to be "alien.json". * It will always use `.json` as the extension. * * If you do not desire this action then provide a URL or data object. * * @param key Unique asset key of the physics json data. * @param url URL of the physics data file. If undefined or `null` and no data is given the url will be set to `.json`, i.e. if `key` was "alien" then the URL will be "alien.json". * @param data An optional JSON data object. If given then the url is ignored and this JSON object is used for physics data instead. * @param format The format of the physics data. - Default: Phaser.Physics.LIME_CORONA_JSON * @return This Loader instance. */ physics(key: string, url?: string, data?: any, format?: string): Phaser.Loader; /** * Process the next item(s) in the file/asset queue. * * Process the queue and start loading enough items to fill up the inflight queue. * * If a sync-file is encountered then subsequent asset processing is delayed until it completes. * The exception to this rule is that packfiles can be downloaded (but not processed) even if * there appear other sync files (ie. packs) - this enables multiple packfiles to be fetched in parallel. * such as during the start phaser. */ processLoadQueue(): void; /** * Process pack data. This will usually modify the file list. * * @param pack */ processPack(pack: any): void; /** * Remove all file loading requests - this is _insufficient_ to stop current loading. Use `reset` instead. */ removeAll(): void; /** * Remove a file/asset from the loading queue. * * A file that is loaded or has started loading cannot be removed. * * @param type The type of resource to add to the list (image, audio, xml, etc). * @param key Key of the file you want to remove. */ removeFile(type: string, key: string): void; /** * Internal function that replaces an existing entry in the file list with a new one. Do not call directly. * * @param type The type of resource to add to the list (image, audio, xml, etc). * @param key The unique Cache ID key of this resource. * @param url The URL the asset will be loaded from. * @param properties Any additional properties needed to load the file. */ replaceInFileList(type: string, key: string, url: string, properties: any): void; /** * Reset the loader and clear any queued assets. If `Loader.resetLocked` is true this operation will abort. * * This will abort any loading and clear any queued assets. * * Optionally you can clear any associated events. * * @param hard If true then the preload sprite and other artifacts may also be cleared. * @param clearEvents If true then the all Loader signals will have removeAll called on them. */ reset(hard?: boolean, clearEvents?: boolean): void; /** * Called automatically by ScaleManager when the game resizes in RESIZE scalemode. * * This can be used to adjust the preloading sprite size, eg. */ resize(): void; /** * Adds a JavaScript file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. * * 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. * If you do not desire this action then provide a URL. * * Upon successful load the JavaScript is automatically turned into a script tag and executed, so be careful what you load! * * A callback, which will be invoked as the script tag has been created, can also be specified. * The callback must return relevant `data`. * * @param key Unique asset key of the script file. * @param url URL of the JavaScript file. If undefined or `null` the url will be set to `.js`, i.e. if `key` was "alien" then the URL will be "alien.js". * @param callback Optional callback that will be called after the script tag has loaded, so you can perform additional processing. - Default: (none) * @param callbackContext The context under which the callback will be applied. If not specified it will use the Phaser Loader as the context. - Default: (loader) * @return This Loader instance. */ script(key: string, url?: String, callback?: Function, callbackContext?: any): Phaser.Loader; /** * Adds a fragment shader file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getShader(key)`. * * 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 "blur" * and no URL is given then the Loader will set the URL to be "blur.frag". It will always add `.frag` as the extension. * If you do not desire this action then provide a URL. * * @param key Unique asset key of the fragment file. * @param url URL of the fragment file. If undefined or `null` the url will be set to `.frag`, i.e. if `key` was "blur" then the URL will be "blur.frag". * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ shader(key: string, url?: String, overwrite?: boolean): Phaser.Loader; /** * Set a Sprite to be a "preload" sprite by passing it to this method. * * A "preload" sprite will have its width or height crop adjusted based on the percentage of the loader in real-time. * This allows you to easily make loading bars for games. * * The sprite will automatically be made visible when calling this. * * @param sprite The sprite or image that will be cropped during the load. * @param direction A value of zero means the sprite will be cropped horizontally, a value of 1 means its will be cropped vertically. */ setPreloadSprite(sprite: Phaser.Sprite | Phaser.Image, direction?: number): void; /** * Adds a Sprite Sheet to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * To clarify the terminology that Phaser uses: A Sprite Sheet is an image containing frames, usually of an animation, that are all equal * dimensions and often in sequence. For example if the frame size is 32x32 then every frame in the sprite sheet will be that size. * Sometimes (outside of Phaser) the term "sprite sheet" is used to refer to a texture atlas. * A Texture Atlas works by packing together images as best it can, using whatever frame sizes it likes, often with cropping and trimming * the frames in the process. Software such as Texture Packer, Flash CC or Shoebox all generate texture atlases, not sprite sheets. * If you've got an atlas then use `Loader.atlas` instead. * * The key must be a unique String. It is used to add the image to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getImage(key)`. Sprite sheets, being image based, live in the same Cache as all other Images. * * 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. * If you do not desire this action then provide a URL. * * An image with four frames, `margin = 1`, and `spacing = 2` looks like this: * * ``` * ........ * .# # . * . . * . . * .# # . * . . * . . * ........ * * . margin * spacing * # sprite frame * ``` * * `spacing` must be on only the right and bottom edges of each frame, including the last row and column. * * The first sprite frame is found at (margin) px from the left of the image. * The second sprite frame is found at (margin + frameWidth + spacing) px from the left of the image, and so on. * * @param key Unique asset key of the sheet file. * @param url URL of the sprite sheet file. If undefined or `null` the url will be set to `.png`, i.e. if `key` was "alien" then the URL will be "alien.png". * @param frameWidth Width in pixels of a single frame in the sprite sheet. * @param frameHeight Height in pixels of a single frame in the sprite sheet. * @param frameMax How many frames in this sprite sheet. If not specified it will divide the whole image into frames. - Default: -1 * @param margin The distance from the top-left of the image to the top-left of the first frame, if any. * @param spacing The distance from the right edge of a frame to the left edge of the next frame on the same row, from the right edge of the last frame of a row to the margin, from the bottom edge of a frame to the top edge of the next frame on the same column, and from the bottom edge of the last frame of a column to the margin. * @param skipFrames Skip a number of frames. Useful when there are multiple sprite sheets in one image. * @return This Loader instance. */ spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number, skipFrames?: number): Phaser.Loader; /** * Start loading the assets. Normally you don't need to call this yourself as the StateManager will do so. */ start(): void; /** * Adds a Text file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getText(key)` * * 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.txt". It will always add `.txt` as the extension. * If you do not desire this action then provide a URL. * * @param key Unique asset key of the text file. * @param url URL of the text file. If undefined or `null` the url will be set to `.txt`, i.e. if `key` was "alien" then the URL will be "alien.txt". * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ text(key: string, url?: string, overwrite?: boolean): Phaser.Loader; /** * Adds a Compressed Texture Image to the current load queue. * * Compressed Textures are a WebGL only feature, and require 3rd party tools to create. * Available tools include Texture Packer, PVRTexTool, DirectX Texture Tool and Mali Texture Compression Tool. * * Supported texture compression formats are: PVRTC, S3TC and ETC1. * Supported file formats are: PVR, DDS, KTX and PKM. * * The formats that support all 3 compression algorithms are PVR and KTX. * PKM only supports ETC1, and DDS only S3TC for now. * * The texture path object looks like this: * * ```javascript * load.texture('factory', { * etc1: 'assets/factory_etc1.pkm', * s3tc: 'assets/factory_dxt1.pvr', * pvrtc: 'assets/factory_pvrtc.pvr', * truecolor: 'assets/factory.png' * }); * ``` * * The `truecolor` property points to a standard PNG file, that will be used if none of the * compressed formats are supported by the browser / GPU. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the image via `Cache.getImage(key)` * * 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.pvr". It will always add `.pvr` as the extension. * If you do not desire this action then provide a URL. * * @param key Unique asset key of this image file. * @param object The texture path data object. * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ texture(key: string, object: any, overwrite?: boolean): Phaser.Loader; /** * Adds a Tile Map data file to the current load queue. * * Phaser can load data in two different formats: CSV and Tiled JSON. * * Tiled is a free software package, specifically for creating tilemaps, and is available from http://www.mapeditor.org * * You can choose to either load the data externally, by providing a URL to a json file. * Or you can pass in a JSON object or String via the `data` parameter. * If you pass a String the data is automatically run through `JSON.parse` and then immediately added to the Phaser.Cache. * * If a URL is provided the file is **not** loaded immediately after calling this method, but is added to the load queue. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getTilemapData(key)`. JSON files are automatically parsed upon load. * If you need to control when the JSON is parsed then use `Loader.text` instead and parse the text file as needed. * * 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 and no data is given then the Loader will take the key and create a filename from that. * For example if the key is "level1" and no URL or data is given then the Loader will set the URL to be "level1.json". * If you set the format to be Tilemap.CSV it will set the URL to be "level1.csv" instead. * * If you do not desire this action then provide a URL or data object. * * @param key Unique asset key of the tilemap data. * @param url URL of the tile map file. If undefined or `null` and no data is given the url will be set to `.json`, i.e. if `key` was "level1" then the URL will be "level1.json". * @param data An optional JSON data object. If given then the url is ignored and this JSON object is used for map data instead. * @param format The format of the map data. Either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON. - Default: Phaser.Tilemap.CSV * @return This Loader instance. */ tilemap(key: string, url?: string, data?: any, format?: number): Phaser.Loader; /** * Returns the number of files that have already been loaded, even if they errored. * @return The number of files that have already been loaded (even if they errored) */ totalLoadedFiles(): number; /** * Returns the number of asset packs that have already been loaded, even if they errored. * @return The number of asset packs that have already been loaded (even if they errored) */ totalLoadedPacks(): number; /** * Returns the number of files still waiting to be processed in the load queue. This value decreases as each file in the queue is loaded. * @return The number of files that still remain in the load queue. */ totalQueuedFiles(): number; /** * Returns the number of asset packs still waiting to be processed in the load queue. This value decreases as each pack in the queue is loaded. * @return The number of asset packs that still remain in the load queue. */ totalQueuedPacks(): number; /** * Transforms the asset URL. * * The default implementation prepends the baseURL if the url doesn't begin with http or // * * @param url The url to transform. * @param file The file object being transformed. * @return The transformed url. In rare cases where the url isn't specified it will return false instead. */ transformUrl(url: string, file?: any): string; /** * Update the loading sprite progress. */ updateProgress(): void; /** * Adds a video file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getVideo(key)`. * * 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 don't need to preload a video in order to play it in your game. See `Video.createVideoFromURL` for details. * * @param key Unique asset key of the video file. * @param urls Either a single string or an array of URIs or pairs of `{uri: .., type: ..}`. * If an array is specified then the first URI (or URI + mime pair) that is device-compatible will be selected. * For example: `"boom.mp4"`, `['boom.mp4', 'boom.ogg', 'boom.webm']`, or `[{uri: "data:", type: 'opus'}, 'fallback.mp4']`. * BLOB and DATA URIs can be used but only support automatic detection when used in the pair form; otherwise the format must be manually checked before adding the resource. * @param loadEvent This sets the Video source event to listen for before the load is considered complete. * 'canplaythrough' implies the video has downloaded enough, and bandwidth is high enough that it can be played to completion. * 'canplay' implies the video has downloaded enough to start playing, but not necessarily to finish. * 'loadeddata' just makes sure that the video meta data and first frame have downloaded. Phaser uses this value automatically if the * browser is detected as being Firefox and no `loadEvent` is given, otherwise it defaults to `canplaythrough`. - Default: 'canplaythrough' * @param asBlob Video files can either be loaded via the creation of a video element which has its src property set. * Or they can be loaded via xhr, stored as binary data in memory and then converted to a Blob. This isn't supported in IE9 or Android 2. * If you need to have the same video playing at different times across multiple Sprites then you need to load it as a Blob. * @return This Loader instance. */ video(key: string, urls: string | string[] | any, loadEvent?: string, asBlob?: boolean): Phaser.Loader; /** * Add a synchronization point to the assets / files added within the supplied callback. * * A synchronization point denotes that an asset _must_ be completely loaded before * subsequent assets can be loaded. An asset marked as a sync-point does not need to wait * for previous assets to load (unless they are sync-points). Resources, such as packs, may still * be downloaded around sync-points, as long as they do not finalize loading. * * @param callback The callback is invoked and is supplied with a single argument: the loader. * @param callbackContext Context for the callback. - Default: (loader) * @return This Loader instance. */ withSyncPoint(callback: Function, callbackContext?: any): Phaser.Loader; /** * Adds an XML file to the current load queue. * * The file is **not** loaded immediately after calling this method. The file is added to the queue ready to be loaded when the loader starts. * * The key must be a unique String. It is used to add the file to the Phaser.Cache upon successful load. * * Retrieve the file via `Cache.getXML(key)`. * * 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.xml". It will always add `.xml` as the extension. * If you do not desire this action then provide a URL. * * @param key Unique asset key of the xml file. * @param url URL of the XML file. If undefined or `null` the url will be set to `.xml`, i.e. if `key` was "alien" then the URL will be "alien.xml". * @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it. * @return This Loader instance. */ xml(key: string, url?: string, overwrite?: boolean): Phaser.Loader; /** * Starts the xhr loader. * * This is designed specifically to use with asset file processing. * * @param file The file/pack to load. * @param url The URL of the file. * @param type The xhr responseType. * @param onload The function to call on success. Invoked in `this` context and supplied with `(file, xhr)` arguments. * @param onerror The function to call on error. Invoked in `this` context and supplied with `(file, xhr)` arguments. - Default: fileError */ xhrLoad(file: any, url: string, type: string, onload: Function, onerror?: Function): void; /** * Successfully loaded an XML file - only used for certain types. * * @param file File associated with this request * @param xhr */ xmlLoadComplete(file: any, xhr: XMLHttpRequest): void; } /** * Phaser.LoaderParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into the Cache. */ class LoaderParser { /** * Alias for xmlBitmapFont, for backwards compatibility. * * @param xml XML data you want to parse. * @param baseTexture The BaseTexture this font uses. * @param xSpacing Additional horizontal spacing between the characters. * @param ySpacing Additional vertical spacing between the characters. * @param frame Optional Frame, if this font is embedded in a texture atlas. * @param resolution Optional game resolution to apply to the kerning data. - Default: 1 * @return The parsed Bitmap Font data. */ static bitmapFont(xml: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number, frame?: Phaser.Frame, resolution?: number): any; /** * Parse a Bitmap Font from an XML file. * * @param xml XML data you want to parse. * @param baseTexture The BaseTexture this font uses. * @param xSpacing Additional horizontal spacing between the characters. * @param ySpacing Additional vertical spacing between the characters. * @param frame Optional Frame, if this font is embedded in a texture atlas. * @param resolution Optional game resolution to apply to the kerning data. - Default: 1 * @return The parsed Bitmap Font data. */ static xmlBitmapFont(xml: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number, frame?: Phaser.Frame, resolution?: number): any; /** * Parse a Bitmap Font from a JSON file. * * @param json JSON data you want to parse. * @param baseTexture The BaseTexture this font uses. * @param xSpacing Additional horizontal spacing between the characters. * @param ySpacing Additional vertical spacing between the characters. * @param frame Optional Frame, if this font is embedded in a texture atlas. * @param resolution Optional game resolution to apply to the kerning data. - Default: 1 * @return The parsed Bitmap Font data. */ static jsonBitmapFont(json: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number, frame?: Phaser.Frame, resolution?: number): any; } /** * The Matrix is a 3x3 matrix mostly used for display transforms within the renderer. * * It is represented like so: * * | a | c | tx | * | b | d | ty | * | 0 | 0 | 1 | */ class Matrix { /** * * Default: 1 */ a: number; /** * * Default: 0 */ b: number; /** * * Default: 0 */ c: number; /** * * Default: 1 */ d: number; /** * * Default: 0 */ tx: number; /** * * Default: 0 */ ty: number; /** * The const type of this object. */ type: number; /** * The Matrix is a 3x3 matrix mostly used for display transforms within the renderer. * * It is represented like so: * * | a | c | tx | * | b | d | ty | * | 0 | 0 | 1 | * * @param a Horizontal scaling - Default: 1 * @param b Horizontal skewing * @param c Vertical skewing * @param d Vertical scaling - Default: 1 * @param tx Horizontal translation * @param ty Vertical translation */ constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number); /** * Get a new position with the current transformation applied. * * Can be used to go from a childs coordinate space to the world coordinate space (e.g. rendering) * * @param pos The origin Point. * @param newPos The point that the new position is assigned to. This can be same as input point. * @return The new point, transformed through this matrix. */ apply(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point; /** * Get a new position with the inverse of the current transformation applied. * * Can be used to go from the world coordinate space to a childs coordinate space. (e.g. input) * * @param pos The origin Point. * @param newPos The point that the new position is assigned to. This can be same as input point. * @return The new point, inverse transformed through this matrix. */ applyInverse(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point; /** * Creates a new Matrix object based on the values of this Matrix. * If you provide the output parameter the values of this Matrix will be copied over to it. * If the output parameter is blank a new Matrix object will be created. * * @param output If provided the values of this Matrix will be copied to it, otherwise a new Matrix object is created. * @return A clone of this Matrix. */ clone(output?: Phaser.Matrix): Phaser.Matrix; /** * Copies the properties from the given Matrix into this Matrix. * * @param matrix The Matrix to copy from. * @return This Matrix object. */ copyFrom(matrix: Phaser.Matrix): Phaser.Matrix; /** * Copies the properties from this Matrix to the given Matrix. * * @param matrix The Matrix to copy from. * @return The destination Matrix object. */ copyTo(matrix: Phaser.Matrix): Phaser.Matrix; /** * Sets the values of this Matrix to the values in the given array. * * The Array elements should be set as follows: * * a = array[0] * b = array[1] * c = array[3] * d = array[4] * tx = array[2] * ty = array[5] * * @param array The array to copy from. * @return This Matrix object. */ fromArray(array: number[]): Phaser.Matrix; /** * Sets the values of this Matrix to the given values. * * @param a Horizontal scaling * @param b Horizontal skewing * @param c Vertical skewing * @param d Vertical scaling * @param tx Horizontal translation * @param ty Vertical translation * @return This Matrix object. */ setTo(a: number, b: number, c: number, d: number, tx: number, ty: number): Phaser.Matrix; /** * Creates a Float32 Array with values populated from this Matrix object. * * @param transpose Whether the values in the array are transposed or not. * @param array If provided the values will be set into this array, otherwise a new Float32Array is created. * @return The newly created array which contains the matrix. */ toArray(transpose?: boolean, array?: number[]): number[]; /** * Translates the matrix on the x and y. * This is the same as Matrix.tx += x. * * @param x The x value to translate on. * @param y The y value to translate on. * @return This Matrix object. */ translate(x: number, y: number): Phaser.Matrix; /** * Applies a scale transformation to this matrix. * * @param x The amount to scale horizontally. * @param y The amount to scale vertically. * @return This Matrix object. */ scale(x: number, y: number): Phaser.Matrix; /** * Applies a rotation transformation to this matrix. * * @param angle The angle to rotate by, given in radians. * @return This Matrix object. */ rotate(angle: number): Phaser.Matrix; /** * Appends the given Matrix to this Matrix. * * @param matrix The matrix to append to this one. * @return This Matrix object. */ append(matrix: Phaser.Matrix): Phaser.Matrix; /** * Resets this Matrix to an identity (default) matrix. * @return This Matrix object. */ identity(): Phaser.Matrix; } /** * A collection of useful mathematical functions. * * These are normally accessed through `game.math`. */ class Math { /** * Find the angle of a segment from (x1, y1) -> (x2, y2). * * @param x1 The x coordinate of the first value. * @param y1 The y coordinate of the first value. * @param x2 The x coordinate of the second value. * @param y2 The y coordinate of the second value. * @return The angle, in radians. */ static angleBetween(x1: number, y1: number, x2: number, y2: number): number; /** * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). * * @param point1 The first point. * @param point2 The second point. * @return The angle between the two points, in radians. */ static angleBetweenPoints(point1: Phaser.Point, point2: Phaser.Point): number; /** * Find the angle of a segment from (x1, y1) -> (x2, y2). * * The difference between this method and Math.angleBetween is that this assumes the y coordinate travels * down the screen. * * @param x1 The x coordinate of the first value. * @param y1 The y coordinate of the first value. * @param x2 The x coordinate of the second value. * @param y2 The y coordinate of the second value. * @return The angle, in radians. */ static angleBetweenY(x1: number, y1: number, x2: number, y2: number): number; /** * Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y). * * @param point1 * @param point2 * @return The angle, in radians. */ static angleBetweenPointsY(point1: Phaser.Point, point2: Phaser.Point): number; /** * Averages all values passed to the function and returns the result. * @return The average of all given values. */ static average(...numbers: number[]): number; /** * * * @param n * @param i */ static bernstein(n: number, i: number): number; /** * Returns a random float in the range `[min, max)`. If these parameters are not in order than they will be put in order. * Default is 0 for `min` and 1 for `max`. * * @param min The minimum value. Must be a Number. * @param max The maximum value. Must be a Number. * @return A floating point number between min (inclusive) and max (exclusive). */ static random(min: number, max: number): number; /** * Returns a random integer in the range `[min, max]`. If these parameters are not in order than they will be put in order. * Default is 0 for `min` and 1 for `max`. * * @param min The minimum value. Must be a Number. * @param max The maximum value. Must be a Number. * @return An integer between min (inclusive) and max (inclusive). */ static between(min: number, max: number): number; /** * A Bezier Interpolation Method, mostly used by Phaser.Tween. * * @param v The input array of values to interpolate between. * @param k The percentage of interpolation, between 0 and 1. * @return The interpolated value */ static bezierInterpolation(v: number[], k: number): number; /** * Calculates a catmum rom value. * * @param p0 * @param p1 * @param p2 * @param p3 * @param t */ static catmullRom(p0: number, p1: number, p2: number, p3: number, t: number): number; /** * A Catmull Rom Interpolation Method, mostly used by Phaser.Tween. * * @param v The input array of values to interpolate between. * @param k The percentage of interpolation, between 0 and 1. * @return The interpolated value */ static catmullRomInterpolation(v: number[], k: 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. * @param base The base to round in. Default is 10 for decimal. - Default: 10 * @return The rounded value. */ static ceilTo(value: number, place?: number, base?: number): number; /** * Force a value within the boundaries by clamping it to the range `min`, `max`. * * @param v The value to be clamped. * @param min The minimum bounds. * @param max The maximum bounds. * @return The clamped value. */ static clamp(x: number, a: number, b: number): number; /** * Clamp `x` to the range `[a, Infinity)`. * Roughly the same as `Math.max(x, a)`, except for NaN handling. * * @param x * @param a */ static clampBottom(x: number, a: number): number; /** * Convert degrees to radians. * * @param degrees Angle in degrees. * @return Angle in radians. */ static degToRad(degrees: number): number; /** * The absolute difference between two values. * * @param a The first value to check. * @param b The second value to check. * @return The absolute difference between the two values. */ static difference(a: number, b: number): number; /** * Returns the euclidian distance between the two given set of coordinates. * * @param x1 * @param y1 * @param x2 * @param y2 * @return The distance between the two sets of coordinates. */ static distance(x1: number, y1: number, x2: number, y2: number): number; /** * Returns the euclidean distance squared between the two given set of * coordinates (cuts out a square root operation before returning). * * @param x1 * @param y1 * @param x2 * @param y2 * @return The distance squared between the two sets of coordinates. */ static distanceSq(x1: number, y1: number, x2: number, y2: number): number; /** * Returns the distance between the two given set of coordinates at the power given. * * @param x1 * @param y1 * @param x2 * @param y2 * @param pow - Default: 2 * @return The distance between the two sets of coordinates. */ static distancePow(xy: number, y1: number, x2: number, y2: number, pow?: number): number; /** * * * @param value the number you want to evaluate */ static factorial(value: 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. * @param base The base to round in. Default is 10 for decimal. - Default: 10 * @return The rounded value. */ static floorTo(value: number, place?: number, base?: number): number; /** * Applies a fuzzy ceil to the given value. * * @param val The value to ceil. * @param epsilon The epsilon (a small value used in the calculation) - Default: 0.0001 * @return ceiling(val-epsilon) */ static fuzzyCeil(val: number, epsilon?: number): number; /** * Two number are fuzzyEqual if their difference is less than epsilon. * * @param a The first number to compare. * @param b The second number to compare. * @param epsilon The epsilon (a small value used in the calculation) - Default: 0.0001 * @return True if |a-b|b+epsilon */ static fuzzyGreaterThan(a: number, b: number, epsilon?: number): boolean; /** * `a` is fuzzyLessThan `b` if it is less than b + epsilon. * * @param a The first number to compare. * @param b The second number to compare. * @param epsilon The epsilon (a small value used in the calculation) - Default: 0.0001 * @return True if a to range * * @param x The value to map * @param a1 First endpoint of the range * @param a2 Final endpoint of the range * @param b1 First endpoint of the range * @param b2 Final endpoint of the range */ static mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number; /** * Variation of Math.max that can be passed either an array of numbers or the numbers as parameters. * * Prefer the standard `Math.max` function when appropriate. * @return The largest value from those given. */ static max(...numbers: number[]): number; /** * Adds the given amount to the value, but never lets the value go over the specified maximum. * * @param value The value to add the amount to. * @param amount The amount to add to the value. * @param max The maximum the value is allowed to be. * @return The new value. */ static maxAdd(value: number, amount: number, max: number): number; /** * Variation of Math.max that can be passed a property and either an array of objects or the objects as parameters. * It will find the largest matching property value from the given objects. * @return The largest value from those given. */ static maxProperty(...numbers: number[]): number; /** * Variation of Math.min that can be passed either an array of numbers or the numbers as parameters. * * Prefer the standard `Math.min` function when appropriate. * @return The lowest value from those given. */ static min(...numbers: number[]): number; /** * Variation of Math.min that can be passed a property and either an array of objects or the objects as parameters. * It will find the lowest matching property value from the given objects. * @return The lowest value from those given. */ static minProperty(...numbers: number[]): number; /** * Subtracts the given amount from the value, but never lets the value go below the specified minimum. * * @param value The base value. * @param amount The amount to subtract from the base value. * @param min The minimum the value is allowed to be. * @return The new value. */ static minSub(value: number, amount: number, min: number): number; /** * Normalizes an angle to the [0,2pi) range. * * @param angleRad The angle to normalize, in radians. * @return The angle, fit within the [0,2pi] range, in radians. */ static normalizeAngle(angle: number, radians?: boolean): number; /** * Work out what percentage value `a` is of value `b` using the given base. * * @param a The value to work out the percentage for. * @param b The value you wish to get the percentage of. * @param base The base value. * @return The percentage a is of b, between 0 and 1. */ static percent(a: number, b: number, base?: number): number; static p2px(v: number): number; /** * Twice PI. * Default: ~6.283 */ static PI2: number; /** * Convert radians to degrees. * * @param radians Angle in radians. * @return Angle in degrees */ static radToDeg(radians: number): number; /** * Reverses an angle. * * @param angleRad The angle to reverse, in radians. * @return The reverse angle, in radians. */ static reverseAngle(angleRed: 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 * @return The adjusted angle. */ static rotateToAngle(currentAngle: number, targetAngle: number, lerp?: number): number; /** * Round to the next whole number _away_ from zero. * * @param value Any number. * @return The rounded value of that number. */ static roundAwayFromZero(value: number): number; /** * Round 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. * * e.g. 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011 * * roundTo(2000/7,3) === 0 * roundTo(2000/7,2) == 300 * roundTo(2000/7,1) == 290 * roundTo(2000/7,0) == 286 * roundTo(2000/7,-1) == 285.7 * roundTo(2000/7,-2) == 285.71 * roundTo(2000/7,-3) == 285.714 * roundTo(2000/7,-4) == 285.7143 * roundTo(2000/7,-5) == 285.71429 * * roundTo(2000/7,3,2) == 288 -- 100100000 * roundTo(2000/7,2,2) == 284 -- 100011100 * roundTo(2000/7,1,2) == 286 -- 100011110 * roundTo(2000/7,0,2) == 286 -- 100011110 * roundTo(2000/7,-1,2) == 285.5 -- 100011101.1 * roundTo(2000/7,-2,2) == 285.75 -- 100011101.11 * roundTo(2000/7,-3,2) == 285.75 -- 100011101.11 * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011 * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111 * * Note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed * because we are rounding 100011.1011011011011011 which rounds up. * * @param value The value to round. * @param place The place to round to. * @param base The base to round in. Default is 10 for decimal. - Default: 10 * @return The rounded value. */ static roundTo(value: number, place?: number, base?: number): number; /** * * * @param n * @return n mod 1 */ static shear(n: number): number; /** * A value representing the sign of the value: -1 for negative, +1 for positive, 0 if value is 0. * * This works differently from `Math.sign` for values of NaN and -0, etc. * * @param x * @return An integer in {-1, 0, 1} */ static sign(x: number): number; /** * Generate a sine and cosine table simultaneously and extremely quickly. * The parameters allow you to specify the length, amplitude and frequency of the wave. * This generator is fast enough to be used in real-time. * Code based on research by Franky of scene.at * * @param length The length of the wave * @param sinAmplitude The amplitude to apply to the sine table (default 1.0) if you need values between say -+ 125 then give 125 as the value * @param cosAmplitude The amplitude to apply to the cosine table (default 1.0) if you need values between say -+ 125 then give 125 as the value * @param frequency The frequency of the sine and cosine table data * @return Returns the table data. */ static sinCosGenerator(length: number, sinAmplitude?: number, cosAmplitude?: number, frequency?: number): { sin: number[]; cos: number[]; }; /** * Returns the length of the hypotenuse connecting two segments of given lengths. * * @param a * @param b * @return The length of the hypotenuse connecting the given lengths. */ static hypot(a: number, b: number): number; /** * Smootherstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep * * @param x The input value. * @param min The left edge. Should be smaller than the right edge. * @param max The right edge. * @return A value between 0 and 1. */ static smootherstep(x: number, min: number, max: number): number; /** * Smoothstep function as detailed at http://en.wikipedia.org/wiki/Smoothstep * * @param x The input value. * @param min The left edge. Should be smaller than the right edge. * @param max The right edge. * @return A value between 0 and 1. */ static smoothstep(x: number, min: number, max: number): number; /** * Snap a value to nearest grid slice, using rounding. * * 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 input The value to snap. * @param gap The interval gap of the grid. * @param start Optional starting offset for gap. * @return The snapped value. */ static snapTo(input: number, gap: number, start?: number): number; /** * 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 will snap to 15... but 16 will snap to 20. * * @param input The value to snap. * @param gap The interval gap of the grid. * @param start Optional starting offset for gap. * @return The snapped value. */ static snapToCeil(input: number, gap: number, start?: number): number; /** * 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 input The value to snap. * @param gap The interval gap of the grid. * @param start Optional starting offset for gap. * @return The snapped value. */ static snapToFloor(input: number, gap: number, start?: number): number; /** * Checks if two values are within the given tolerance of each other. * * @param a The first number to check * @param b The second number to check * @param tolerance The tolerance. Anything equal to or less than this is considered within the range. * @return True if a is <= tolerance of b. */ static within(a: number, b: number, tolerance: number): boolean; /** * Ensures that the value always stays between min and max, by wrapping the value around. * * If `max` is not larger than `min` the result is 0. * * @param value The value to wrap. * @param min The minimum the value is allowed to be. * @param max The maximum the value is allowed to be, should be larger than `min`. * @return The wrapped value. */ static wrap(value: number, min: number, max: number): number; /** * Keeps an angle value between -180 and +180; or -PI and PI if radians. * * @param angle The angle value to wrap * @param radians Set to `true` if the angle is given in radians, otherwise degrees is expected. * @return The new angle value; will be the same as the input angle if it was within bounds. */ static wrapAngle(angle: number, radians?: boolean): number; /** * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. * * Values _must_ be positive integers, and are passed through Math.abs. See {@link Phaser.Math#wrap} for an alternative. * * @param value The value to add the amount to. * @param amount The amount to add to the value. * @param max The maximum the value is allowed to be. * @return The wrapped value. */ static wrapValue(value: number, amount: number, max: number): number; } interface WheelEventProxy { bindEvent(event: any): WheelEventProxy; type: string; deltaMode: number; deltaX: number; deltaY: number; deltaZ: number; } /** * The Mouse class is responsible for handling all aspects of mouse interaction with the browser. * * It captures and processes mouse events that happen on the game canvas object. * It also adds a single `mouseup` listener to `window` which is used to capture the mouse being released * when not over the game. * * You should not normally access this class directly, but instead use a Phaser.Pointer object * which normalises all game input for you, including accurate button handling. */ class Mouse { /** * The Mouse class is responsible for handling all aspects of mouse interaction with the browser. * * It captures and processes mouse events that happen on the game canvas object. * It also adds a single `mouseup` listener to `window` which is used to capture the mouse being released * when not over the game. * * You should not normally access this class directly, but instead use a Phaser.Pointer object * which normalises all game input for you, including accurate button handling. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); static NO_BUTTON: number; static LEFT_BUTTON: number; static MIDDLE_BUTTON: number; static RIGHT_BUTTON: number; static BACK_BUTTON: number; static FORWARD_BUTTON: number; static WHEEL_DOWN: number; static WHEEL_UP: number; button: number; /** * The context under which callbacks are called. */ callbackContext: any; /** * If true the DOM mouse events will have event.preventDefault applied to them. */ capture: boolean; /** * Whether the handler has started. */ active: boolean; /** * Whether mouse input is passed to the Input Manager and Mouse Pointer. * When enabled is false, `game.input` and `game.input.mousePointer` are not updated by this handler. * The handler is still running and will call any added callbacks and apply {@link Phaser.Mouse#capture}. * Default: true */ enabled: boolean; /** * The browser mouse DOM event. Will be null if no mouse event has ever been received. * Access this property only inside a Mouse event handler and do not keep references to it. */ event: MouseEvent; /** * A reference to the currently running game. */ game: Phaser.Game; /** * A reference to the Phaser Input Manager. */ input: Phaser.Input; locked: boolean; /** * A callback that can be fired when the mouse is pressed down. * You should set {@link Phaser.Input.MSPointer#pointerDownCallback} as well. */ mouseDownCallback: (event: MouseEvent) => void; /** * A callback that can be fired when the mouse is no longer over the game canvas. * You should set {@link Phaser.Input.MSPointer#pointerOutCallback} as well. */ mouseOutCallback: (event: MouseEvent) => void; /** * A callback that can be fired when the mouse enters the game canvas (usually after a mouseout). * You should set {@link Phaser.Input.MSPointer#pointerOverCallback} as well. */ mouseOverCallback: (event: MouseEvent) => void; /** * A callback that can be fired when the mouse is released from a pressed down state. * You should set {@link Phaser.Input.MSPointer#pointerUpCallback} as well. */ mouseUpCallback: (event: MouseEvent) => void; mouseWheelCallback: (event: MouseEvent) => void; /** * Internal event handler reference. */ _onMouseDown: (event: MouseEvent) => void; /** * Internal event handler reference. */ _onMouseMove: (event: MouseEvent) => void; /** * Internal event handler reference. */ _onMouseUp: (event: MouseEvent) => void; /** * Internal event handler reference. */ _onMouseOut: (event: MouseEvent) => void; /** * Internal event handler reference. */ _onMouseOver: (event: MouseEvent) => void; _onMouseWheel: (event: MouseEvent) => void; _wheelEvent: WheelEventProxy; pointerLock: Phaser.Signal; /** * If true Pointer.stop will be called if the mouse leaves the game canvas. * You should set {@link Phaser.Input.MSPointer#stopOnGameOut} as well. */ stopOnGameOut: boolean; wheelDelta: number; /** * The internal method that handles the mouse down event from the browser. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseDown(event: MouseEvent): void; /** * The internal method that handles the mouse move event from the browser. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseMove(event: MouseEvent): void; /** * The internal method that handles the mouse out event from the browser. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseOut(event: MouseEvent): void; /** * The internal method that handles the mouse over event from the browser. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseOver(event: MouseEvent): void; /** * The internal method that handles the mouse up event from the browser. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseUp(event: MouseEvent): void; /** * The internal method that handles the mouse up event from the window. * * @param event The native event from the browser. This gets stored in Mouse.event. */ onMouseUpGlobal(event: MouseEvent): void; onMouseWheel(event: MouseEvent): void; pointerLockChange(event: MouseEvent): void; releasePointerLock(): void; requestPointerLock(): void; /** * Starts the event listeners running. * @return - Whether the handler was started. */ start(): boolean; /** * Stop the event listeners. */ stop(): void; } /** * The mouse wheel input handler. */ class MouseWheel { static UP: number; static DOWN: number; /** * The currently running game. */ game: Phaser.Game; /** * The Input Manager. */ input: Phaser.Input; /** * The element where event listeners are added (the game canvas). */ element: HTMLElement; /** * Whether the default mouse wheel actions (usually zoom or pan) are cancelled. * Default: true */ preventDefault: boolean /** * Whether the handler is active. */ active: boolean; /** * A callback to call for each wheel event. * It receives an `event` parameter. */ callback: (event: WheelEvent) => void; /** * The context for {@link Phaser.MouseWheel#callback}. * The default is {@link Phaser.MouseWheel#game}. */ callbackContext: any; /** * The direction of the last wheel event. * Between -1 (down) and 1 (up). */ delta: number; /** * Activates the handler, unless unsupported or already activate. * @return - True if the handler was started, otherwise false. */ start(): boolean; /** * Deactivates the handler. */ stop(): void; } /** * The MSPointer class handles pointer interactions with the game via the {@link https://developers.google.com/web/updates/2016/10/pointer-events Pointer Events API}. (It's named after the nonstandard {@link https://msdn.microsoft.com/library/hh673557(v=vs.85).aspx MSPointerEvent}, ancestor of the current API.) * * It's {@link http://caniuse.com/#feat=pointer currently supported in IE 10+, Edge, Chrome (including Android), and Opera}. * * You should not normally access this class directly, but instead use a {@link Phaser.Pointer} object which * normalises all game input for you including accurate button handling. * * Phaser does not yet support {@link http://www.w3.org/TR/pointerevents/#chorded-button-interactions chorded button interactions}. * * You can disable Phaser's use of Pointer Events: * * ```javascript * new Phaser.Game({ mspointer: false }); * ``` */ class MSPointer { /** * The MSPointer class handles pointer interactions with the game via the {@link https://developers.google.com/web/updates/2016/10/pointer-events Pointer Events API}. (It's named after the nonstandard {@link https://msdn.microsoft.com/library/hh673557(v=vs.85).aspx MSPointerEvent}, ancestor of the current API.) * * It's {@link http://caniuse.com/#feat=pointer currently supported in IE 10+, Edge, Chrome (including Android), and Opera}. * * You should not normally access this class directly, but instead use a {@link Phaser.Pointer} object which * normalises all game input for you including accurate button handling. * * Phaser does not yet support {@link http://www.w3.org/TR/pointerevents/#chorded-button-interactions chorded button interactions}. * * You can disable Phaser's use of Pointer Events: * * ```javascript * new Phaser.Game({ mspointer: false }); * ``` * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); button: number; /** * If true the PointerEvent will call preventDefault(), canceling the corresponding MouseEvent or * TouchEvent. * * If the {@link Phaser.Mouse Mouse} handler is active as well, you should set this to true to avoid * duplicate events. * * "Mouse events can only be prevented when the pointer is down. Hovering pointers (e.g. a mouse with * no buttons pressed) cannot have their mouse events prevented. And, the `mouseover` and `mouseout` * events are never prevented (even if the pointer is down)." */ capture: boolean; /** * Whether the input handler is active. */ active: boolean; /** * PointerEvent input will only be processed if enabled. * Default: true */ enabled: boolean; /** * The context under which callbacks are called (defaults to game). */ callbackContext: any; /** * The most recent PointerEvent from the browser. Will be null if no event has ever been received. * Access this property only inside a Pointer event handler and do not keep references to it. */ event: MSPointerEvent; /** * A reference to the currently running game. */ game: Phaser.Game; /** * A reference to the Phaser Input Manager. */ input: Phaser.Input; onPointerDown: (event: MSPointerEvent) => void; onPointerMove: (event: MSPointerEvent) => void; onPointerUp: (event: MSPointerEvent) => void; mouseDownCallback: (event: MSPointerEvent) => void; mouseMoveCallback: (event: MSPointerEvent) => void; mouseUpCallback: (event: MSPointerEvent) => void; /** * A callback that can be fired on a pointerdown event. */ pointerDownCallback: (event: MSPointerEvent) => void; /** * A callback that can be fired on a pointermove event. */ pointerMoveCallback: (event: MSPointerEvent) => void; /** * A callback that can be fired on a pointerup event. */ pointerUpCallback: (event: MSPointerEvent) => void; /** * Starts the event listeners running. */ start(): boolean; /** * Stop the event listeners. */ stop(): void; } /** * Create a new `Particle` object. Particles are extended Sprites that are emitted by a particle emitter such as Phaser.Particles.Arcade.Emitter. */ class Particle extends Phaser.Sprite { /** * Create a new `Particle` object. Particles are extended Sprites that are emitted by a particle emitter such as Phaser.Particles.Arcade.Emitter. * * @param game A reference to the currently running game. * @param x The x coordinate (in world space) to position the Particle at. * @param y The y coordinate (in world space) to position the Particle at. * @param key This is the image or texture used by the Particle during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If this Particle is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ constructor(game: Phaser.Game, x: number, y: number, key?: any, frame?: any); /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * Called by the Emitter when this particle is emitted. Left empty for you to over-ride as required. */ onEmit(): void; /** * Resets the Particle. This places the Particle at the given x/y world coordinates and then * sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values. * If the Particle has a physics body that too is reset. * * @param x The x coordinate (in world space) to position the Particle at. * @param y The y coordinate (in world space) to position the Particle at. * @param health The health to give the Particle. - Default: 1 * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.Particle; /** * Called by the Emitter if autoAlpha has been enabled. Passes over the alpha ease data and resets the alpha counter. */ setAlphaData(data: any[]): void; /** * Called by the Emitter if autoScale has been enabled. Passes over the scale ease data and resets the scale counter. */ setScaleData(data: any[]): void; /** * Updates the Particle scale or alpha if autoScale and autoAlpha are set. */ update(): void; } /** * Phaser.Particles tracks any Emitters attached to it. */ class Particles { /** * Phaser.Particles tracks any Emitters attached to it. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * Internal emitters store. */ emitters: any; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * - */ ID: number; /** * Adds a new Particle Emitter to the Particle Manager. * * @param emitter The emitter to be added to the particle manager. * @return The emitter that was added. */ add(emitter: Phaser.Particles.Arcade.Emitter): Phaser.Particles.Arcade.Emitter; /** * Removes an existing Particle Emitter from the Particle Manager. * * @param emitter The emitter to remove. */ remove(emitter: Phaser.Particles.Arcade.Emitter): void; update(): void; } module Particles { module Arcade { interface EmitterCount { emitted: number; failed: number; totalEmitted: number; totalFailed: number; } /** * Emitter is a lightweight particle emitter that uses Arcade Physics. * It can be used for one-time explosions or for continuous effects like rain and fire. * All it really does is launch Particle objects out at set intervals, and fixes their positions and velocities accordingly. */ class Emitter extends Phaser.Group { /** * Emitter is a lightweight particle emitter that uses Arcade Physics. * It can be used for one-time explosions or for continuous effects like rain and fire. * All it really does is launch Particle objects out at set intervals, and fixes their positions and velocities accordingly. * * @param game Current game instance. * @param x The x coordinate within the Emitter that the particles are emitted from. * @param y The y coordinate within the Emitter that the particles are emitted from. * @param maxParticles The total number of particles in this emitter. - Default: 50 */ constructor(game: Phaser.Game, x?: number, y?: number, maxParticles?: number); /** * The {@link #setSize size} of the emitter's emit area. The **actual** emit area is a rectangle of this size centered on (emitX, emitY): `{x: this.left, y: this.top, width: this.area.width, height: this.area.height}`. Particles are generated at a random position within this area. */ area: Phaser.Rectangle; /** * An array of the calculated alpha easing data applied to particles with alphaRates > 0. */ alphaData: any[]; /** * When a new Particle is emitted this controls if it will automatically change alpha. Use Emitter.setAlpha to configure. */ autoAlpha: boolean; /** * When a new Particle is emitted this controls if it will automatically scale in size. Use Emitter.setScale to configure. */ autoScale: boolean; /** * The angle of rotation of the group container, in degrees. * * This adjusts the group itself by modifying its local rotation transform. * * This has no impact on the rotation/angle properties of the children, but it will update their worldTransform * and on-screen orientation and position. */ angle: number; /** * The angular drag component of particles launched from the emitter if they are rotating. */ angularDrag: number; /** * The blendMode as set on the particle when emitted from the Emitter. Defaults to NORMAL. Needs browser capable of supporting canvas blend-modes (most not available in WebGL) */ blendMode: Phaser.blendModes; /** * Gets the bottom position of the Emitter. */ bottom: number; /** * How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce. */ bounce: Phaser.Point; counts: EmitterCount; /** * The point the particles are emitted from. * Emitter.x and Emitter.y control the containers location, which updates all current particles * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position. */ emitX: number; /** * The point the particles are emitted from. * Emitter.x and Emitter.y control the containers location, which updates all current particles * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position. */ emitY: number; /** * If exists is false the group will be excluded from collision checks and filters such as {@link Phaser.Group#forEachExists forEachExists}. The group will not call `preUpdate` and `postUpdate` on its children and the children will not receive physics updates or camera/world boundary checks. The group will still be {@link Phaser.Group#visible visible} and will still call `update` on its children (unless {@link Phaser.Group#updateOnlyExistingChildren updateOnlyExistingChildren} is true). * Default: true */ exists: boolean; /** * How often a particle is emitted in ms (if emitter is started with Explode === false). * Default: 100 */ frequency: number; /** * Sets the `body.gravity` of each particle sprite to this on launch. */ gravity: Phaser.Point; group: Phaser.Group; /** * Gets or sets the height of the Emitter. This is the region in which a particle can be emitted. */ height: number; /** * Gets the left position of the Emitter. */ left: number; /** * How long each particle lives once it is emitted in ms. Default is 2 seconds. Set lifespan to 'zero' for particles to live forever. * Default: 2000 */ lifespan: number; /** * The number of particles released during one particle's {@link Phaser.Particles.Arcade.Emitter#lifespan lifespan}, after calling {@link Phaser.Particles.Arcade.Emitter#flow flow}. */ lifespanOutput: number; /** * The maximum angle of initial particle velocities, in degrees. When set to a non-null value (with {@link Phaser.Particles.Arcade.Emitter#minAngle minAngle}), {@link Phaser.Particles.Arcade.Emitter#minSpeed minSpeed} and {@link Phaser.Particles.Arcade.Emitter#maxSpeed maxSpeed} are used and {@link Phaser.Particles.Arcade.Emitter#minParticleSpeed minParticleSpeed} and {@link Phaser.Particles.Arcade.Emitter#maxParticleSpeed maxParticleSpeed} are ignored. */ maxAngle: number; /** * The total number of particles in this emitter. */ maxParticles: number; /** * The maximum possible scale of a particle. This is applied to the X and Y axis. If you need to control each axis see maxParticleScaleX. * Default: 1 */ maxParticleScale: number; /** * The maximum possible velocity of a particle. */ maxParticleSpeed: Phaser.Point; /** * The maximum possible angular velocity of a particle. * Default: 360 */ maxRotation: number; /** * The maximum initial speed of particles released within {@link Phaser.Particles.Arcade.Emitter#minAngle minAngle} and {@link Phaser.Particles.Arcade.Emitter#maxAngle maxAngle}. * Default: 100 */ maxSpeed: number; /** * The minimum angle of initial particle velocities, in degrees. When set to a non-null value (with {@link Phaser.Particles.Arcade.Emitter#maxAngle maxAngle}), {@link Phaser.Particles.Arcade.Emitter#minSpeed minSpeed} and {@link Phaser.Particles.Arcade.Emitter#maxSpeed maxSpeed} are used and {@link Phaser.Particles.Arcade.Emitter#minParticleSpeed minParticleSpeed} and {@link Phaser.Particles.Arcade.Emitter#maxParticleSpeed maxParticleSpeed} are ignored. */ minAngle: number; /** * The minimum possible scale of a particle. This is applied to the X and Y axis. If you need to control each axis see minParticleScaleX. * Default: 1 */ minParticleScale: number; /** * The minimum possible velocity of a particle. */ minParticleSpeed: Phaser.Point; /** * The minimum possible angular velocity of a particle. */ minRotation: number; /** * The minimum initial speed of particles released within {@link Phaser.Particles.Arcade.Emitter#minAngle minAngle} and {@link Phaser.Particles.Arcade.Emitter#maxAngle maxAngle}. */ minSpeed: number; /** * A handy string name for this emitter. Can be set to anything. */ name: string; /** * Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this. */ on: boolean; /** * The number of particles released per second, after calling {@link Phaser.Particles.Arcade.Emitter#flow flow}. */ output: number; /** * When a particle is created its anchor will be set to match this Point object (defaults to x/y: 0.5 to aid in rotation) */ particleAnchor: Phaser.Point; /** * If this is `true` then when the Particle is emitted it will be bought to the top of the Emitters display list. */ particleBringToTop: boolean; /** * If this is `true` then when the Particle is emitted it will be sent to the back of the Emitters display list. */ particleSendToBack: boolean; /** * For emitting your own particle class types. They must extend Phaser.Particle. */ particleClass: any; /** * The X and Y drag component of particles launched from the emitter. */ particleDrag: Phaser.Point; /** * The const physics body type of this object. */ physicsType: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The expected number of unreleased particles after a flow interval of {@link Phaser.Particles.Arcade.Emitter#lifespan lifespan}, after calling {@link Phaser.Particles.Arcade.Emitter#flow flow}. */ remainder: number; /** * Gets the right position of the Emitter. */ right: number; /** * An array of the calculated scale easing data applied to particles with scaleRates > 0. */ scaleData: any[]; /** * Gets the top position of the Emitter. */ top: number; /** * Internal Phaser Type value. */ type: number; /** * Gets or sets the width of the Emitter. This is the region in which a particle can be emitted. */ width: number; /** * Gets or sets the x position of the Emitter. */ x: number; /** * Gets or sets the y position of the Emitter. */ y: number; /** * Change the emitter's center to match the center of any object with a `center` property, such as an Arcade Body. * If the object doesn't have a `center` property it will be set to the object's anchor-adjusted world position (`object.world`). * * @param object The object that you wish to match the center with. * @return This Emitter instance. */ at(object: any): Phaser.Particles.Arcade.Emitter; /** * This function is used internally to emit the next particle in the queue. * * However it can also be called externally to emit a particle. * * When called externally you can use the arguments to override any defaults the Emitter has set. * * The newly emitted particle is available in {@link Phaser.Particles.Arcade.Emitter#cursor}. * * @param x The x coordinate to emit the particle from. If `null` or `undefined` it will use `Emitter.emitX` or if the Emitter has a width > 1 a random value between `Emitter.left` and `Emitter.right`. * @param y The y coordinate to emit the particle from. If `null` or `undefined` it will use `Emitter.emitY` or if the Emitter has a height > 1 a random value between `Emitter.top` and `Emitter.bottom`. * @param key This is the image or texture used by the Particle during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Particle is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @return True if a particle was emitted, otherwise false. */ emitParticle(x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): boolean; /** * Call this function to emit the given quantity of particles at all once (an explosion) * * @param lifespan How long each particle lives once emitted in ms. 0 = forever. * @param quantity How many particles to launch. - Default: this.maxParticles * @return This Emitter instance. */ explode(lifespan?: number, quantity?: number): Phaser.Particles.Arcade.Emitter; /** * Call this function to start emitting a flow of particles. * `quantity` particles are released every interval of `frequency` ms until `total` particles have been released (or forever). * If you set the total to be 20 and quantity to be 5 then flow will emit 4 times in total (4 × 5 = 20 total) and then turn {@link #on off}. * If you set the total to be -1 then no quantity cap is used and it will keep emitting (as long as there are inactive particles available). * * {@link Phaser.Particles.Arcade.Emitter#output output}, {@link Phaser.Particles.Arcade.Emitter#lifespanOutput lifespanOutput}, and {@link Phaser.Particles.Arcade.Emitter#remainder remainder} describe the particle flow rate. * During a stable flow, the number of active particles approaches {@link Phaser.Particles.Arcade.Emitter#lifespanOutput lifespanOutput} and the number of inactive particles approaches {@link Phaser.Particles.Arcade.Emitter#remainder remainder}. * If {@link Phaser.Particles.Arcade.Emitter#remainder remainder} is less than 0, there will likely be no particles available for a portion of the flow (see {@link Phaser.Particles.Arcade.Emitter#count count}). * * @param lifespan How long each particle lives once emitted in ms. 0 = forever. * @param frequency The interval between each release of particles, given in ms. Values between 0 and 16.66 will behave the same (60 releases per second). - Default: 250 * @param quantity How many particles to launch at each interval. Not larger than {@link #maxParticles}. - Default: 1 * @param total Turn {@link #on off} after launching this many particles in total. If -1 it will carry on indefinitely. - Default: -1 * @param immediate Should the flow start immediately (true) or wait until the first frequency event? (false) - Default: true * @return This Emitter instance. */ flow(lifespan?: number, frequency?: number, quantity?: number, total?: number, immediate?: boolean): Phaser.Particles.Arcade.Emitter; /** * Call this function to turn off all the particles and the emitter. * @return This Emitter instance. */ kill(): Phaser.Particles.Arcade.Emitter; /** * This function generates a new set of particles for use by this emitter. * The particles are stored internally waiting to be emitted via Emitter.start. * * @param keys A string or an array of strings that the particle sprites will use as their texture. If an array one is picked at random. * @param frames A frame number, or array of frames that the sprite will use. If an array one is picked at random. * @param quantity The number of particles to generate. If not given it will use the value of Emitter.maxParticles. If the value is greater than Emitter.maxParticles it will use Emitter.maxParticles as the quantity. * @param collide If you want the particles to be able to collide with other Arcade Physics bodies then set this to true. * @param collideWorldBounds A particle can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World. * @param particleArguments Custom arguments to pass to your particle class * @return This Emitter instance. */ makeParticles(keys: any, frames?: any, quantity?: number, collide?: boolean, collideWorldBounds?: boolean, particleArguments?: any): Phaser.Particles.Arcade.Emitter; reset(x: number, y: number, health?: number): Phaser.Particles; /** * A more compact way of setting the alpha constraints of the particles. * The rate parameter, if set to a value above zero, lets you set the speed at which the Particle change in alpha from min to max. * If rate is zero, which is the default, the particle won't change alpha - instead it will pick a random alpha between min and max on emit. * * @param min The minimum value for this range. - Default: 1 * @param max The maximum value for this range. - Default: 1 * @param rate The rate (in ms) at which the particles will change in alpha from min to max, or set to zero to pick a random alpha between the two. * @param ease If you've set a rate > 0 this is the easing formula applied between the min and max values. - Default: Phaser.Easing.Linear.None * @param yoyo If you've set a rate > 0 you can set if the ease will yoyo or not (i.e. ease back to its original values) * @return This Emitter instance. */ setAlpha(min?: number, max?: number, rate?: number, ease?: (k: number) => number, yoyo?: boolean): Phaser.Particles.Arcade.Emitter; /** * Sets a radial pattern for emitting particles. * * This is a shorthand for setting {@link Phaser.Particles.Arcade.Emitter#minAngle minAngle}, {@link Phaser.Particles.Arcade.Emitter#maxAngle maxAngle}, {@link Phaser.Particles.Arcade.Emitter#minSpeed minSpeed}, and {@link Phaser.Particles.Arcade.Emitter#maxSpeed maxSpeed}. * * To remove the radial pattern, use `setAngle(null, null)`. * * @param minAngle The minimum angle of initial particle velocities, in degrees. * @param maxAngle The maximum angle of initial particle velocities, in degrees. * @param minSpeed The minimum initial particle speed. * @param maxSpeed The maximum initial particle speed. * @return This Emitter instance. */ setAngle(minAngle: number, maxAngle: number, minSpeed?: number, maxSpeed?: number): Phaser.Particles.Arcade.Emitter; /** * Sets gravity for emitted particles. * * @param x The horizontal gravity component. * @param y The vertical gravity component. * @return This Emitter instance. */ setGravity(x?: number, y?: number): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the angular velocity constraints of the particles. * * @param min The minimum value for this range. * @param max The maximum value for this range. * @return This Emitter instance. */ setRotation(min?: number, max?: number): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the scale constraints of the particles. * The rate parameter, if set to a value above zero, lets you set the speed and ease which the Particle uses to change in scale from min to max across both axis. * If rate is zero, which is the default, the particle won't change scale during update, instead it will pick a random scale between min and max on emit. * * @param minX The minimum value of Particle.scale.x. - Default: 1 * @param maxX The maximum value of Particle.scale.x. - Default: 1 * @param minY The minimum value of Particle.scale.y. - Default: 1 * @param maxY The maximum value of Particle.scale.y. - Default: 1 * @param rate The rate (in ms) at which the particles will change in scale from min to max, or set to zero to pick a random size between the two. * @param ease If you've set a rate > 0 this is the easing formula applied between the min and max values. - Default: Phaser.Easing.Linear.None * @param yoyo If you've set a rate > 0 you can set if the ease will yoyo or not (i.e. ease back to its original values) * @return This Emitter instance. */ setScale(minX?: number, maxX?: number, minY?: number, maxY?: number, rate?: number, ease?: (k: number) => number, yoyo?: boolean): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the width and height of the emitter. * * @param width The desired width of the emitter (particles are spawned randomly within these dimensions). * @param height The desired height of the emitter. * @return This Emitter instance. */ setSize(width: number, height: number): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the X and Y velocity ranges of the emitter. * * @param minX The minimum horizontal speed. * @param maxX The maximum horizontal speed. * @param minY The minimum vertical speed. * @param maxY The maximum vertical speed. * @return This Emitter instance. */ setSpeed(minX: number, maxX: number, minY: number, maxY: number): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the X velocity range of the emitter. * * @param min The minimum value for this range. * @param max The maximum value for this range. * @return This Emitter instance. */ setXSpeed(min: number, max: number): Phaser.Particles.Arcade.Emitter; /** * A more compact way of setting the Y velocity range of the emitter. * * @param min The minimum value for this range. * @param max The maximum value for this range. * @return This Emitter instance. */ setYSpeed(min: number, max: number): Phaser.Particles.Arcade.Emitter; /** * Start emitting particles. * * {@link Phaser.Particles.Arcade.Emitter#explode explode} and {@link Phaser.Particles.Arcade.Emitter#flow flow} are simpler methods. * * There are two patterns, based on the `explode` argument: * * ##### explode=true * * start(true, lifespan=0, null, total) * * When `explode` is true or `forceQuantity` is true, `start` emits `total` particles immediately. You should pass a nonzero `total`. * * ##### explode=false * * start(false, lifespan=0, frequency=250, total=0) * * When `explode` is false and `forceQuantity` is false, `start` emits 1 particle every interval of `frequency` ms. If `total` is not zero, the emitter turns itself off after `total` particles have been released. If `total` is zero, the emitter keeps emitting particles as long as they are available. To emit more than 1 particle per flow interval, use {@link Phaser.Particles.Arcade.Emitter#flow flow} instead. * * `forceQuantity` seems equivalent to `explode` and can probably be avoided. * * @param explode Whether the particles should all burst out at once (true) or at the frequency given (false). - Default: true * @param lifespan How long each particle lives once emitted in ms. 0 = forever. * @param frequency The interval between each release of 1 particle, when `explode` is false. Value given in ms. Ignored if `explode` is set to true. - Default: 250 * @param total Turn {@link #on off} after launching this many particles in total. * @param forceQuantity Equivalent to `explodes`. * @return This Emitter instance. */ start(explode?: boolean, lifespan?: number, frequency?: number, total?: number, forceQuantity?: boolean): Phaser.Particles.Arcade.Emitter; /** * Called automatically by the game loop, decides when to launch particles and when to "die". */ update(): void; /** * Handy for bringing game objects "back to life". Just sets alive and exists back to true. * @return This Emitter instance. */ revive(): Phaser.Particles.Arcade.Emitter; } } } /** * The Physics Manager is responsible for looking after all of the running physics systems. * Phaser supports 4 physics systems: Arcade Physics, P2, Ninja Physics and Box2D via a commercial plugin. * * Game Objects (such as Sprites) can only belong to 1 physics system, but you can have multiple systems active in a single game. * * For example you could have P2 managing a polygon-built terrain landscape that an vehicle drives over, while it could be firing bullets that use the * faster (due to being much simpler) Arcade Physics system. */ class Physics { /** * The Physics Manager is responsible for looking after all of the running physics systems. * Phaser supports 4 physics systems: Arcade Physics, P2, Ninja Physics and Box2D via a commercial plugin. * * Game Objects (such as Sprites) can only belong to 1 physics system, but you can have multiple systems active in a single game. * * For example you could have P2 managing a polygon-built terrain landscape that an vehicle drives over, while it could be firing bullets that use the * faster (due to being much simpler) Arcade Physics system. * * @param game A reference to the currently running game. * @param physicsConfig A physics configuration object to pass to the Physics world on creation. */ constructor(game: Phaser.Game, config?: any); static ARCADE: number; static P2JS: number; static NINJA: number; static BOX2D: number; static CHIPMUNK: number; static MATTERJS: number; /** * The Arcade Physics system. */ arcade: Phaser.Physics.Arcade; /** * The physics configuration object as passed to the game on creation. */ config: any; /** * Local reference to game. */ game: Phaser.Game; /** * The N+ Ninja Physics system. */ ninja: Phaser.Physics.Ninja; /** * The P2.JS Physics system. */ p2: Phaser.Physics.P2; /** * The Box2D Physics system. */ box2d: any; /** * Clears down all active physics systems. This doesn't destroy them, it just clears them of objects and is called when the State changes. */ clear(): void; /** * Destroys all active physics systems. Usually only called on a Game Shutdown, not on a State swap. */ destroy(): void; /** * This will create a default physics body on the given game object or array of objects. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * It can be for any of the physics systems that have been started: * * Phaser.Physics.Arcade - A light weight AABB based collision system with basic separation. * Phaser.Physics.P2JS - A full-body advanced physics system supporting multiple object shapes, polygon loading, contact materials, springs and constraints. * Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. Advanced AABB and Circle vs. Tile collision. * Phaser.Physics.BOX2D - A port of https://code.google.com/p/box2d-html5 * Phaser.Physics.MATTER - A full-body and light-weight advanced physics system (still in development) * Phaser.Physics.CHIPMUNK is still in development. * * If you require more control over what type of body is created, for example to create a Ninja Physics Circle instead of the default AABB, then see the * individual physics systems `enable` methods instead of using this generic one. * * @param object The game object to create the physics body on. Can also be an array of objects, a body will be created on every object in the array. * @param system The physics system that will be used to create the body. Defaults to Arcade Physics. - Default: Phaser.Physics.ARCADE * @param debug Enable the debug drawing for this body. Defaults to false. */ enable(object: any, system?: number, debug?: boolean): void; /** * Parses the Physics Configuration object passed to the Game constructor and starts any physics systems specified within. */ parseConfig(): void; /** * preUpdate checks. */ preUpdate(): void; /** * Resets the active physics system. Called automatically on a Phaser.State swap. */ reset(): void; /** * Updates the physics bounds to match the world dimensions. */ setBoundsToWorld(): void; /** * This will create an instance of the requested physics simulation. * Phaser.Physics.Arcade is running by default, but all others need activating directly. * * You can start the following physics systems: * * Phaser.Physics.P2JS - A full-body advanced physics system by Stefan Hedman. * Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. * Phaser.Physics.BOX2D - A commercial Phaser Plugin (see http://phaser.io) * * Both Ninja Physics and Box2D require their respective plugins to be loaded before you can start them. * They are not bundled into the core Phaser library. * * If the physics world has already been created (i.e. in another state in your game) then * calling startSystem will reset the physics world, not re-create it. If you need to start them again from their constructors * then set Phaser.Physics.p2 (or whichever system you want to recreate) to `null` before calling `startSystem`. * * @param system The physics system to start: Phaser.Physics.ARCADE, Phaser.Physics.P2JS, Phaser.Physics.NINJA or Phaser.Physics.BOX2D. */ startSystem(system: number): void; /** * Updates all running physics systems. */ update(): void; } /** * A Video object that takes a previously loaded Video from the Phaser Cache and handles playback of it. * * Alternatively it takes a getUserMedia feed from an active webcam and streams the contents of that to * the Video instead (see `startMediaStream` method) * * The video can then be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback * changes (i.e. you pause the video, or seek to a new time) then this change will be seen across all Sprites simultaneously. * * Due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode. * * If you need each Sprite to be able to play a video fully independently then you will need one Video object per Sprite. * Please understand the obvious performance implications of doing this, and the memory required to hold videos in RAM. * * On some mobile browsers such as iOS Safari, you cannot play a video until the user has explicitly touched the screen. * This works in the same way as audio unlocking. Phaser will handle the touch unlocking for you, however unlike with audio * it's worth noting that every single Video needs to be touch unlocked, not just the first one. You can use the `changeSource` * method to try and work around this limitation, but see the method help for details. * * Small screen devices, especially iPod and iPhone will launch the video in its own native video player, * outside of the Safari browser. There is no way to avoid this, it's a device imposed limitation. * * Note: On iOS if you need to detect when the user presses the 'Done' button (before the video ends) * then you need to add your own event listener */ export class Video { /** * A reference to the currently running game. */ game: Phaser.Game; /** * The key of the Video in the Cache, if stored there. Will be `null` if this Video is using the webcam instead. * Default: null */ key: string; /** * The HTML Video Element that is added to the document. */ video: HTMLVideoElement; baseTexture: PIXI.BaseTexture; /** * The PIXI.Texture. */ texture: PIXI.Texture; /** * The Frame this video uses for rendering. */ textureFrame: Phaser.Frame; /** * The const type of this object. */ type: number; /** * If true this video will never send its image data to the GPU when its dirty flag is true. This only applies in WebGL. */ disableTextureUpload: boolean; dirty: boolean; /** * The current time of the video in seconds. If set the video will attempt to seek to that point in time. */ currentTime: number; /** * The duration of the video in seconds. */ duration: number; /** * The progress of this video. This is a value between 0 and 1, where 0 is the start and 1 is the end of the video. */ progress: number; /** * Gets or sets the muted state of the Video. */ mute: boolean; /** * Gets or sets the paused state of the Video. * If the video is still touch locked (such as on iOS devices) this call has no effect. */ paused: boolean; /** * Gets or sets the volume of the Video, a value between 0 and 1. The value given is clamped to the range 0 to 1. */ volume: number; /** * Gets or sets the playback rate of the Video. This is the speed at which the video is playing. */ playbackRate: boolean; /** * True if the video is currently playing (and not paused or ended), otherwise false. */ playing: boolean; /** * Start playing the video when it's unlocked. * Default: true */ playWhenUnlocked: boolean; /** * Gets or sets if the Video is set to loop. * Please note that at present some browsers (i.e. Chrome) do not support *seamless* video looping. * If the video isn't yet set this will always return false. */ loop: boolean; /** * The width of the video in pixels. */ width: number; /** * The height of the video in pixels. */ height: number; /** * The Video Stream data. Only set if this Video is streaming from the webcam via `startMediaStream`. */ videoStream: any; /** * Is there a streaming video source? I.e. from a webcam. */ isStreaming: boolean; /** * A snapshot grabbed from the video. This is initially black. Populate it by calling Video.grab(). * When called the BitmapData is updated with a grab taken from the current video playing or active video stream. * If Phaser has been compiled without BitmapData support this property will always be `null`. */ snapshot: Phaser.BitmapData; /** * The amount of ms allowed to elapsed before the Video.onTimeout signal is dispatched while waiting for webcam access. * Default: 15000 */ timeout: number; /** * 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. * Default: 20 */ retryLimit: number; /** * The current retry attempt. */ retry: number; /** * The number of ms between each retry at monitoring the status of a downloading video. * Default: 500 */ retryInterval: number; /** * This signal is dispatched if the user allows access to their webcam. */ onAccess: Phaser.Signal; /** * This signal is dispatched if an error occurs either getting permission to use the webcam (for a Video Stream) or when trying to play back a video file. */ onError: Phaser.Signal; /** * This signal is dispatched when the Video starts to play. It sends 3 parameters: a reference to the Video object, if the video is set to loop or not and the playback rate. */ onPlay: Phaser.Signal; /** * This signal is dispatched when the Video completes playback, i.e. enters an 'ended' state. On iOS specifically it also fires if the user hits the 'Done' button at any point during playback. Videos set to loop will never dispatch this signal. */ onComplete: Phaser.Signal; /** * This signal is dispatched when the Video is unlocked. */ onTouchUnlock: Phaser.Signal; onUpdate: Phaser.Signal; /** * This signal is dispatched if when asking for permission to use the webcam no response is given within a the Video.timeout limit. * This may be because the user has picked `Not now` in the permissions window, or there is a delay in establishing the LocalMediaStream. */ onTimeout: Phaser.Signal; /** * true if this video is currently locked awaiting a touch event. This happens on some mobile devices, such as iOS. */ touchLocked: boolean; complete: () => void; /** * A Video object that takes a previously loaded Video from the Phaser Cache and handles playback of it. * * Alternatively it takes a getUserMedia feed from an active webcam and streams the contents of that to * the Video instead (see `startMediaStream` method) * * The video can then be applied to a Sprite as a texture. If multiple Sprites share the same Video texture and playback * changes (i.e. you pause the video, or seek to a new time) then this change will be seen across all Sprites simultaneously. * * Due to a bug in IE11 you cannot play a video texture to a Sprite in WebGL. For IE11 force Canvas mode. * * If you need each Sprite to be able to play a video fully independently then you will need one Video object per Sprite. * Please understand the obvious performance implications of doing this, and the memory required to hold videos in RAM. * * On some mobile browsers such as iOS Safari, you cannot play a video until the user has explicitly touched the screen. * This works in the same way as audio unlocking. Phaser will handle the touch unlocking for you, however unlike with audio * it's worth noting that every single Video needs to be touch unlocked, not just the first one. You can use the `changeSource` * method to try and work around this limitation, but see the method help for details. * * Small screen devices, especially iPod and iPhone will launch the video in its own native video player, * outside of the Safari browser. There is no way to avoid this, it's a device imposed limitation. * * Note: On iOS if you need to detect when the user presses the 'Done' button (before the video ends) * then you need to add your own event listener * * @param game A reference to the currently running game. * @param key The key of the video file in the Phaser.Cache that this Video object will play. Set to `null` or leave undefined if you wish to use a webcam as the source. See `startMediaStream` to start webcam capture. * @param url If the video hasn't been loaded then you can provide a full URL to the file here (make sure to set key to null) */ constructor(game: Phaser.Game, key?: string, url?: string); /** * Updates the given Display Objects so they use this Video as their texture. * This will replace any texture they will currently have set. * * @param object Either a single Sprite/Image or an Array of Sprites/Images. * @return This Video object for method chaining. */ add(object: Phaser.Sprite | Phaser.Sprite[] | Phaser.Image | Phaser.Image[]): Phaser.Video; /** * Creates a new Phaser.Image object, assigns this Video to be its texture, adds it to the world then returns it. * * @param x The x coordinate to place the Image at. * @param y The y coordinate to place the Image at. * @param anchorX Set the x anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param anchorY Set the y anchor point of the Image. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. * @param scaleX The horizontal scale factor of the Image. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @param scaleY The vertical scale factor of the Image. A value of 1 means no scaling. 2 would be twice the size, and so on. - Default: 1 * @return The newly added Image object. */ addToWorld(x?: number, y?: number, anchorX?: number, anchorY?: Number, scaleX?: number, scaleY?: number): Phaser.Image; /** * Creates a new Video element from the given Blob. The Blob must contain the video data in the correct encoded format. * This method is typically called by the Phaser.Loader and Phaser.Cache for you, but is exposed publicly for convenience. * * @param blob The Blob containing the video data. * @return This Video object for method chaining. */ createVideoFromBlob(blob: Blob): Phaser.Video; /** * Instead of playing a video file this method allows you to stream video data from an attached webcam. * * As soon as this method is called the user will be prompted by their browser to "Allow" access to the webcam. * If they allow it the webcam feed is directed to this Video. Call `Video.play` to start the stream. * * If they block the webcam the onError signal will be dispatched containing the NavigatorUserMediaError * or MediaStreamError event. * * You can optionally set a width and height for the stream. If set the input will be cropped to these dimensions. * If not given then as soon as the stream has enough data the video dimensions will be changed to match the webcam device. * You can listen for this with the onChangeSource signal. * * @param captureAudio Controls if audio should be captured along with video in the video stream. * @param width The width is used to create the video stream. If not provided the video width will be set to the width of the webcam input source. * @param height The height is used to create the video stream. If not provided the video height will be set to the height of the webcam input source. * @param captureVideo Constraints and settings used to create the video stream. * @return This Video object for method chaining or false if the device doesn't support getUserMedia. */ startMediaStream(captureAudio?: boolean | MediaTrackConstraints, width?: number, height?: number, captureVideo?: MediaTrackConstraints): Phaser.Video; /** * Creates a new Video element from the given URL. * * @param url The URL of the video. * @param autoplay Automatically start the video? * @param crossOrigin The crossorigin parameter provides support for CORS * @return This Video object for method chaining. */ createVideoFromURL(url: string, autoplay?: boolean, crossOrigin?: string): Phaser.Video; /** * On some mobile browsers you cannot play a video until the user has explicitly touched the video to allow it. * Phaser handles this via the `setTouchLock` method. However if you have 3 different videos, maybe an "Intro", "Start" and "Game Over" * split into three different Video objects, then you will need the user to touch-unlock every single one of them. * * You can avoid this by using just one Video object and simply changing the video source. Once a Video element is unlocked it remains * unlocked, even if the source changes. So you can use this to your benefit to avoid forcing the user to 'touch' the video yet again. * * As you'd expect there are limitations. So far we've found that the videos need to be in the same encoding format and bitrate. * This method will automatically handle a change in video dimensions, but if you try swapping to a different bitrate we've found it * cannot render the new video on iOS (desktop browsers cope better). * * When the video source is changed the video file is requested over the network. Listen for the `onChangeSource` signal to know * when the new video has downloaded enough content to be able to be played. Previous settings such as the volume and loop state * are adopted automatically by the new video. * * @param src The new URL to change the video.src to. * @param autoplay Should the video play automatically after the source has been updated? - Default: true * @return This Video object for method chaining. */ changeSource(src: string, autoplay?: boolean): Phaser.Video; connectToMediaStram(video: any, stream: any): Phaser.Video; /** * Destroys the Video object. This calls `Video.stop` and then `Video.removeVideoElement`. * If any Sprites are using this Video as their texture it is up to you to manage those. */ destroy(): void; /** * Starts this video playing. * * If the video is already playing, or has been queued to play with `changeSource` then this method just returns. * * @param loop Should the video loop automatically when it reaches the end? Please note that at present some browsers (i.e. Chrome) do not support *seamless* video looping. * @param playbackRate The playback rate of the video. 1 is normal speed, 2 is x2 speed, and so on. You cannot set a negative playback rate. - Default: 1 * @return This Video object for method chaining. */ play(loop?: boolean, playbackRate?: number): Phaser.Video; /** * Called when the video starts to play. Updates the texture. */ playHandler(): void; /** * If the game is running in WebGL this will push the texture up to the GPU if it's dirty. * This is called automatically if the Video is being used by a Sprite, otherwise you need to remember to call it in your render function. * If you wish to suppress this functionality set Video.disableTextureUpload to `true`. */ render(): void; /** * Removes the Video element from the DOM by calling parentNode.removeChild on itself. * Also removes the autoplay and src attributes and nulls the reference. */ removeVideoElement(): void; resizeFrame(parent: any, width: number, height: number): void; /** * Sets the Input Manager touch callback to be Video.unlock. * Required for mobile video unlocking. Mostly just used internally. */ setTouchLock(): void; /** * Grabs the current frame from the Video or Video Stream and renders it to the Video.snapshot BitmapData. * * You can optionally set if the BitmapData should be cleared or not, the alpha and the blend mode of the draw. * * If you need more advanced control over the grabbing them call `Video.snapshot.copy` directly with the same parameters as BitmapData.copy. * * @param clear Should the BitmapData be cleared before the Video is grabbed? Unless you are using alpha or a blend mode you can usually leave this set to false. * @param alpha The alpha that will be set on the video before drawing. A value between 0 (fully transparent) and 1, opaque. - Default: 1 * @param blendMode The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. * @return A reference to the Video.snapshot BitmapData object for further method chaining. */ grab(clear?: boolean, alpha?: number, blendMode?: string): Phaser.BitmapData; /** * Stops the video playing. * * This removes all locally set signals. * * If you only wish to pause playback of the video, to resume at a later time, use `Video.paused = true` instead. * If the video hasn't finished downloading calling `Video.stop` will not abort the download. To do that you need to * call `Video.destroy` instead. * * If you are using a video stream from a webcam then calling Stop will disconnect the MediaStream session and disable the webcam. * @return This Video object for method chaining. */ stop(): void; /** * Enables the video on mobile devices, usually after the first touch. * If the SoundManager hasn't been unlocked then this will automatically unlock that as well. * Only one video can be pending unlock at any one time. */ unlock(): boolean; /** * Called automatically if the video source changes and updates the internal texture dimensions. * Then dispatches the onChangeSource signal. * * @param event The event which triggered the texture update. * @param width The new width of the video. If undefined `video.videoWidth` is used. * @param height The new height of the video. If undefined `video.videoHeight` is used. */ updateTexture(event?: any, width?: number, height?: number): void; } module Physics { /** * The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods. */ class Arcade { /** * A constant used for the sortDirection value. * Use this if you don't wish to perform any pre-collision sorting at all, or will manually sort your Groups. */ static SORT_NONE: number; /** * A constant used for the sortDirection value. * Use this if your game world is wide but short and scrolls from the left to the right (i.e. Mario) */ static LEFT_RIGHT: number; /** * A constant used for the sortDirection value. * Use this if your game world is wide but short and scrolls from the right to the left (i.e. Mario backwards) */ static RIGHT_LEFT: number; /** * A constant used for the sortDirection value. * Use this if your game world is narrow but tall and scrolls from the top to the bottom (i.e. Dig Dug) */ static TOP_BOTTOM: number; /** * A constant used for the sortDirection value. * Use this if your game world is narrow but tall and scrolls from the bottom to the top (i.e. Commando or a vertically scrolling shoot-em-up) */ static BOTTOM_TOP: number; /** * The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods. * * @param game reference to the current game instance. */ constructor(game: Phaser.Game); /** * A value added to the delta values during collision checks. Increase it to prevent sprite tunneling. * Default: 4 */ OVERLAP_BIAS: number; TILE_BIAS: number; /** * The bounds inside of which the physics world exists. Defaults to match the world bounds. */ bounds: Phaser.Rectangle; /** * Which edges of the World bounds Bodies can collide against when `collideWorldBounds` is `true`. * For example checkCollision.down = false means Bodies cannot collide with the World.bounds.bottom. An object containing allowed collision flags (up, down, left, right). */ checkCollision: { up?: boolean; down?: boolean; left?: boolean; right?: boolean; }; /** * If true World.separate will always separate on the X axis before Y. Otherwise it will check gravity totals first. */ forceX: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * The World gravity setting. Defaults to x: 0, y: 0, or no gravity. */ gravity: Phaser.Point; /** * If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies. */ isPaused: boolean; /** * The world QuadTree. */ quadTree: Phaser.QuadTree; /** * Used by the QuadTree to set the maximum number of objects per quad. */ maxObjects: number; /** * Used by the QuadTree to set the maximum number of iteration levels. */ maxLevels: number; /** * If true the QuadTree will not be used for any collision. QuadTrees are great if objects are well spread out in your game, otherwise they are a performance hit. If you enable this you can disable on a per body basis via `Body.skipQuadTree`. */ skipQuadTree: boolean; /** * Used when colliding a Sprite vs. a Group, or a Group vs. a Group, this defines the direction the sort is based on. Default is Phaser.Physics.Arcade.LEFT_RIGHT. */ sortDirection: number; /** * Given the rotation (in radians) and speed calculate the acceleration and return it as a Point object, or set it to the given point object. * One way to use this is: accelerationFromRotation(rotation, 200, sprite.acceleration) which will set the values directly to the sprites acceleration and not create a new Point object. * * @param rotation The angle in radians. * @param speed The speed it will move, in pixels per second sq. - Default: 60 * @param point The Point object in which the x and y properties will be set to the calculated acceleration. * @return - A Point where point.x contains the acceleration x value and point.y contains the acceleration y value. */ accelerationFromRotation(rotation: number, speed?: number, point?: Phaser.Point): Phaser.Point; /** * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * 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. * * @param displayObject The display object to move. * @param destination The display object to move towards. Can be any object but must have visible x/y properties. * @param speed The speed it will accelerate in pixels per second. - Default: 60 * @param xSpeedMax The maximum x velocity the display object can reach. - Default: 500 * @param ySpeedMax The maximum y velocity the display object can reach. - Default: 500 * @return The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToObject(displayObject: any, destination: any, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; /** * Sets the acceleration.x/y property on the display object so it will move towards the target at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * 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. * * @param displayObject The display object to move. * @param pointer The pointer to move towards. Defaults to Phaser.Input.activePointer. * @param speed The speed it will accelerate in pixels per second. - Default: 60 * @param xSpeedMax The maximum x velocity the display object can reach. - Default: 500 * @param ySpeedMax The maximum y velocity the display object can reach. - Default: 500 * @return The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToPointer(displayObject: any, pointer?: Phaser.Pointer, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; /** * Sets the acceleration.x/y property on the display object so it will move towards the x/y coordinates at the given speed (in pixels per second sq.) * You must give a maximum speed value, beyond which the display object won't go any faster. * 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. * * @param displayObject The display object to move. * @param x The x coordinate to accelerate towards. * @param y The y coordinate to accelerate towards. * @param speed The speed it will accelerate in pixels per second. - Default: 60 * @param xSpeedMax The maximum x velocity the display object can reach. - Default: 500 * @param ySpeedMax The maximum y velocity the display object can reach. - Default: 500 * @return The angle (in radians) that the object should be visually set to in order to match its new trajectory. */ accelerateToXY(displayObject: any, x: number, y: number, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number; /** * Find the angle in radians between two display objects (like Sprites). * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * @param source The Display Object to test from. * @param target The Display Object to test to. * @param world Calculate the angle using World coordinates (true), or Object coordinates (false, the default) * @return The angle in radians between the source and target display objects. */ angleBetween(source: any, target: any, world?: boolean): number; /** * Find the angle in radians between a display object (like a Sprite) and a Pointer, taking their x/y and center into account. * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * @param displayObject The Display Object to test from. * @param pointer The Phaser.Pointer to test to. If none is given then Input.activePointer is used. * @param world Calculate the angle using World coordinates (true), or Object coordinates (false, the default) * @return The angle in radians between displayObject.x/y to Pointer.x/y */ angleToPointer(displayObject: any, pointer?: Phaser.Pointer, world?: boolean): number; /** * Find the angle in radians between a display object (like a Sprite) and the given x/y coordinate. * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * @param displayObject The Display Object to test from. * @param x The x coordinate to get the angle to. * @param y The y coordinate to get the angle to. * @param world Calculate the angle using World coordinates (true), or Object coordinates (false, the default) * @return The angle in radians between displayObject.x/y to Pointer.x/y */ angleToXY(displayObject: any, x: number, y: number, world?: boolean): number; /** * From a set of points or display objects, find the one closest to a source point or object. * * @param source The {@link Phaser.Point Point} or Display Object distances will be measured from. * @param targets The {@link Phaser.Point Points} or Display Objects whose distances to the source will be compared. * @param world Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If `useCenter` is true, this value is ignored. * @param useCenter Calculate the distance using the {@link Phaser.Sprite#centerX} and {@link Phaser.Sprite#centerY} coordinates. If true, this value overrides the `world` argument. * @return - The first target closest to the origin. */ closest(source: any, targets: any[], world?: boolean, useCenter?: boolean): any; /** * Checks for collision between two game objects and separates them if colliding ({@link https://gist.github.com/samme/cbb81dd19f564dcfe2232761e575063d details}). If you don't require separation then use {@link Phaser.Physics.Arcade#overlap overlap} instead. * * You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions. * Both the `object1` and `object2` can be arrays of objects, of differing types. * * If two Groups or arrays are passed, each member of one will be tested against each member of the other. * * If one Group **only** is passed (as `object1`), each member of the Group will be collided against the other members. * * If either object is `null` the collision test will fail. * * Bodies with `enable = false` and Sprites with `exists = false` are skipped (ignored). * * An optional processCallback can be provided. If given this function will be called when two sprites are found to be colliding. It is called before any separation takes place, giving you the chance to perform additional checks. If the function returns true then the collision and separation is carried out. If it returns false it is skipped. * * The collideCallback is an optional function that is only called if two sprites collide. If a processCallback has been set then it needs to return true for collideCallback to be called. * * **This function is not recursive**, and will not test against children of objects passed (i.e. Groups or Tilemaps within other Groups). * * ##### Examples * * ```javascript * collide(group); * collide(group, undefined); // equivalent * * collide(sprite1, sprite2); * * collide(sprite, group); * * collide(group1, group2); * * collide([sprite1, sprite2], [sprite3, sprite4]); // 1 vs. 3, 1 vs. 4, 2 vs. 3, 2 vs. 4 * ``` * * ##### Tilemaps * * Tiles marked via {@link Phaser.Tilemap#setCollision} (and similar methods) are "solid". If a Sprite collides with one of these tiles, the two are separated by moving the Sprite outside the tile's edges. Enable {@link Phaser.TilemapLayer#debug} to see the colliding edges of the Tilemap. * * Tiles with a callback attached via {@link Phaser.Tilemap#setTileIndexCallback} or {@link Phaser.Tilemap#setTileLocationCallback} invoke the callback if a Sprite collides with them. If a tile has a callback attached via both methods, only the location callback is invoked. The colliding Sprite is separated from the tile only if the callback returns `true`. * * @param object1 The first object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.TilemapLayer. * @param object2 The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.TilemapLayer. * @param collideCallback An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are colliding Group vs. Sprite, in which case Sprite will always be the first parameter. * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collision will only happen if processCallback returns true. The two objects will be passed to this function in the same order in which you specified them, unless you are colliding Group vs. Sprite, in which case Sprite will always be the first parameter. * @param callbackContext The context in which to run the callbacks. * @return True if a collision occurred otherwise false. */ collide(object1: any, object2?: any, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean; /** * A tween-like function that takes a starting velocity and some other factors and returns an altered velocity. * Based on a function in Flixel by @ADAMATOMIC * * @param axis 0 for nothing, 1 for horizontal, 2 for vertical. * @param body The Body object to be updated. * @param velocity Any component of velocity (e.g. 20). * @param acceleration Rate at which the velocity is changing. * @param drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set. * @param max An absolute value cap for the velocity. - Default: 10000 * @return The altered Velocity value. */ computeVelocity(axis: number, body: Phaser.Physics.Arcade.Body, velocity: number, acceleration: number, drag: number, max?: number): number; /** * Find the distance between two display objects (like Sprites). * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * If you have nested objects and need to calculate the distance between their centers in World coordinates, * set their anchors to (0.5, 0.5) and use the `world` argument. * * If objects aren't nested or they share a parent's offset, you can calculate the distance between their * centers with the `useCenter` argument, regardless of their anchor values. * * @param source The Display Object to test from. * @param target The Display Object to test to. * @param world Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If `useCenter` is true, this value is ignored. * @param useCenter Calculate the distance using the {@link Phaser.Sprite#centerX} and {@link Phaser.Sprite#centerY} coordinates. If true, this value overrides the `world` argument. * @return The distance between the source and target objects. */ distanceBetween(source: any, target: any, world?: boolean, useCenter?: boolean): number; /** * Find the distance between a display object (like a Sprite) and a Pointer. If no Pointer is given the Input.activePointer is used. * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed. * If you need to calculate from the center of a display object instead use {@link Phaser.Physics.Arcade#distanceBetween distanceBetween} with the `useCenter` argument. * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * @param displayObject The Display Object to test from. * @param pointer The Phaser.Pointer to test to. If none is given then Input.activePointer is used. * @param world Calculate the distance using World coordinates (true), or Object coordinates (false, the default) * @return The distance between the object and the Pointer. */ distanceToPointer(displayObject: any, pointer?: Phaser.Pointer, world?: boolean): number; /** * Find the distance between a display object (like a Sprite) and the given x/y coordinates. * The calculation is made from the display objects x/y coordinate. This may be the top-left if its anchor hasn't been changed. * If you need to calculate from the center of a display object instead use {@link Phaser.Physics.Arcade#distanceBetween distanceBetween} with the `useCenter` argument. * * The optional `world` argument allows you to return the result based on the Game Objects `world` property, * instead of its `x` and `y` values. This is useful of the object has been nested inside an offset Group, * or parent Game Object. * * @param displayObject The Display Object to test from. * @param x The x coordinate to move towards. * @param y The y coordinate to move towards. * @param world Calculate the distance using World coordinates (true), or Object coordinates (false, the default) * @return The distance between the object and the x/y coordinates. */ distanceToXY(displayObject: any, x: number, y: number, world?: boolean): number; /** * This will create an Arcade Physics body on the given game object or array of game objects. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enable(object: any, children?: Boolean): void; /** * Creates an Arcade Physics body on the given game object. * * A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled. * * When you add an Arcade Physics body to an object it will automatically add the object into its parent Groups hash array. * * @param object The game object to create the physics body on. A body will only be created if this object has a null `body` property. */ enableBody(object: any): void; /** * From a set of points or display objects, find the one farthest from a source point or object. * * @param source The {@link Phaser.Point Point} or Display Object distances will be measured from. * @param targets The {@link Phaser.Point Points} or Display Objects whose distances to the source will be compared. * @param world Calculate the distance using World coordinates (true), or Object coordinates (false, the default). If `useCenter` is true, this value is ignored. * @param useCenter Calculate the distance using the {@link Phaser.Sprite#centerX} and {@link Phaser.Sprite#centerY} coordinates. If true, this value overrides the `world` argument. * @return - The target closest to the origin. */ farthest(source: any, targets: any[], world?: boolean, useCenter?: boolean): any; /** * Given a Group and a location this will check to see which Group children overlap with the coordinates. * Each child will be sent to the given callback for further processing. * Note that the children are not checked for depth order, but simply if they overlap the coordinate or not. * * @param x The x coordinate to check. * @param y The y coordinate to check. * @param group The Group to check. * @param callback A callback function that is called if the object overlaps the coordinates. The callback will be sent two parameters: the callbackArg and the Object that overlapped the location. * @param callbackContext The context in which to run the callback. * @param callbackArg An argument to pass to the callback. * @return An array of the Sprites from the Group that overlapped the coordinates. */ getObjectsAtLocation(x: number, y: number, group: Phaser.Group, callback?: (callbackArg: any, object: any) => void, callbackContext?: any, callbackArg?: any): Sprite[]; /** * Calculates the horizontal overlap between two Bodies and sets their properties accordingly, including: * `touching.left`, `touching.right` 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? * @return Returns the amount of horizontal overlap between the two bodies. */ getOverlapX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): number; /** * Calculates the vertical overlap between two Bodies and sets their properties accordingly, including: * `touching.up`, `touching.down` 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? * @return Returns the amount of vertical overlap between the two bodies. */ getOverlapY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): number; /** * Check for intersection against two bodies. * * @param body1 The first Body object to check. * @param body2 The second Body object to check. * @return True if they intersect, otherwise false. */ intersects(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): boolean; /** * 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 displayObject The display object to move. * @param destination The display object to move towards. Can be any object but must have visible x/y properties. * @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. * @return The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToObject(displayObject: any, destination: any, speed?: number, maxTime?: number): number; /** * Move the given display object towards the pointer at a steady velocity. If no pointer is given it will use Phaser.Input.activePointer. * 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. * * @param displayObject The display object to move. * @param speed The speed it will move, in pixels per second (default is 60 pixels/sec) - Default: 60 * @param pointer The pointer to move towards. Defaults to Phaser.Input.activePointer. * @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. * @return The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToPointer(displayObject: any, speed?: number, pointer?: Phaser.Pointer, maxTime?: number): number; /** * 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 displayObject The display object to move. * @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. * @return The angle (in radians) that the object should be visually set to in order to match its new velocity. */ moveToXY(displayObject: any, x: number, y: number, speed?: number, maxTime?: number): number; /** * Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters. * * Unlike {@link Phaser.Physics.Arcade#collide collide} the objects are NOT automatically separated or have any physics applied, they merely test for overlap results. * * You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks. * Both the first and second parameter can be arrays of objects, of differing types. * If two arrays are passed, the contents of the first parameter will be tested against all contents of the 2nd parameter. * * **This function is not recursive**, and will not test against children of objects passed (i.e. Groups within Groups). * * ##### Tilemaps * * Any overlapping tiles, including blank/null tiles, will give a positive result. Tiles marked via {@link Phaser.Tilemap#setCollision} (and similar methods) have no special status, and callbacks added via {@link Phaser.Tilemap#setTileIndexCallback} or {@link Phaser.Tilemap#setTileLocationCallback} are not invoked. So calling this method without any callbacks isn't very useful. * * If you're interested only in whether an object overlaps a certain tile or class of tiles, filter the tiles with `processCallback` and then use the result returned by this method. Blank/null tiles can be excluded by their {@link Phaser.Tile#index index} (-1). * * If you want to take action on certain overlaps, examine the tiles in `collideCallback` and then handle as you like. * * @param object1 The first object or array of objects to check. Can be Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param object2 The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param overlapCallback An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them, unless you are checking Group vs. Sprite, in which case Sprite will always be the first parameter. * @param processCallback A 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. * @return True if an overlap occurred otherwise false. */ overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean; processTileSeparationX(body: Phaser.Physics.Arcade.Body, x: number): boolean; processTileSeparationY(body: Phaser.Physics.Arcade.Body, y: number): void; /** * Updates the size of this physics world. * * @param x Top left most corner of the world. * @param y Top left most corner of the world. * @param width New width of the world. Can never be smaller than the Game.width. * @param height New height of the world. Can never be smaller than the Game.height. */ setBounds(x: number, y: number, width: number, height: number): void; /** * Updates the size of this physics world to match the size of the game world. */ setBoundsToWorld(): void; /** * The core separation function to separate two physics bodies. * * @param body1 The first Body object to separate. * @param body2 The second Body object to separate. * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this function is set then the sprites will only be collided if it returns true. * @param callbackContext The context in which to run the process callback. * @param overlapOnly Just run an overlap or a full collision. * @return Returns true if the bodies collided, otherwise false. */ separate(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, processCallback?: Function, callbackContext?: any, overlapOnly?: boolean): boolean; /** * The core separation function to separate two physics bodies on the x axis. * * @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, no separation or exchange of velocity will take place. * @return Returns true if the bodies were separated or overlap, otherwise false. */ separateX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean): boolean; /** * The core separation function to separate two physics bodies on the y axis. * * @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, no separation or exchange of velocity will take place. * @return Returns true if the bodies were separated or overlap, otherwise false. */ separateY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean): boolean; separateTile(i: number, body: Phaser.Physics.Arcade.Body, tile: Phaser.Tile): boolean; /** * This method will sort a Groups hash array. * * If the Group has `physicsSortDirection` set it will use the sort direction defined. * * Otherwise if the sortDirection parameter is undefined, or Group.physicsSortDirection is null, it will use Phaser.Physics.Arcade.sortDirection. * * By changing Group.physicsSortDirection you can customise each Group to sort in a different order. * * @param group The Group to sort. * @param sortDirection The sort direction used to sort this Group. */ sort(group: Phaser.Group): void; tileCheckX(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tile): number; tileCheckY(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tile): number; /** * Called automatically by a Physics body, it updates all motion related values on the Body unless `World.isPaused` is `true`. * * @param The Body object to be updated. */ updateMotion(body: Phaser.Physics.Arcade.Body): void; /** * Given the angle (in degrees) and speed calculate the velocity and return it as a Point object, or set it to the given point object. * One way to use this is: velocityFromAngle(angle, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point 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 sq. - Default: 60 * @param point The Point object in which the x and y properties will be set to the calculated velocity. * @return - A Point where point.x contains the velocity x value and point.y contains the velocity y value. */ velocityFromAngle(angle: number, speed?: number, point?: Phaser.Point): Phaser.Point; /** * Given the rotation (in radians) and speed calculate the velocity and return it as a Point object, or set it to the given point object. * One way to use this is: velocityFromRotation(rotation, 200, sprite.velocity) which will set the values directly to the sprites velocity and not create a new Point object. * * @param rotation The angle in radians. * @param speed The speed it will move, in pixels per second sq. - Default: 60 * @param point The Point object in which the x and y properties will be set to the calculated velocity. * @return - A Point where point.x contains the velocity x value and point.y contains the velocity y value. */ velocityFromRotation(rotation: number, speed?: number, point?: Phaser.Point): Phaser.Point; } module Arcade { /** * The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than * the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body. */ class Body { /** * The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than * the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body. * * @param sprite The Sprite object this physics body belongs to. */ constructor(sprite: Phaser.Sprite); /** * The acceleration is the rate of change of the velocity. Measured in pixels per second squared. */ acceleration: Phaser.Point; /** * Allow this Body to be influenced by {@link Phaser.Physics.Arcade.Body#drag drag}? * Default: true */ allowDrag: boolean; /** * Allow this Body to be influenced by gravity? Either world or local. * Default: true */ allowGravity: boolean; /** * Allow this Body to be rotated? (via angularVelocity, etc) * Default: true */ allowRotation: boolean; /** * The angle of the Body's **velocity** in radians. */ angle: number; /** * The angular acceleration is the rate of change of the angular velocity. Measured in degrees per second squared. */ angularAcceleration: number; /** * The drag applied during the rotation of the Body. Measured in degrees per second squared. */ angularDrag: number; /** * The angular velocity is the rate of change of the Body's rotation. It is measured in degrees per second. */ angularVelocity: number; /** * This object is populated with boolean values when the Body collides with the World bounds or a Tile. * For example if blocked.up is true then the Body cannot move up. An object containing on which faces this Body is blocked from moving, if any (none, up, down, left, right). */ blocked: FaceChoices; /** * The bottom value of this Body (same as Body.y + Body.height) */ bottom: number; /** * The elasticity of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity. */ bounce: Phaser.Point; /** * The center coordinate of the Physics Body. */ center: Phaser.Point; /** * Set the checkCollision properties to control which directions collision is processed for this Body. * For example checkCollision.up = false means it won't collide when the collision happened while moving up. * If you need to disable a Body entirely, use `body.enable = false`, this will also disable motion. * If you need to disable just collision and/or overlap checks, but retain motion, set `checkCollision.none = true`. An object containing allowed collision (none, up, down, left, right). */ checkCollision: FaceChoices; /** * A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World. Should the Body collide with the World bounds? */ collideWorldBounds: boolean; /** * This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate. * Used in combination with your own collision processHandler you can create whatever type of collision response you need. Use a custom separation system or the built-in one? */ customSeparateX: boolean; /** * This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate. * Used in combination with your own collision processHandler you can create whatever type of collision response you need. Use a custom separation system or the built-in one? */ customSeparateY: boolean; /** * The Sprite position is updated based on the delta x/y values. You can set a cap on those (both +-) using deltaMax. */ deltaMax: Phaser.Point; /** * If this Body in a preUpdate (true) or postUpdate (false) state? */ dirty: boolean; /** * The drag applied to the motion of the Body (when {@link Phaser.Physics.Arcade.Body#allowDrag allowDrag} is enabled). Measured in pixels per second squared. */ drag: Phaser.Point; /** * If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true. Body embed value. */ embedded: boolean; /** * A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run. * Default: true */ enable: boolean; /** * A const reference to the direction the Body is traveling or facing: Phaser.NONE, Phaser.LEFT, Phaser.RIGHT, Phaser.UP, or Phaser.DOWN. If the Body is moving on both axes, UP and DOWN take precedence. */ facing: number; /** * If this Body is {@link Phaser.Physics.Arcade.Body#immovable immovable} and moving, and another Body is 'riding' this one, this is the amount of motion the riding Body receives on each axis. */ friction: Phaser.Point; /** * Local reference to game. */ game: Phaser.Game; /** * This Body's local gravity, **added** to any world gravity, unless Body.allowGravity is set to false. */ gravity: Phaser.Point; /** * The calculated width / 2 of the physics body. */ halfWidth: number; /** * The calculated height / 2 of the physics body. */ halfHeight: number; /** * The calculated height of the physics body. */ height: number; /** * An immovable Body will not receive any impacts from other bodies. **Two** immovable Bodies can't separate or exchange momentum and will pass through each other. */ immovable: boolean; /** * If `true` this Body is using circular collision detection. If `false` it is using rectangular. * Use `Body.setCircle` to control the collision shape this Body uses. */ isCircle: boolean; /** * Set by the `moveTo` and `moveFrom` methods. */ isMoving: boolean; /** * The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity. * Default: 1 */ mass: number; /** * The maximum angular velocity in degrees per second that the Body can reach. * Default: 1000 */ maxAngular: number; /** * The maximum velocity (in pixels per second squared) that the Body can reach. */ maxVelocity: Phaser.Point; /** * Whether the physics system should update the Body's position and rotation based on its velocity, acceleration, drag, and gravity. * * If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never * actually changes, then you should set Body.moves = false. Otherwise it will most likely fly off the screen. * If you want the physics system to move the body around, then set moves to true. * * A Body with moves = false can still be moved slightly (but not accelerated) during collision separation unless you set {@link Phaser.Physics.Arcade.Body#immovable immovable} as well. Set to true to allow the Physics system to move this Body, otherwise false to move it manually. * Default: true */ moves: boolean; /** * Optional callback. If set, invoked during the running of `moveTo` or `moveFrom` events. */ movementCallback: any; /** * Context in which to call the movementCallback. */ movementCallbackContext: any; /** * The distanced traveled during the last update, equal to `velocity * physicsElapsed`. Calculated during the Body.preUpdate and applied to its position. */ newVelocity: Phaser.Point; /** * The offset of the Physics Body from the Sprite's texture. */ offset: Phaser.Point; /** * A Signal that is dispatched when this Body collides with another Body. * * You still need to call `game.physics.arcade.collide` in your `update` method in order * for this signal to be dispatched. * * Usually you'd pass a callback to the `collide` method, but this signal provides for * a different level of notification. * * Due to the potentially high volume of signals this could create it is disabled by default. * * To use this feature set this property to a Phaser.Signal: `sprite.body.onCollide = new Phaser.Signal()` * and it will be called when a collision happens, passing two arguments: the sprites which collided. * The first sprite in the argument is always the owner of this Body. * * If two Bodies with this Signal set collide, both will dispatch the Signal. */ onCollide: Phaser.Signal; /** * Listen for the completion of `moveTo` or `moveFrom` events. */ onMoveComplete: Phaser.Signal; /** * A Signal that is dispatched when this Body overlaps with another Body. * * You still need to call `game.physics.arcade.overlap` in your `update` method in order * for this signal to be dispatched. * * Usually you'd pass a callback to the `overlap` method, but this signal provides for * a different level of notification. * * Due to the potentially high volume of signals this could create it is disabled by default. * * To use this feature set this property to a Phaser.Signal: `sprite.body.onOverlap = new Phaser.Signal()` * and it will be called when a collision happens, passing two arguments: the sprites which collided. * The first sprite in the argument is always the owner of this Body. * * If two Bodies with this Signal set collide, both will dispatch the Signal. */ onOverlap: Phaser.Signal; /** * A Signal that is dispatched when this Body collides with the world bounds. * Due to the potentially high volume of signals this could create it is disabled by default. * To use this feature set this property to a Phaser.Signal: `sprite.body.onWorldBounds = new Phaser.Signal()` * and it will be called when a collision happens, passing five arguments: * `onWorldBounds(sprite, up, down, left, right)` * where the Sprite is a reference to the Sprite that owns this Body, and the other arguments are booleans * indicating on which side of the world the Body collided. */ onWorldBounds: Phaser.Signal; /** * When this body collides with another, the amount of overlap is stored here. The amount of horizontal overlap during the collision. */ overlapX: number; /** * When this body collides with another, the amount of overlap is stored here. The amount of vertical overlap during the collision. */ overlapY: number; phase: number; /** * The position of the physics body, equivalent to ({@link Phaser.Physics.Arcade.Body#left left}, {@link Phaser.Physics.Arcade.Body#top top}). */ position: Phaser.Point; /** * The previous rotation of the physics body, in degrees. */ preRotation: number; /** * The previous position of the physics body. */ prev: Phaser.Point; /** * The radius of the circular collision shape this Body is using if Body.setCircle has been enabled, relative to the Sprite's _texture_. * If you wish to change the radius then call {@link Phaser.Physics.Arcade.Body#setCircle setCircle} again with the new value. * If you wish to stop the Body using a circle then call {@link Phaser.Physics.Arcade.Body#setCircle setCircle} with a radius of zero (or undefined). * The actual radius of the Body (at any Sprite scale) is equal to {@link Phaser.Physics.Arcade.Body#halfWidth halfWidth} and the diameter is equal to {@link Phaser.Physics.Arcade.Body#width width}. */ radius: number; /** * The right value of this Body (same as Body.x + Body.width) */ right: number; /** * The Body's rotation in degrees, as calculated by its angularVelocity and angularAcceleration. Please understand that the collision Body * itself never rotates, it is always axis-aligned. However these values are passed up to the parent Sprite and updates its rotation. */ rotation: number; /** * If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree. */ skipQuadTree: boolean; /** * The un-scaled original size. */ sourceWidth: number; /** * The un-scaled original size. */ sourceHeight: number; /** * The speed of the Body in pixels per second, equal to the magnitude of the velocity. */ speed: number; /** * Reference to the parent Sprite. */ sprite: Phaser.Sprite; /** * Set by the `moveTo` and `moveFrom` methods. */ stopVelocityOnCollide: boolean; /** * If true the Body will check itself against the Sprite.getBounds() dimensions and adjust its width and height accordingly. * If false it will compare its dimensions against the Sprite scale instead, and adjust its width height if the scale has changed. * Typically you would need to enable syncBounds if your sprite is the child of a responsive display object such as a FlexLayer, * or in any situation where the Sprite scale doesn't change, but its parents scale is effecting the dimensions regardless. */ syncBounds: boolean; /** * If this is an especially small or fast moving object then it can sometimes skip over tilemap collisions if it moves through a tile in a step. * Set this padding value to add extra padding to its bounds. tilePadding.x applied to its width, y to its height. Extra padding to be added to this sprite's dimensions when checking for tile collision. */ tilePadding: Phaser.Point; /** * This object is populated with boolean values when the Body collides with another. * touching.up = true means the collision happened to the top of this Body for example. An object containing touching results (none, up, down, left, right). */ touching: FaceChoices; /** * The type of physics system this body belongs to. */ type: number; /** * This object is populated with previous touching values from the bodies previous collision. An object containing previous touching results (none, up, down, left, right). */ wasTouching: FaceChoices; /** * The calculated width of the physics body. */ width: number; /** * The elasticity of the Body when colliding with the World bounds. * By default this property is `null`, in which case `Body.bounce` is used instead. Set this property * to a Phaser.Point object in order to enable a World bounds specific bounce value. */ worldBounce: Phaser.Point; /** * The velocity, or rate of change the Body's position. Measured in pixels per second. */ velocity: Phaser.Point; /** * The x position. */ x: number; /** * The y position. */ y: number; /** * Internal method. * @return True if the Body collided with the world bounds, otherwise false. */ checkWorldBounds(): void; /** * Returns the delta x value. The difference between Body.x now and in the previous step. * @return The delta value. Positive if the motion was to the right, negative if to the left. */ deltaX(): number; /** * Returns the delta y value. The difference between Body.y now and in the previous step. * @return The delta value. Positive if the motion was downwards, negative if upwards. */ deltaY(): number; /** * Returns the delta z value. The difference between Body.rotation now and in the previous step. * @return The delta value. Positive if the motion was clockwise, negative if anti-clockwise. */ deltaZ(): number; /** * Returns the absolute delta x value. * @return The absolute delta value. */ deltaAbsX(): number; /** * Returns the absolute delta y value. * @return The absolute delta value. */ deltaAbsY(): number; /** * Destroys this Body. * * First it calls Group.removeFromHash if the Game Object this Body belongs to is part of a Group. * Then it nulls the Game Objects body reference, and nulls this Body.sprite reference. */ destroy(): void; /** * Returns the bounds of this physics body. * * Only used internally by the World collision methods. * * @param obj The object in which to set the bounds values. * @return The object that was given to this method. */ getBounds(obj: any): any; /** * Tests if a world point lies within this Body. * * @param x The world x coordinate to test. * @param y The world y coordinate to test. * @return True if the given coordinates are inside this Body, otherwise false. */ hitTest(x: number, y: number): boolean; /** * Note: This method is experimental, and may be changed or removed in a future release. * * This method moves the Body in the given direction, for the duration specified. * It works by setting the velocity on the Body, and an internal timer, and then * monitoring the duration each frame. When the duration is up the movement is * stopped and the `Body.onMoveComplete` signal is dispatched. * * Movement also stops if the Body collides or overlaps with any other Body. * * You can control if the velocity should be reset to zero on collision, by using * the property `Body.stopVelocityOnCollide`. * * Stop the movement at any time by calling `Body.stopMovement`. * * You can optionally set a speed in pixels per second. If not specified it * will use the current `Body.speed` value. If this is zero, the function will return false. * * Please note that due to browser timings you should allow for a variance in * when the duration will actually expire. Depending on system it may be as much as * +- 50ms. Also this method doesn't take into consideration any other forces acting * on the Body, such as Gravity, drag or maxVelocity, all of which may impact the * movement. * * @param duration The duration of the movement, in ms. * @param speed The speed of the movement, in pixels per second. If not provided `Body.speed` is used. * @param direction The angle of movement. If not provided `Body.angle` is used. * @return True if the movement successfully started, otherwise false. */ moveFrom(duration: number, speed?: number, direction?: number): boolean; /** * Note: This method is experimental, and may be changed or removed in a future release. * * This method moves the Body in the given direction, for the duration specified. * It works by setting the velocity on the Body, and an internal distance counter. * The distance is monitored each frame. When the distance equals the distance * specified in this call, the movement is stopped, and the `Body.onMoveComplete` * signal is dispatched. * * Movement also stops if the Body collides or overlaps with any other Body. * * You can control if the velocity should be reset to zero on collision, by using * the property `Body.stopVelocityOnCollide`. * * Stop the movement at any time by calling `Body.stopMovement`. * * Please note that due to browser timings you should allow for a variance in * when the distance will actually expire. * * Note: This method doesn't take into consideration any other forces acting * on the Body, such as Gravity, drag or maxVelocity, all of which may impact the * movement. * * @param duration The duration of the movement, in ms. * @param distance The distance, in pixels, the Body will move. * @param direction The angle of movement. If not provided `Body.angle` is used. * @return True if the movement successfully started, otherwise false. */ moveTo(duration: number, distance: number, direction?: number): boolean; /** * Returns true if the bottom of this Body is in contact with either the world bounds or a tile. * @return True if in contact with either the world bounds or a tile. */ onFloor(): boolean; /** * Returns true if either side of this Body is in contact with either the world bounds or a tile. * @return True if in contact with either the world bounds or a tile. */ onWall(): boolean; /** * Internal method. */ preUpdate(): void; /** * Internal method. */ postUpdate(): void; /** * Render Sprite Body. * * @param context The context to render to. * @param body The Body to render the info of. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgba(0,255,0,0.4)' * @param filled Render the objected as a filled (default, true) or a stroked (false) - Default: true * @param lineWidth The width of the stroke when unfilled. - Default: 1 */ render(context: any, body: Phaser.Physics.Arcade.Body, color?: string, filled?: boolean, lineWidth?: number): void; /** * Render Sprite Body Physics Data as text. * * @param body The Body to render the info of. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ renderBodyInfo(debug: Phaser.Utils.Debug, body: Phaser.Physics.Arcade.Body): void; /** * Resets all Body values (velocity, acceleration, rotation, etc) * * @param x The new x position of the Body. * @param y The new y position of the Body. */ reset(x: number, y: number): void; /** * Sets this Body as using a circle, of the given radius, for all collision detection instead of a rectangle. * The radius is given in pixels (relative to the Sprite's _texture_) and is the distance from the center of the circle to the edge. * * You can also control the x and y offset, which is the position of the Body relative to the top-left of the Sprite's texture. * * To change a Body back to being rectangular again call `Body.setSize`. * * Note: Circular collision only happens with other Arcade Physics bodies, it does not * work against tile maps, where rectangular collision is the only method supported. * * @param radius The radius of the Body in pixels. Pass a value of zero / undefined, to stop the Body using a circle for collision. * @param offsetX The X offset of the Body from the left of the Sprite's texture. * @param offsetY The Y offset of the Body from the top of the Sprite's texture. */ setCircle(radius: number, offsetX?: number, offsetY?: number): void; /** * You can modify the size of the physics Body to be any dimension you need. * This allows you to make it smaller, or larger, than the parent Sprite. You * can also control the x and y offset of the Body. * * The width, height, and offset arguments are relative to the Sprite * _texture_ and are scaled with the Sprite's {@link Phaser.Sprite#scale} * (but **not** the scale of any ancestors or the {@link Phaser.Camera#scale * Camera scale}). * * For example: If you have a Sprite with a texture that is 80x100 in size, * and you want the physics body to be 32x32 pixels in the middle of the * texture, you would do: * * `setSize(32 / Math.abs(this.scale.x), 32 / Math.abs(this.scale.y), 24, * 34)` * * Where the first two parameters are the new Body size (32x32 pixels) * relative to the Sprite's scale. 24 is the horizontal offset of the Body * from the top-left of the Sprites texture, and 34 is the vertical offset. * * If you've scaled a Sprite by altering its `width`, `height`, or `scale` * and you want to position the Body relative to the Sprite's dimensions * (which will differ from its texture's dimensions), you should divide these * arguments by the Sprite's current scale: * * `setSize(32 / sprite.scale.x, 32 / sprite.scale.y)` * * Calling `setSize` on a Body that has already had `setCircle` will reset * all of the Circle properties, making this Body rectangular again. * * @param width The width of the Body, relative to the Sprite's * texture. * @param height The height of the Body, relative to the Sprite's * texture. * @param offsetX The X offset of the Body from the left of the * Sprite's texture. * @param offsetY The Y offset of the Body from the top of the * Sprite's texture. */ setSize(width: number, height: number, offsetX?: number, offsetY?: number): void; /** * Internal method. */ updateBounds(): boolean; } class FaceChoices { none: boolean; up: boolean; down: boolean; left: boolean; right: boolean; } } /** * Ninja Physics. The Ninja Physics system was created in Flash by Metanet Software and ported to JavaScript by Richard Davey. * * It allows for AABB and Circle to Tile collision. Tiles can be any of 34 different types, including slopes, convex and concave shapes. * * It does what it does very well, but is ripe for expansion and optimisation. Here are some features that I'd love to see the community add: * * * AABB to AABB collision * * AABB to Circle collision * * AABB and Circle 'immovable' property support * * n-way collision, so an AABB/Circle could pass through a tile from below and land upon it. * * QuadTree or spatial grid for faster Body vs. Tile Group look-ups. * * Optimise the internal vector math and reduce the quantity of temporary vars created. * * Expand Gravity and Bounce to allow for separate x/y axis values. * * Support Bodies linked to Sprites that don't have anchor set to 0.5 * * Feel free to attempt any of the above and submit a Pull Request with your code! Be sure to include test cases proving they work. */ class Ninja { /** * Ninja Physics. The Ninja Physics system was created in Flash by Metanet Software and ported to JavaScript by Richard Davey. * * It allows for AABB and Circle to Tile collision. Tiles can be any of 34 different types, including slopes, convex and concave shapes. * * It does what it does very well, but is ripe for expansion and optimisation. Here are some features that I'd love to see the community add: * * * AABB to AABB collision * * AABB to Circle collision * * AABB and Circle 'immovable' property support * * n-way collision, so an AABB/Circle could pass through a tile from below and land upon it. * * QuadTree or spatial grid for faster Body vs. Tile Group look-ups. * * Optimise the internal vector math and reduce the quantity of temporary vars created. * * Expand Gravity and Bounce to allow for separate x/y axis values. * * Support Bodies linked to Sprites that don't have anchor set to 0.5 * * Feel free to attempt any of the above and submit a Pull Request with your code! Be sure to include test cases proving they work. * * @param game reference to the current game instance. */ constructor(game: Phaser.Game); /** * Local reference to game. */ game: Phaser.Game; /** * The World gravity setting. */ gravity: number; /** * The bounds inside of which the physics world exists. Defaults to match the world bounds. */ bounds: Phaser.Rectangle; /** * Used by the QuadTree to set the maximum number of objects per quad. */ maxObjects: number; /** * Used by the QuadTree to set the maximum number of iteration levels. */ maxLevels: number; /** * The world QuadTree. */ quadTree: Phaser.QuadTree; /** * Local reference to game.time. */ time: Phaser.Time; /** * Clears all physics bodies from the given TilemapLayer that were created with `World.convertTilemap`. * * @param map The Tilemap to get the map data from. * @param layer The layer to operate on. If not given will default to map.currentLayer. */ clearTilemapLayerBodies(map: Phaser.Tilemap, layer: any): void; /** * Checks for collision between two game objects. You can perform Sprite vs. Sprite, Sprite vs. Group, Group vs. Group, Sprite vs. Tilemap Layer or Group vs. Tilemap Layer collisions. * The second parameter can be an array of objects, of differing types. * The objects are also automatically separated. If you don't require separation then use ArcadePhysics.overlap instead. * An optional processCallback can be provided. If given this function will be called when two sprites are found to be colliding. It is called before any separation takes place, * giving you the chance to perform additional checks. If the function returns true then the collision and separation is carried out. If it returns false it is skipped. * The collideCallback is an optional function that is only called if two sprites collide. If a processCallback has been set then it needs to return true for collideCallback to be called. * * @param object1 The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter, or Phaser.TilemapLayer. * @param object2 The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group, Phaser.Particles.Emitter or Phaser.TilemapLayer. * @param collideCallback An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them. * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then collision will only happen if processCallback returns true. The two objects will be passed to this function in the same order in which you specified them. * @param callbackContext The context in which to run the callbacks. * @return True if a collision occurred, otherwise false. */ collide(object1: any, object2: any, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean; /** * Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics tiles. * Only call this *after* you have specified all of the tiles you wish to collide with calls like Tilemap.setCollisionBetween, etc. * Every time you call this method it will destroy any previously created bodies and remove them from the world. * Therefore understand it's a very expensive operation and not to be done in a core game update loop. * * In Ninja the Tiles have an ID from 0 to 33, where 0 is 'empty', 1 is a full tile, 2 is a 45-degree slope, etc. You can find the ID * list either at the very bottom of `Tile.js`, or in a handy visual reference in the `resources/Ninja Physics Debug Tiles` folder in the repository. * The slopeMap parameter is an array that controls how the indexes of the tiles in your tilemap data will map to the Ninja Tile IDs. * For example if you had 6 tiles in your tileset: Imagine the first 4 should be converted into fully solid Tiles and the other 2 are 45-degree slopes. * Your slopeMap array would look like this: `[ 1, 1, 1, 1, 2, 3 ]`. * Where each element of the array is a tile in your tilemap and the resulting Ninja Tile it should create. * * @param map The Tilemap to get the map data from. * @param layer The layer to operate on. If not given will default to map.currentLayer. * @param slopeMap The tilemap index to Tile ID map. * @return An array of the Phaser.Physics.Ninja.Tile objects that were created. */ convertTilemap(map: Phaser.Tilemap, layer: any, slopeMap: any): Phaser.Physics.Ninja.Tile[]; /** * This will create a Ninja Physics AABB body on the given game object. Its dimensions will match the width and height of the object at the point it is created. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enableAABB(object: any, children?: boolean): void; /** * This will create a Ninja Physics Circle body on the given game object. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param radius The radius of the Circle. * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enableCircle(object: any, radius: number, children?: boolean): void; /** * This will create a Ninja Physics Tile body on the given game object. There are 34 different types of tile you can create, including 45 degree slopes, * convex and concave circles and more. The id parameter controls which Tile type is created, but you can also change it at run-time. * Note that for all degree based tile types they need to have an equal width and height. If the given object doesn't have equal width and height it will use the width. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param id The type of Tile this will use, i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc. - Default: 1 * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enableTile(object: any, id: number, children?: boolean): void; /** * This will create a Ninja Physics body on the given game object or array of game objects. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param type The type of Ninja shape to create. 1 = AABB, 2 = Circle or 3 = Tile. - Default: 1 * @param id If this body is using a Tile shape, you can set the Tile id here, i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc. - Default: 1 * @param radius If this body is using a Circle shape this controls the radius. * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enable(object: any, type?: number, id?: number, radius?: number, children?: boolean): void; /** * Creates a Ninja Physics body on the given game object. * A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled. * * @param object The game object to create the physics body on. A body will only be created if this object has a null `body` property. */ enableBody(object: any, type?: number, id?: number, radius?: number): void; /** * Checks for overlaps between two game objects. The objects can be Sprites, Groups or Emitters. * You can perform Sprite vs. Sprite, Sprite vs. Group and Group vs. Group overlap checks. * Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results. * The second parameter can be an array of objects, of differing types. * * @param object1 The first object to check. Can be an instance of Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param object2 The second object or array of objects to check. Can be Phaser.Sprite, Phaser.Group or Phaser.Particles.Emitter. * @param overlapCallback An optional callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you specified them. * @param processCallback A 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 processCallback returns true. * @param callbackContext The context in which to run the callbacks. * @return True if an overlap occurred, otherwise false. */ overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean; /** * The core separation function to separate two physics bodies. * * @param body1 The Body object to separate. * @param body2 The Body object to separate. * @return Returns true if the bodies collided, otherwise false. */ separate(body1: Phaser.Physics.Ninja.Body, body2: Phaser.Physics.Ninja.Body, processCallback?: Function, callbackContext?: any, overlapOnly?: boolean): boolean; /** * Updates the size of this physics world. * * @param x Top left most corner of the world. * @param y Top left most corner of the world. * @param width New width of the world. Can never be smaller than the Game.width. * @param height New height of the world. Can never be smaller than the Game.height. */ setBounds(x: number, y: number, width: number, height: number): void; /** * Updates the size of this physics world to match the size of the game world. */ setBoundsToWorld(): void; } module Ninja { /** * The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than * the Sprite itself. For example you can set the velocity, bounce values etc all on the Body. */ class Body { /** * The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than * the Sprite itself. For example you can set the velocity, bounce values etc all on the Body. * * @param system The physics system this Body belongs to. * @param sprite The Sprite object this physics body belongs to. * @param type The type of Ninja shape to create. 1 = AABB, 2 = Circle or 3 = Tile. - Default: 1 * @param id If this body is using a Tile shape, you can set the Tile id here, i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc. - Default: 1 * @param radius If this body is using a Circle shape this controls the radius. - Default: 16 * @param x The x coordinate of this Body. This is only used if a sprite is not provided. * @param y The y coordinate of this Body. This is only used if a sprite is not provided. * @param width The width of this Body. This is only used if a sprite is not provided. * @param height The height of this Body. This is only used if a sprite is not provided. */ constructor(system: Phaser.Physics.Ninja, sprite: Phaser.Sprite, type?: number, id?: number, radius?: number, x?: number, y?: number, width?: number, height?: number); /** * The AABB object this body is using for collision. */ aabb: Phaser.Physics.Ninja.AABB; /** * The angle of this Body */ angle: number; /** * The bottom value of this Body (same as Body.y + Body.height) */ bottom: number; /** * The bounciness of this object when it collides. A value between 0 and 1. We recommend setting it to 0.999 to avoid jittering. * Default: 0.3 */ bounce: number; /** * Set the checkCollision properties to control which directions collision is processed for this Body. * For example checkCollision.up = false means it won't collide when the collision happened while moving up. An object containing allowed collision. */ checkCollision: Phaser.Physics.Arcade.FaceChoices; /** * The Circle object this body is using for collision. */ circle: Phaser.Physics.Ninja.Circle; /** * A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World. Should the Body collide with the World bounds? */ collideWorldBounds: boolean; /** * The drag applied to this object as it moves. * Default: 1 */ drag: number; /** * A const reference to the direction the Body is traveling or facing. */ facing: number; /** * The friction applied to this object as it moves. * Default: 0.05 */ friction: number; /** * Local reference to game. */ game: Phaser.Game; /** * How much of the world gravity should be applied to this object? 1 = all of it, 0.5 = 50%, etc. * Default: 1 */ gravityScale: number; /** * The height of this Body */ height: number; /** * An immovable Body will not receive any impacts from other bodies. Not fully implemented. */ immovable: boolean; /** * The maximum speed this body can travel at (taking drag and friction into account) * Default: 8 */ maxSpeed: number; /** * The right value of this Body (same as Body.x + Body.width) */ right: number; /** * Reference to the parent Sprite. */ sprite: Phaser.Sprite; /** * The parent physics system. */ system: Phaser.Physics.Ninja; /** * The Tile object this body is using for collision. */ tile: Phaser.Physics.Ninja.Tile; /** * This object is populated with boolean values when the Body collides with another. * touching.up = true means the collision happened to the top of this Body for example. An object containing touching results. */ touching: Phaser.Physics.Arcade.FaceChoices; /** * The type of physics system this body belongs to. */ type: number; /** * A local reference to the body shape. */ shape: any; /** * The speed of this Body */ speed: number; /** * The velocity in pixels per second sq. of the Body. */ velocity: Phaser.Point; /** * This object is populated with previous touching values from the bodies previous collision. An object containing previous touching results. */ wasTouching: Phaser.Physics.Arcade.FaceChoices; /** * The width of this Body */ width: number; /** * The x position. */ x: number; /** * The y position. */ y: number; /** * Returns the absolute delta x value. * @return The absolute delta value. */ deltaAbsX(): number; /** * Returns the absolute delta y value. * @return The absolute delta value. */ deltaAbsY(): number; /** * Returns the delta x value. The difference between Body.x now and in the previous step. * @return The delta value. Positive if the motion was to the right, negative if to the left. */ deltaX(): number; /** * Returns the delta y value. The difference between Body.y now and in the previous step. * @return The delta value. Positive if the motion was downwards, negative if upwards. */ deltaY(): number; /** * Destroys this body's reference to the sprite and system, and destroys its shape. */ destroy(): void; /** * Stops all movement of this body. */ setZeroVelocity(): void; moveTo(speed: number, angle: number): void; moveFrom(speed: number, angle: number): void; moveLeft(speed: number): void; moveRight(speed: number): void; moveUp(speed: number): void; moveDown(speed: number): void; poseUpdate(): void; /** * Internal method. */ preUpdate(): void; /** * Render Sprite's Body. * * @param context The context to render to. * @param body The Body to render. * @param color color of the debug shape to be rendered. (format is css color string). - Default: 'rgba(0,255,0,0.4)' * @param filled Render the shape as a filled (default, true) or a stroked (false) - Default: true */ render(context: any, body: Phaser.Physics.Ninja.Body, color?: string, filled?: boolean): void; /** * Resets all Body values and repositions on the Sprite. */ reset(): void; } /** * Ninja Physics AABB constructor. * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. */ class AABB { /** * Ninja Physics AABB constructor. * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. * * @param body The body that owns this shape. * @param x The x coordinate to create this shape at. * @param y The y coordinate to create this shape at. * @param width The width of this AABB. * @param height The height of this AABB. */ constructor(body: Phaser.Physics.Ninja.Body, x: number, y: number, width: number, height: number); static COL_NONE: number; static COL_AXIS: number; static COL_OTHER: number; /** * All of the collision response handlers. */ aabbTileProjections: any; /** * A reference to the body that owns this shape. */ body: Phaser.Physics.Ninja.Body; /** * The height. */ height: number; oldPos: Phaser.Point; /** * The position of this object. */ pos: Phaser.Point; /** * A reference to the physics system. */ system: Phaser.Physics.Ninja; /** * The width. */ width: number; /** * The velocity of this object. */ velocity: Phaser.Point; /** * Half the width. */ xw: number; /** * Half the height. */ yw: number; /** * Collides this AABB against the world bounds. */ collideWorldBounds(): void; /** * Collides this AABB against a AABB. * * @param aabb The AABB to collide against. */ collideAABBVsAABB(aabb: Phaser.Physics.Ninja.AABB): boolean; /** * Collides this AABB against a Tile. * * @param tile The Tile to collide against. */ collideAABBVsTile(tile: Phaser.Physics.Ninja.Tile): boolean; /** * Destroys this AABB's reference to Body and System */ destroy(): void; /** * Updates this AABBs position. */ integrate(): void; /** * Render this AABB for debugging purposes. * * @param context The context to render to. * @param xOffset X offset from AABB's position to render at. * @param yOffset Y offset from AABB's position to render at. * @param color color of the debug shape to be rendered. (format is css color string). * @param filled Render the shape as solid (true) or hollow (false). */ render(context: any, xOffset: number, yOffset: number, color: string, filled: boolean): void; /** * Process a collision partner-agnostic collision response and apply the resulting forces. * * @param px The tangent velocity * @param py The tangent velocity * @param dx Collision normal * @param dy Collision normal */ reportCollision(px: number, py: number, dx: number, dy: number): void; /** * Process a world collision and apply the resulting forces. * * @param px The tangent velocity * @param py The tangent velocity * @param dx Collision normal * @param dy Collision normal */ reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void; /** * Process a body collision and apply the resulting forces. Still very much WIP and doesn't work fully. Feel free to fix! * * @param px The tangent velocity * @param py The tangent velocity * @param dx Collision normal * @param dy Collision normal * @param obj Object this AABB collided with */ reportCollisionVsBody(px: number, py: number, dx: number, dy: number, obj: any): void; /** * Resolves tile collision. * * @param x Penetration depth on the x axis. * @param y Penetration depth on the y axis. * @param body The AABB involved in the collision. * @param tile The Tile involved in the collision. * @return True if the collision was processed, otherwise false. */ resolveTile(x: number, y: number, body: Phaser.Physics.Ninja.AABB, tile: Phaser.Physics.Ninja.Tile): boolean; reverse(): void; } /** * Ninja Physics Circle constructor. * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. */ class Circle { /** * Ninja Physics Circle constructor. * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. * * @param body The body that owns this shape. * @param x The x coordinate to create this shape at. * @param y The y coordinate to create this shape at. * @param radius The radius of this Circle. */ constructor(body: Phaser.Physics.Ninja.Body, x: number, y: number, radius: number); COL_NONE: number; COL_AXIS: number; COL_OTHER: number; /** * A reference to the body that owns this shape. */ body: Phaser.Physics.Ninja.Body; /** * All of the collision response handlers. */ circleTileProjections: { [index: number]: ((x: number, y: number, oH: number, oV: number, obj: Phaser.Physics.Ninja.Circle, t: Phaser.Physics.Ninja.Tile) => number); }; oldPos: Phaser.Point; /** * The height. */ height: number; /** * The position of this object. */ pos: Phaser.Point; /** * The radius of this circle shape. */ radius: number; /** * A reference to the physics system. */ system: Phaser.Physics.Ninja; type: number; /** * The velocity of this object. */ velocity: Phaser.Point; /** * The width. */ width: number; /** * Half the width. */ xw: number; /** * Half the height. */ yw: number; /** * Collides this Circle with a Tile. * * @param t The Tile involved in the collision. * @return True if they collide, otherwise false. */ collideCircleVsTile(tile: Phaser.Physics.Ninja.Tile): boolean; /** * Collides this Circle against the world bounds. */ collideWorldBounds(): void; /** * Destroys this Circle's reference to Body and System */ destroy(): void; distance(dest: number, round?: boolean): number; /** * Updates this Circles position. */ integrate(): void; /** * Render this circle for debugging purposes. * * @param context The context to render to. * @param xOffset X offset from circle's position to render at. * @param yOffset Y offset from circle's position to render at. * @param color color of the debug shape to be rendered. (format is css color string). * @param filled Render the shape as solid (true) or hollow (false). */ render(context: any, xOffset: number, yOffset: number, color: string, filled: boolean): void; /** * Process a world collision and apply the resulting forces. * * @param px The tangent velocity * @param py The tangent velocity * @param dx Collision normal * @param dy Collision normal * @param obj Object this Circle collided with */ reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void; reportCollisionVsBody(px: number, py: number, dx: number, dy: number, obj: any): void; /** * Resolves tile collision. * * @param x Penetration depth on the x axis. * @param y Penetration depth on the y axis. * @param oH Grid / voronoi region. * @param oV Grid / voronoi region. * @param obj The Circle involved in the collision. * @param t The Tile involved in the collision. * @return The result of the collision. */ resolveCircleTile(x: number, y: number, oH: number, oV: number, obj: Phaser.Physics.Ninja.Circle, t: Phaser.Physics.Ninja.Tile): boolean; } enum TileType { TYPE_EMPTY, TYPE_FULL, TYPE_45DEG, TYPE_CONCAVE, TYPE_CONVEX, TYPE_22DEGs, TYPE_22DEGb, TYPE_67DEGs, TYPE_67DEGb, TYPE_HALF } /** * Ninja Physics Tile constructor. * A Tile is defined by its width, height and type. It's type can include slope data, such as 45 degree slopes, or convex slopes. * Understand that for any type including a slope (types 2 to 29) the Tile must be SQUARE, i.e. have an equal width and height. * Also note that as Tiles are primarily used for levels they have gravity disabled and world bounds collision disabled by default. * * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. */ class Tile { /** * Ninja Physics Tile constructor. * A Tile is defined by its width, height and type. It's type can include slope data, such as 45 degree slopes, or convex slopes. * Understand that for any type including a slope (types 2 to 29) the Tile must be SQUARE, i.e. have an equal width and height. * Also note that as Tiles are primarily used for levels they have gravity disabled and world bounds collision disabled by default. * * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. * * @param body The body that owns this shape. * @param x The x coordinate to create this shape at. * @param y The y coordinate to create this shape at. * @param width The width of this AABB. * @param height The height of this AABB. * @param type The type of Ninja shape to create. 1 = AABB, 2 = Circle or 3 = Tile. - Default: 1 */ constructor(body: Phaser.Physics.Ninja.Body, x: number, y: number, width: number, height: number, type?: number); /** * A reference to the body that owns this shape. */ body: Phaser.Physics.Ninja.Body; /** * The bottom value of this Body (same as Body.y + Body.height) */ bottom: number; flipped: boolean; /** * The height. */ height: number; /** * The ID of this Tile. */ id: number; /** * The position of this object in the previous update. */ oldpos: Phaser.Point; /** * The position of this object. */ pos: Phaser.Point; /** * The right value of this Body (same as Body.x + Body.width) */ right: number; rotation: number; /** * A reference to the physics system. */ system: Phaser.Physics.Ninja; /** * The type of this Tile. */ type: Phaser.Physics.Ninja.TileType; /** * The velocity of this object. */ velocity: Phaser.Point; /** * The width. */ width: number; /** * Half the width. */ xw: number; /** * Half the height. */ yw: number; /** * The x position. */ x: number; /** * The y position. */ y: number; /** * Sets this tile to be empty. */ clear(): void; /** * Tiles cannot collide with the world bounds, it's up to you to keep them where you want them. But we need this API stub to satisfy the Body. */ collideWorldBounds(): void; /** * Destroys this Tiles reference to Body and System. */ destroy(): void; /** * Updates this objects position. */ integrate(): void; /** * Process a world collision and apply the resulting forces. * * @param px The tangent velocity * @param py The tangent velocity * @param dx Collision normal * @param dy Collision normal * @param obj Object this Tile collided with */ reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void; /** * Tiles cannot collide with the world bounds, it's up to you to keep them where you want them. But we need this API stub to satisfy the Body. * * @param id The type of Tile this will use, i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc. */ setType(id: number): number; } } /** * This is your main access to the P2 Physics World. * From here you can create materials, listen for events and add bodies into the physics simulation. */ class P2 { /** * This is your main access to the P2 Physics World. * From here you can create materials, listen for events and add bodies into the physics simulation. * * @param game Reference to the current game instance. * @param config Physics configuration object passed in from the game constructor. */ constructor(game: Phaser.Game, config?: any); /** * Enable to automatically apply body damping each step. */ applyDamping: boolean; /** * Enable to automatically apply gravity each step. */ applyGravity: boolean; /** * Enable to automatically apply spring forces each step. */ applySpringForces: boolean; /** * An array of the bodies the world bounds collides with. */ boundsCollidesWith: Phaser.Physics.P2.Body[]; /** * A default collision group. */ boundsCollisionGroup: Phaser.Physics.P2.CollisionGroup; /** * The p2 World configuration object. */ config: any; /** * The context under which the callbacks are fired. */ callbackContext: any; /** * An array containing the collision groups that have been defined in the World. */ collisionGroups: Phaser.Physics.P2.CollisionGroup[]; /** * The default Contact Material being used by the World. */ contactMaterial: Phaser.Physics.P2.ContactMaterial; /** * Set to true if you want to the world to emit the "impact" event. Turning this off could improve performance. */ emitImpactEvent: boolean; /** * A default collision group. */ everythingCollisionGroup: Phaser.Physics.P2.CollisionGroup; /** * The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property. */ frameRate: number; /** * Friction between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair. */ friction: number; /** * Local reference to game. */ game: Phaser.Game; /** * The gravity applied to all bodies each step. */ gravity: Phaser.Physics.P2.InversePointProxy; /** * A local array of all created Materials. */ materials: Phaser.Physics.P2.Material[]; /** * A default collision group. */ nothingCollisionGroup: Phaser.Physics.P2.CollisionGroup; /** * This signal is dispatched when a new Body is added to the World. * * It sends 1 argument: `body` which is the `Phaser.Physics.P2.Body` that was added to the world. */ onBodyAdded: Phaser.Signal; /** * This signal is dispatched when a Body is removed to the World. * * It sends 1 argument: `body` which is the `Phaser.Physics.P2.Body` that was removed from the world. */ onBodyRemoved: Phaser.Signal; /** * This Signal is dispatched when a first contact is created between two bodies. This happens *before* the step has been done. * * It sends 5 arguments: `bodyA`, `bodyB`, `shapeA`, `shapeB` and `contactEquations`. * * It is possible that in certain situations the `bodyA` or `bodyB` values are `null`. You should check for this * in your own code to avoid processing potentially null physics bodies. */ onBeginContact: Phaser.Signal; /** * This signal is dispatched when a Constraint is added to the World. * * It sends 1 argument: `constraint` which is the `Phaser.Physics.P2.Constraint` that was added to the world. */ onConstraintAdded: Phaser.Signal; /** * This signal is dispatched when a Constraint is removed from the World. * * It sends 1 argument: `constraint` which is the `Phaser.Physics.P2.Constraint` that was removed from the world. */ onConstraintRemoved: Phaser.Signal; /** * This signal is dispatched when a Contact Material is added to the World. * * It sends 1 argument: `material` which is the `Phaser.Physics.P2.ContactMaterial` that was added to the world. */ onContactMaterialAdded: Phaser.Signal; /** * This signal is dispatched when a Contact Material is removed from the World. * * It sends 1 argument: `material` which is the `Phaser.Physics.P2.ContactMaterial` that was removed from the world. */ onContactMaterialRemoved: Phaser.Signal; /** * This Signal is dispatched when final contact occurs between two bodies. This happens *before* the step has been done. * * It sends 4 arguments: `bodyA`, `bodyB`, `shapeA` and `shapeB`. * * It is possible that in certain situations the `bodyA` or `bodyB` values are `null`. You should check for this * in your own code to avoid processing potentially null physics bodies. */ onEndContact: Phaser.Signal; /** * This signal is dispatched when a Spring is added to the World. * * It sends 1 argument: `spring` which is either a `Phaser.Physics.P2.Spring`, `p2.LinearSpring` or `p2.RotationalSpring` that was added to the world. */ onSpringAdded: Phaser.Signal; /** * This signal is dispatched when a Spring is removed from the World. * * It sends 1 argument: `spring` which is either a `Phaser.Physics.P2.Spring`, `p2.LinearSpring` or `p2.RotationalSpring` that was removed from the world. */ onSpringRemoved: Phaser.Signal; /** * The paused state of the P2 World. */ paused: boolean; postBroaddphaseCallback: Function; /** * Default coefficient of restitution between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair. */ restitution: number; /** * Enable/disable constraint solving in each step. */ solveConstraints: boolean; /** * The World time. */ time: any; /** * The total number of bodies in the world. */ total: number; /** * If true the frameRate value will be ignored and instead p2 will step with the value of Game.Time.delta, which is a delta time value. */ useElapsedTime: boolean; /** * An object containing the 4 wall bodies that bound the physics world. */ walls: { left?: Phaser.Physics.P2.Body; right?: Phaser.Physics.P2.Body; top?: Phaser.Physics.P2.Body; bottom?: Phaser.Physics.P2.Body; }; /** * The p2 World in which the simulation is run. */ world: p2.World; /** * Add a body to the world. * * @param body The Body to add to the World. * @return True if the Body was added successfully, otherwise false. */ addBody(body: Phaser.Physics.P2.Body): boolean; /** * Adds a Contact Material to the world. * * @param material The Contact Material to be added to the World. * @return The Contact Material that was added. */ addContactMaterial(material: Phaser.Physics.P2.ContactMaterial): Phaser.Physics.P2.ContactMaterial; /** * Adds a Constraint to the world. * * @param constraint The Constraint to add to the World. * @return The Constraint that was added. */ addConstraint(constraint: T): T; /** * Adds a Spring to the world. * * @param spring The Spring to add to the World. * @return The Spring that was added. */ addSpring(spring: Phaser.Physics.P2.Spring): Phaser.Physics.P2.Spring; /** * Handles a p2 begin contact event. * * @param event The event data. */ beginContactHandler(event: any): void; /** * Clears all bodies from the simulation, resets callbacks and resets the collision bitmask. * * The P2 world is also cleared: * * * Removes all solver equations * * Removes all constraints * * Removes all bodies * * Removes all springs * * Removes all contact materials * * This is called automatically when you switch state. */ clear(): void; /** * Clears all physics bodies from the given TilemapLayer that were created with `World.convertTilemap`. * * @param map The Tilemap to get the map data from. * @param layer The layer to operate on. If not given will default to map.currentLayer. */ clearTilemapLayerBodies(map: Phaser.Tilemap, layer?: any): void; /** * Converts all of the polyline, polygon, and rectangle objects inside a Tiled ObjectGroup into physics bodies that are added to the world. * Note that the polylines and polygons must be created in such a way that they can withstand polygon decomposition. * * @param map The Tilemap to get the map data from. * @param layer The layer to operate on. If not given will default to map.currentLayer. * @param addToWorld If true it will automatically add each body to the world. - Default: true * @return An array of the Phaser.Physics.Body objects that have been created. */ convertCollisionObjects(map: Phaser.Tilemap, layer?: any, addToWorld?: boolean): Phaser.Physics.P2.Body[]; /** * Goes through all tiles in the given Tilemap and TilemapLayer and converts those set to collide into physics bodies. * Only call this *after* you have specified all of the tiles you wish to collide with calls like Tilemap.setCollisionBetween, etc. * Every time you call this method it will destroy any previously created bodies and remove them from the world. * Therefore understand it's a very expensive operation and not to be done in a core game update loop. * * @param map The Tilemap to get the map data from. * @param layer The layer to operate on. If not given will default to map.currentLayer. * @param addToWorld If true it will automatically add each body to the world, otherwise it's up to you to do so. - Default: true * @param optimize If true adjacent colliding tiles will be combined into a single body to save processing. However it means you cannot perform specific Tile to Body collision responses. - Default: true * @return An array of the Phaser.Physics.P2.Body objects that were created. */ convertTilemap(map: Phaser.Tilemap, layer?: any, addToWorld?: Boolean, optimize?: boolean): Phaser.Physics.P2.Body[]; /** * Creates a new Body and adds it to the World. * * @param x The x coordinate of Body. * @param y The y coordinate of Body. * @param mass The mass of the Body. A mass of 0 means a 'static' Body is created. * @param addToWorld Automatically add this Body to the world? (usually false as it won't have any shapes on construction). * @param options An object containing the build options: * @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices. * @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. * @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. * @param points An array of 2d vectors that form the convex or concave polygon. * Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], * or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers. * @return The body */ createBody(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[][]): Phaser.Physics.P2.Body; /** * Creates a new Body and adds it to the World. * * @param x The x coordinate of Body. * @param y The y coordinate of Body. * @param mass The mass of the Body. A mass of 0 means a 'static' Body is created. * @param addToWorld Automatically add this Body to the world? (usually false as it won't have any shapes on construction). * @param options An object containing the build options: * @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices. * @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. * @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. * @param points An array of 2d vectors that form the convex or concave polygon. * Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], * or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers. * @return The body */ createBody(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[]): Phaser.Physics.P2.Body; /** * Creates a new Collision Group and optionally applies it to the given object. * Collision Groups are handled using bitmasks, therefore you have a fixed limit you can create before you need to re-use older groups. * * @param object An optional Sprite or Group to apply the Collision Group to. If a Group is given it will be applied to all top-level children. */ createCollisionGroup(group?: Phaser.Group): Phaser.Physics.P2.CollisionGroup; /** * Creates a new Collision Group and optionally applies it to the given object. * Collision Groups are handled using bitmasks, therefore you have a fixed limit you can create before you need to re-use older groups. * * @param object An optional Sprite or Group to apply the Collision Group to. If a Group is given it will be applied to all top-level children. */ createCollisionGroup(group?: Phaser.Sprite): Phaser.Physics.P2.CollisionGroup; /** * Creates a Contact Material from the two given Materials. You can then edit the properties of the Contact Material directly. * * @param materialA The first Material to create the ContactMaterial from. If undefined it will create a new Material object first. * @param materialB The second Material to create the ContactMaterial from. If undefined it will create a new Material object first. * @param options Material options object. * @return The Contact Material that was created. */ createContactMaterial(materialA: Phaser.Physics.P2.Material, materialB: Phaser.Physics.P2.Material, options?: p2.ContactMaterialOptions): Phaser.Physics.P2.ContactMaterial; /** * Creates a constraint that tries to keep the distance between two bodies constant. * * @param bodyA First connected body. * @param bodyB Second connected body. * @param distance The distance to keep between the bodies. * @param localAnchorA The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0]. * @param localAnchorB The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0]. * @param maxForce The maximum force that should be applied to constrain the bodies. * @return The constraint */ createDistanceConstraint(bodyA: any, bodyB: any, distance: number, localAnchorA?: number[], localAnchorB?: number[], maxForce?: number): Phaser.Physics.P2.DistanceConstraint; /** * Creates a constraint that tries to keep the relative angle between two bodies constant. * * @param bodyA First connected body. * @param bodyB Second connected body. * @param angle The relative angle * @param ratio The gear ratio. - Default: 1 * @return The constraint */ createGearConstraint(bodyA: any, bodyB: any, angle?: number, ratio?: number): Phaser.Physics.P2.GearConstraint; /** * Locks the relative position between two bodies. * * @param bodyA First connected body. * @param bodyB Second connected body. * @param offset The offset of bodyB in bodyA's frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param angle The angle of bodyB in bodyA's frame. * @param maxForce The maximum force that should be applied to constrain the bodies. * @return The constraint */ createLockConstraint(bodyA: any, bodyB: any, offset?: number[], angle?: number, maxForce?: number): Phaser.Physics.P2.LockConstraint; /** * Creates a Material. Materials are applied to Shapes owned by a Body and can be set with Body.setMaterial(). * Materials are a way to control what happens when Shapes collide. Combine unique Materials together to create Contact Materials. * Contact Materials have properties such as friction and restitution that allow for fine-grained collision control between different Materials. * * @param name Optional name of the Material. Each Material has a unique ID but string names are handy for debugging. * @param body Optional Body. If given it will assign the newly created Material to the Body shapes. * @return The Material that was created. This is also stored in Phaser.Physics.P2.materials. */ createMaterial(name?: string, body?: Phaser.Physics.P2.Body): Phaser.Physics.P2.Material; /** * Creates a new Particle and adds it to the World. * * @param x The x coordinate of Body. * @param y The y coordinate of Body. * @param mass The mass of the Body. A mass of 0 means a 'static' Body is created. * @param addToWorld Automatically add this Body to the world? (usually false as it won't have any shapes on construction). * @param options An object containing the build options: * @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices. * @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. * @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. * @param points An array of 2d vectors that form the convex or concave polygon. * Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], * or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers. */ createParticle(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[][]): Phaser.Physics.P2.Body; /** * Creates a new Particle and adds it to the World. * * @param x The x coordinate of Body. * @param y The y coordinate of Body. * @param mass The mass of the Body. A mass of 0 means a 'static' Body is created. * @param addToWorld Automatically add this Body to the world? (usually false as it won't have any shapes on construction). * @param options An object containing the build options: * @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices. * @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. * @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. * @param points An array of 2d vectors that form the convex or concave polygon. * Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], * or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers. */ createParticle(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[]): Phaser.Physics.P2.Body; /** * Constraint that only allows bodies to move along a line, relative to each other. * See http://www.iforce2d.net/b2dtut/joints-prismatic * * @param bodyA First connected body. * @param bodyB Second connected body. * @param lockRotation If set to false, bodyB will be free to rotate around its anchor point. - Default: true * @param anchorA Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param anchorB Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param axis An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param maxForce The maximum force that should be applied to constrain the bodies. * @return The constraint */ createPrismaticConstraint(body: any, bodyB: any, lockRotation?: boolean, anchorA?: number[], anchorB?: number[], axis?: Float32Array, maxForce?: number): Phaser.Physics.P2.PrismaticConstraint; /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. * The pivot points are given in world (pixel) coordinates. * * @param bodyA First connected body. * @param pivotA The point relative to the center of mass of bodyA which bodyA is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param bodyB Second connected body. * @param pivotB The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param maxForce The maximum force that should be applied to constrain the bodies. * @param worldPivot A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value. * @return The constraint */ createRevoluteConstraint(bodyA: any, pivotA: number[], bodyB: any, pivotB: number[], maxForce?: number, worldPivot?: number[]): Phaser.Physics.P2.RevoluteConstraint; /** * Creates a rotational spring, connecting two bodies. A spring can have a resting length, a stiffness and damping. * * @param bodyA First connected body. * @param bodyB Second connected body. * @param restAngle The relative angle of bodies at which the spring is at rest. If not given, it's set to the current relative angle between the bodies. * @param stiffness Stiffness of the spring. A number >= 0. - Default: 100 * @param damping Damping of the spring. A number >= 0. - Default: 1 * @return The spring */ createRotationalSpring(bodyA: any, bodyB: any, restAngle?: number, stiffness?: number, damping?: number): p2.RotationalSpring; /** * Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping. * * @param bodyA First connected body. * @param bodyB Second connected body. * @param restLength Rest length of the spring. A number > 0. - Default: 1 * @param stiffness Stiffness of the spring. A number >= 0. - Default: 100 * @param damping Damping of the spring. A number >= 0. - Default: 1 * @param worldA Where to hook the spring to body A in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32]. * @param worldB Where to hook the spring to body B in world coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32]. * @param localA Where to hook the spring to body A in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32]. * @param localB Where to hook the spring to body B in local body coordinates. This value is an array by 2 elements, x and y, i.e: [32, 32]. * @return The spring */ createSpring(bodyA: any, bodyB: any, restLength?: number, stiffness?: number, damping?: number, worldA?: number[], worldB?: number[], localA?: number[], localB?: number[]): Phaser.Physics.P2.Spring; /** * Clears all bodies from the simulation and unlinks World from Game. Should only be called on game shutdown. Call `clear` on a State change. */ destroy(): void; /** * This will create a P2 Physics body on the given game object or array of game objects. * A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed. * Note: When the game object is enabled for P2 physics it has its anchor x/y set to 0.5 so it becomes centered. * * @param object The game object to create the physics body on. Can also be an array or Group of objects, a body will be created on every child that has a `body` property. * @param debug Create a debug object to go with this body? * @param children Should a body be created on all children of this object? If true it will recurse down the display list as far as it can go. - Default: true */ enable(object: any, debug?: boolean, children?: boolean): void; /** * Creates a P2 Physics body on the given game object. * A game object can only have 1 physics body active at any one time, and it can't be changed until the body is nulled. * * @param object The game object to create the physics body on. A body will only be created if this object has a null `body` property. * @param debug Create a debug object to go with this body? */ enableBody(object: any, debug: boolean): void; /** * Handles a p2 end contact event. * * @param event The event data. */ endContactHandler(event: any): void; /** * Populates and returns an array with references to of all current Bodies in the world. * @return An array containing all current Bodies in the world. */ getBodies(): Phaser.Physics.P2.Body[]; /** * Checks the given object to see if it has a p2.Body and if so returns it. * * @param object The object to check for a p2.Body on. * @return The p2.Body, or null if not found. */ getBody(object: any): Phaser.Physics.P2.Body; /** * Populates and returns an array of all current Constraints in the world. * You will get an array of p2 constraints back. This can be of mixed types, for example the array may contain * PrismaticConstraints, RevoluteConstraints or any other valid p2 constraint type. * @return An array containing all current Constraints in the world. */ getConstraints(): p2.Constraint[]; /** * Populates and returns an array of all current Springs in the world. * @return An array containing all current Springs in the world. */ getSprings(): Phaser.Physics.P2.Spring[]; /** * Gets a Contact Material based on the two given Materials. * * @param materialA The first Material to search for. * @param materialB The second Material to search for. * @return The Contact Material or false if none was found matching the Materials given. */ getContactMaterial(materialA: Phaser.Physics.P2.Material, materialB: Phaser.Physics.P2.Material): Phaser.Physics.P2.ContactMaterial; /** * Test if a world point overlaps bodies. You will get an array of actual P2 bodies back. You can find out which Sprite a Body belongs to * (if any) by checking the Body.parent.sprite property. Body.parent is a Phaser.Physics.P2.Body property. * * @param worldPoint Point to use for intersection tests. The points values must be in world (pixel) coordinates. * @param bodies A list of objects to check for intersection. If not given it will check Phaser.Physics.P2.world.bodies (i.e. all world bodies) * @param precision Used for matching against particles and lines. Adds some margin to these infinitesimal objects. - Default: 5 * @param filterStatic If true all Static objects will be removed from the results array. * @return Array of bodies that overlap the point. */ hitTest(worldPoint: Phaser.Point, bodies?: any[], precision?: number, filterStatic?: boolean): Phaser.Physics.P2.Body[]; /** * Convert p2 physics value (meters) to pixel scale. * By default Phaser uses a scale of 20px per meter. * If you need to modify this you can over-ride these functions via the Physics Configuration object. * * @param v The value to convert. * @return The scaled value. */ mpx(v: number): number; /** * Convert p2 physics value (meters) to pixel scale and inverses it. * By default Phaser uses a scale of 20px per meter. * If you need to modify this you can over-ride these functions via the Physics Configuration object. * * @param v The value to convert. * @return The scaled value. */ mpxi(v: number): number; /** * Pauses the P2 World independent of the game pause state. */ pause(): void; /** * Called at the start of the core update loop. Purges flagged bodies from the world. */ preUpdate(): void; /** * Convert pixel value to p2 physics scale (meters). * By default Phaser uses a scale of 20px per meter. * If you need to modify this you can over-ride these functions via the Physics Configuration object. * * @param v The value to convert. * @return The scaled value. */ pxm(v: number): number; /** * Convert pixel value to p2 physics scale (meters) and inverses it. * By default Phaser uses a scale of 20px per meter. * If you need to modify this you can over-ride these functions via the Physics Configuration object. * * @param v The value to convert. * @return The scaled value. */ pxmi(v: number): number; /** * Removes a body from the world. This will silently fail if the body wasn't part of the world to begin with. * * @param body The Body to remove from the World. * @return The Body that was removed. */ removeBody(body: Phaser.Physics.P2.Body): Phaser.Physics.P2.Body; /** * This will add a P2 Physics body into the removal list for the next step. * * @param body The body to remove at the start of the next step. */ removeBodyNextStep(body: Phaser.Physics.P2.Body): void; /** * Removes a Constraint from the world. * * @param constraint The Constraint to be removed from the World. * @return The Constraint that was removed. */ removeConstraint(constraint: T): T; /** * Removes a Contact Material from the world. * * @param material The Contact Material to be removed from the World. * @return The Contact Material that was removed. */ removeContactMaterial(material: Phaser.Physics.P2.ContactMaterial): Phaser.Physics.P2.ContactMaterial; /** * Removes a Spring from the world. * * @param spring The Spring to remove from the World. * @return The Spring that was removed. */ removeSpring(spring: Phaser.Physics.P2.Spring): Phaser.Physics.P2.Spring; /** * Called by Phaser.Physics when a State swap occurs. * Starts the begin and end Contact listeners again. */ reset(): void; /** * Resumes a paused P2 World. */ resume(): void; /** * 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 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 * @param setCollisionGroup If true the Bounds will be set to use its own Collision Group. - Default: true */ setBounds(x: number, y: number, width: number, height: number, left?: Boolean, right?: boolean, top?: boolean, bottom?: boolean, setCollisionGroup?: boolean): void; setBoundsToWorld(left?: boolean, right?: boolean, top?: boolean, bottom?: boolean, setCollisionGroup?: boolean): void; setCollisionGroup(object: any, group: Phaser.Physics.P2.CollisionGroup): void; /** * Impact event handling is disabled by default. Enable it before any impact events will be dispatched. * In a busy world hundreds of impact events can be generated every step, so only enable this if you cannot do what you need via beginContact or collision masks. * * @param state Set to true to enable impact events, or false to disable. */ setImpactEvents(state: boolean): void; /** * Sets the given Material against all Shapes owned by all the Bodies in the given array. * * @param material The Material to be applied to the given Bodies. * @param bodies An Array of Body objects that the given Material will be set on. */ setMaterial(material: Phaser.Physics.P2.Material, bodies?: Phaser.Physics.P2.Body[]): void; /** * Sets a callback to be fired after the Broadphase has collected collision pairs in the world. * Just because a pair exists it doesn't mean they *will* collide, just that they potentially could do. * If your calback returns `false` the pair will be removed from the narrowphase. This will stop them testing for collision this step. * Returning `true` from the callback will ensure they are checked in the narrowphase. * * @param callback The callback that will receive the postBroadphase event data. It must return a boolean. Set to null to disable an existing callback. * @param context The context under which the callback will be fired. */ setPostBroadphaseCallback(callback: Function, context: any): void; setWorldMaterial(material: Phaser.Physics.P2.Material, left?: boolean, right?: boolean, top?: boolean, bottom?: boolean): void; /** * Converts the current world into a JSON object. * @return A JSON representation of the world. */ toJSON(): any; /** * Internal P2 update loop. */ update(): void; /** * By default the World will be set to collide everything with everything. The bounds of the world is a Body with 4 shapes, one for each face. * If you start to use your own collision groups then your objects will no longer collide with the bounds. * To fix this you need to adjust the bounds to use its own collision group first BEFORE changing your Sprites collision group. * * @param setCollisionGroup If true the Bounds will be set to use its own Collision Group. - Default: true */ updateBoundsCollisionGroup(setCollisionGroup?: boolean): void; } module P2 { /** * The Physics Body is typically linked to a single Sprite and defines properties that determine how the physics body is simulated. * These properties affect how the body reacts to forces, what forces it generates on itself (to simulate friction), and how it reacts to collisions in the scene. * In most cases, the properties are used to simulate physical effects. Each body also has its own property values that determine exactly how it reacts to forces and collisions in the scene. * By default a single Rectangle shape is added to the Body that matches the dimensions of the parent Sprite. See addShape, removeShape, clearShapes to add extra shapes around the Body. * Note: When bound to a Sprite to avoid single-pixel jitters on mobile devices we strongly recommend using Sprite sizes that are even on both axis, i.e. 128x128 not 127x127. * Note: When a game object is given a P2 body it has its anchor x/y set to 0.5, so it becomes centered. */ class Body { /** * Dynamic body. Dynamic bodies body can move and respond to collisions and forces. */ static DYNAMIC: number; /** * Static body. Static bodies do not move, and they do not respond to forces or collision. */ static STATIC: number; /** * Kinematic body. Kinematic bodies only moves according to its .velocity, and does not respond to collisions or force. */ static KINEMATIC: number; /** * The Physics Body is typically linked to a single Sprite and defines properties that determine how the physics body is simulated. * These properties affect how the body reacts to forces, what forces it generates on itself (to simulate friction), and how it reacts to collisions in the scene. * In most cases, the properties are used to simulate physical effects. Each body also has its own property values that determine exactly how it reacts to forces and collisions in the scene. * By default a single Rectangle shape is added to the Body that matches the dimensions of the parent Sprite. See addShape, removeShape, clearShapes to add extra shapes around the Body. * Note: When bound to a Sprite to avoid single-pixel jitters on mobile devices we strongly recommend using Sprite sizes that are even on both axis, i.e. 128x128 not 127x127. * Note: When a game object is given a P2 body it has its anchor x/y set to 0.5, so it becomes centered. * * @param game Game reference to the currently running game. * @param sprite The Sprite object this physics body belongs to. * @param x The x coordinate of this Body. * @param y The y coordinate of this Body. * @param mass The default mass of this Body (0 = static). - Default: 1 */ constructor(game: Phaser.Game, sprite?: Phaser.Sprite, x?: number, y?: number, mass?: number); /** * - */ allowSleep: boolean; /** * The angle of the Body in degrees from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement Body.angle = 450 is the same as Body.angle = 90. * If you wish to work in radians instead of degrees use the property Body.rotation instead. Working in radians is faster as it doesn't have to convert values. The angle of this Body in degrees. */ angle: number; /** * Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second. The angular damping acting acting on the body. */ angularDamping: number; /** * The angular force acting on the body. */ angularForce: number; /** * The angular velocity of the body. */ angularVelocity: number; /** * Array of CollisionGroups that this Bodies shapes collide with. */ collidesWith: Phaser.Physics.P2.CollisionGroup[]; /** * A Body can be set to collide against the World bounds automatically if this is set to true. Otherwise it will leave the World. * Note that this only applies if your World has bounds! The response to the collision should be managed via CollisionMaterials. * Also note that when you set this it will only affect Body shapes that already exist. If you then add further shapes to your Body * after setting this it will *not* proactively set them to collide with the bounds. Should the Body collide with the World bounds? * Default: true */ collideWorldBounds: boolean; /** * Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second. The linear damping acting on the body in the velocity direction. */ damping: number; /** * The p2 Body data. */ data: p2.Body; /** * Enable or disable debug drawing of this body */ debug: boolean; /** * Reference to the debug body. */ debugBody: Phaser.Physics.P2.BodyDebug; /** * Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static. */ dynamic: boolean; /** * - */ fixedRotation: boolean; /** * The force applied to the body. */ force: Phaser.Physics.P2.InversePointProxy; /** * Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static. */ kinematic: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * A locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented. */ gravity: Phaser.Point; /** * The Body ID. Each Body that has been added to the World has a unique ID. */ id: number; /** * The inertia of the body around the Z axis.. */ inertia: number; /** * The mass of the body. */ mass: number; /** * The type of motion this body has. Should be one of: Body.STATIC (the body does not move), Body.DYNAMIC (body can move and respond to collisions) and Body.KINEMATIC (only moves according to its .velocity). */ motionState: number; /** * The offset of the Physics Body from the Sprite x/y position. */ offset: Phaser.Point; /** * Dispatched when a first contact is created between shapes in two bodies. * This event is fired during the step, so collision has already taken place. * * The event will be sent 5 arguments in this order: * * The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world. * The p2.Body this Body is in contact with. * The Shape from this body that caused the contact. * The Shape from the contact body. * The Contact Equation data array. */ onBeginContact: Phaser.Signal; /** * Dispatched when contact ends between shapes in two bodies. * This event is fired during the step, so collision has already taken place. * * The event will be sent 4 arguments in this order: * * The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world. * The p2.Body this Body has ended contact with. * The Shape from this body that caused the original contact. * The Shape from the contact body. */ onEndContact: Phaser.Signal; /** * The angle of the Body in radians. * If you wish to work in degrees instead of radians use the Body.angle property instead. Working in radians is faster as it doesn't have to convert values. The angle of this Body in radians. */ rotation: number; /** * To avoid deleting this body during a physics step, and causing all kinds of problems, set removeNextStep to true to have it removed in the next preUpdate. */ removeNextStep: boolean; /** * Reference to the parent Sprite. */ sprite: Phaser.Sprite; /** * . */ sleepSpeedLimit: number; /** * Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic. */ static: boolean; /** * The type of physics system this body belongs to. */ type: number; /** * The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down. */ velocity: Phaser.Physics.P2.InversePointProxy; /** * Local reference to the P2 World. */ world: Phaser.Physics.P2; /** * The x coordinate of this Body. */ x: number; /** * The y coordinate of this Body. */ y: number; /** * Adds this physics body to the world. */ addToWorld(): void; /** * Adds a Capsule shape to this Body. * You can control the offset from the center of the body and the rotation. * * @param length The distance between the end points in pixels. * @param radius Radius of the capsule in pixels. * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Capsule shape that was added to the Body. */ addCapsule(length: number, radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Capsule; /** * Adds a Circle shape to this Body. You can control the offset from the center of the body and the rotation. * * @param radius The radius of this circle (in pixels) * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Circle shape that was added to the Body. */ addCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle; /** * Add a polygon fixture. This is used during #loadPolygon. * * @param fixtureData The data for the fixture. It contains: isSensor, filter (collision) and the actual polygon shapes. * @return An array containing the generated shapes for the given polygon. */ addFixture(fixtureData: string): p2.Shape[]; /** * Adds a Line shape to this Body. * The line shape is along the x direction, and stretches from [-length/2, 0] to [length/2,0]. * You can control the offset from the center of the body and the rotation. * * @param length The length of this line (in pixels) * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Line shape that was added to the Body. */ addLine(length: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Line; /** * Adds a Particle shape to this Body. You can control the offset from the center of the body and the rotation. * * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Particle shape that was added to the Body. */ addParticle(offsetX?: number, offsetY?: number, rotation?: number): p2.Particle; /** * Reads a polygon shape path, and assembles convex shapes from that and puts them at proper offset points. The shape must be simple and without holes. * This function expects the x.y values to be given in pixels. If you want to provide them at p2 world scales then call Body.data.fromPolygon directly. * * @param options An object containing the build options: * @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices. * @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. * @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. * @param points An array of 2d vectors that form the convex or concave polygon. * Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...]. In the first form **the array will mutate**. * Or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers. * @return True on success, else false. */ addPolygon(options: { optimalDecomp?: boolean; skipSimpleCheck?: boolean; removeCollinearPoints?: boolean; }, points: number[][]): boolean; /** * Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body. * The shape data format is based on the output of the * {@link https://github.com/photonstorm/phaser/tree/master/resources/PhysicsEditor%20Exporter|custom phaser exporter} for * {@link https://www.codeandweb.com/physicseditor|PhysicsEditor} * * @param key The key of the Physics Data file as stored in Game.Cache. * @param object The key of the object within the Physics data file that you wish to load the shape data from. * @return A list of created fixtures to be used with Phaser.Physics.P2.FixtureList */ addPhaserPolygon(key: string, object: string): Phaser.Physics.P2.FixtureList; /** * Adds a Plane shape to this Body. The plane is facing in the Y direction. You can control the offset from the center of the body and the rotation. * * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Plane shape that was added to the Body. */ addPlane(offsetX?: number, offsetY?: number, rotation?: number): p2.Plane; /** * Adds a Rectangle shape to this Body. You can control the offset from the center of the body and the rotation. * * @param width The width of the rectangle in pixels. * @param height The height of the rectangle in pixels. * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The shape that was added to the Body. */ addRectangle(width: number, height: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle; /** * Add a shape to the body. You can pass a local transform when adding a shape, so that the shape gets an offset and an angle relative to the body center of mass. * Will automatically update the mass properties and bounding radius. * If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates. * * @param shape The shape to add to the body. * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The shape that was added to the body. */ addShape(shape: p2.Shape, offsetX?: number, offsetY?: number, rotation?: number): p2.Shape; /** * Moves the shape offsets so their center of mass becomes the body center of mass. */ adjustCenterOfMass(): void; /** * Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details. * * @param dt Current time step. */ applyDamping(dt: number): void; /** * Apply force to a world point. * * This could for example be a point on the RigidBody surface. Applying force * this way will add to Body.force and Body.angularForce. * * @param force The force vector to add. * @param worldX The world x point to apply the force on. * @param worldY The world y point to apply the force on. */ applyForce(force: number[], worldX: number, worldY: number): void; /** * Apply impulse to a point relative to the body. * This could for example be a point on the Body surface. An impulse is a force added to a body during a short * period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity. * * @param impulse The impulse vector to add, oriented in world space. * @param worldX A point relative to the body in world space. If not given, it is set to zero and all of the impulse will be exerted on the center of mass. * @param worldY A point relative to the body in world space. If not given, it is set to zero and all of the impulse will be exerted on the center of mass. */ applyImpulse(impulse: number[], worldX: number, worldY: number): void; /** * Apply impulse to a point local to the body. * * This could for example be a point on the Body surface. An impulse is a force added to a body during a short * period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity. * * @param impulse The impulse vector to add, oriented in local space. * @param localX A local point on the body. * @param localY A local point on the body. */ applyImpulseLocal(impulse: number[], localX: number, localY: number): void; /** * Clears the collision data from the shapes in this Body. Optionally clears Group and/or Mask. * * @param clearGroup Clear the collisionGroup value from the shape/s? - Default: true * @param clearMask Clear the collisionMask value from the shape/s? - Default: true * @param shape An optional Shape. If not provided the collision data will be cleared from all Shapes in this Body. */ clearCollision(clearGroup?: boolean, cleanMask?: boolean, shape?: p2.Shape): void; /** * Removes all Shapes from this Body. */ clearShapes(): void; /** * Adds the given CollisionGroup, or array of CollisionGroups, to the list of groups that this body will collide with and updates the collision masks. * * @param group The Collision Group or Array of Collision Groups that this Bodies shapes will collide with. * @param callback Optional callback that will be triggered when this Body impacts with the given Group. * @param callbackContext The context under which the callback will be called. * @param shape An optional Shape. If not provided the collision mask will be added to all Shapes in this Body. */ collides(group: any, callback?: Function, callbackContext?: any, shape?: p2.Shape): void; /** * Sets a callback to be fired any time a shape in this Body impacts with a shape in the given Body. The impact test is performed against body.id values. * The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body. * Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening. * It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate. * * @param object The object to send impact events for. * @param callback The callback to fire on impact. Set to null to clear a previously set callback. * @param callbackContext The context under which the callback will fire. */ createBodyCallback(object: any, callback: Function, callbackContext?: any): void; /** * Sets a callback to be fired any time this Body impacts with the given Group. The impact test is performed against shape.collisionGroup values. * The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body. * This callback will only fire if this Body has been assigned a collision group. * Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening. * It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate. * * @param group The Group to send impact events for. * @param callback The callback to fire on impact. Set to null to clear a previously set callback. * @param callbackContext The context under which the callback will fire. */ createGroupCallback(group: Phaser.Physics.P2.CollisionGroup, callback: Function, callbackContext?: any): void; /** * Destroys this Body and all references it holds to other objects. */ destroy(): void; /** * Gets the collision bitmask from the groups this body collides with. * @return The bitmask. */ getCollisionMask(): number; /** * Gets the velocity of a point in the body. * * @param result A vector to store the result in. * @param relativePoint A world oriented vector, indicating the position of the point to get the velocity from. * @return The result vector. */ getVelocityAtPoint(result: number[], relativePoint: number[]): number[]; /** * Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body. * * As well as reading the data from the Cache you can also pass `null` as the first argument and a * physics data object as the second. When doing this you must ensure the structure of the object is correct in advance. * * For more details see the format of the Lime / Corona Physics Editor export. * * @param key The key of the Physics Data file as stored in Game.Cache. Alternatively set to `null` and pass the * data as the 2nd argument. * @param object The key of the object within the Physics data file that you wish to load the shape data from, * or if key is null pass the actual physics data object itself as this parameter. * @param scale Optionally resize the loaded polygon. - Default: 1 * @return True on success, else false. */ loadPolygon(key: string, object: string, scale ?: number): boolean; /** * Moves the Body backwards based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move backwards. */ moveBackward(speed: number): void; /** * If this Body is dynamic then this will move it down by setting its y velocity to the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move down, in pixels per second. */ moveDown(speed: number): void; /** * Moves the Body forwards based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move forwards. */ moveForward(speed: number): void; /** * If this Body is dynamic then this will move it to the left by setting its x velocity to the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move to the left, in pixels per second. */ moveLeft(speed: number): void; /** * If this Body is dynamic then this will move it to the right by setting its x velocity to the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move to the right, in pixels per second. */ moveRight(speed: number): void; /** * If this Body is dynamic then this will move it up by setting its y velocity to the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move up, in pixels per second. */ moveUp(speed: number): void; /** * Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished. */ preUpdate(): void; /** * Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished. */ postUpdate(): void; /** * Removes the given CollisionGroup, or array of CollisionGroups, from the list of groups that this body will collide with and updates the collision masks. * * @param group The Collision Group or Array of Collision Groups that this Bodies shapes should not collide with anymore. * @param clearCallback Clear the callback that will be triggered when this Body impacts with the given Group? - Default: true * @param shape An optional Shape. If not provided the updated collision mask will be added to all Shapes in this Body. */ removeCollisionGroup(group: any, clearCallback?: boolean, shape?: p2.Shape): void; /** * Removes this physics body from the world. */ removeFromWorld(): void; /** * Remove a shape from the body. Will automatically update the mass properties and bounding radius. * * @param shape The shape to remove from the body. * @return True if the shape was found and removed, else false. */ removeShape(shape: p2.Shape): boolean; /** * Applies a force to the Body that causes it to 'thrust' backwards (in reverse), based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should reverse. */ reverse(speed: number): void; /** * This will rotate the Body by the given speed to the left (counter-clockwise). * * @param speed The speed at which it should rotate. */ rotateLeft(speed: number): void; /** * This will rotate the Body by the given speed to the left (clockwise). * * @param speed The speed at which it should rotate. */ rotateRight(speed: number): void; /** * Resets the Body force, velocity (linear and angular) and rotation. Optionally resets damping and mass. * * @param x The new x position of the Body. * @param y The new x position of the Body. * @param resetDamping Resets the linear and angular damping. * @param resetMass Sets the Body mass back to 1. */ reset(x: number, y: number, resetDamping?: boolean, resetMass?: boolean): void; /** * Updates the debug draw if any body shapes change. */ shapeChanged(): void; /** * Clears any previously set shapes. Then creates a new Circle shape and adds it to this Body. * If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates. * * @param radius The radius of this circle (in pixels) * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. */ setCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle; /** * Sets the given CollisionGroup to be the collision group for all shapes in this Body, unless a shape is specified. * This also resets the collisionMask. * * @param group The Collision Group that this Bodies shapes will use. * @param shape An optional Shape. If not provided the collision group will be added to all Shapes in this Body. */ setCollisionGroup(group: Phaser.Physics.P2.CollisionGroup, shape?: p2.Shape): void; /** * Clears any previously set shapes. The creates a new Rectangle shape at the given size and offset, and adds it to this Body. * If you wish to create a Rectangle to match the size of a Sprite or Image see Body.setRectangleFromSprite. * If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates. * * @param width The width of the rectangle in pixels. - Default: 16 * @param height The height of the rectangle in pixels. - Default: 16 * @param offsetX Local horizontal offset of the shape relative to the body center of mass. * @param offsetY Local vertical offset of the shape relative to the body center of mass. * @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. * @return The Rectangle shape that was added to the Body. */ setRectangle(width?: number, height?: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle; /** * Clears any previously set shapes. * Then creates a Rectangle shape sized to match the dimensions and orientation of the Sprite given. * If no Sprite is given it defaults to using the parent of this Body. * If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates. * * @param sprite The Sprite on which the Rectangle will get its dimensions. * @return The Rectangle shape that was added to the Body. */ setRectangleFromSprite(sprite: any): p2.Rectangle; /** * Adds the given Material to all Shapes that belong to this Body. * If you only wish to apply it to a specific Shape in this Body then provide that as the 2nd parameter. * * @param material The Material that will be applied. * @param shape An optional Shape. If not provided the Material will be added to all Shapes in this Body. */ setMaterial(material: Phaser.Physics.P2.Material, shape?: p2.Shape): void; /** * Sets the Body damping and angularDamping to zero. */ setZeroDamping(): void; /** * Sets the force on the body to zero. */ setZeroForce(): void; /** * If this Body is dynamic then this will zero its angular velocity. */ setZeroRotation(): void; /** * If this Body is dynamic then this will zero its velocity on both axis. */ setZeroVelocity(): void; /** * Transform a world point to local body frame. * * @param out The vector to store the result in. * @param worldPoint The input world vector. */ toLocalFrame(out: number[], worldPoint: number[]): void; /** * Applies a force to the Body that causes it to 'thrust' forwards, based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should thrust. */ thrust(speed: number): void; /** * Applies a force to the Body that causes it to 'thrust' to the left, based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move to the left. */ thrustLeft(speed: number): void; /** * Applies a force to the Body that causes it to 'thrust' to the right, based on its current angle and the given speed. * The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms). * * @param speed The speed at which it should move to the right. */ thrustRight(speed: number): void; /** * Transform a local point to world frame. * * @param out The vector to store the result in. * @param localPoint The input local vector. */ toWorldFrame(out: number[], localPoint: number[]): void; /** * Updates the collisionMask. * * @param shape An optional Shape. If not provided the collision group will be added to all Shapes in this Body. */ updateCollisionMask(shape?: p2.Shape): void; } /** * Draws a P2 Body to a Graphics instance for visual debugging. * Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead. * So use sparingly and rarely (if ever) in production code. * * Also be aware that the Debug body is only updated when the Sprite it is connected to changes position. If you * manipulate the sprite in any other way (such as moving it to another Group or bringToTop, etc) then you will * need to manually adjust its BodyDebug as well. */ class BodyDebug extends Phaser.Group { /** * Draws a P2 Body to a Graphics instance for visual debugging. * Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead. * So use sparingly and rarely (if ever) in production code. * * Also be aware that the Debug body is only updated when the Sprite it is connected to changes position. If you * manipulate the sprite in any other way (such as moving it to another Group or bringToTop, etc) then you will * need to manually adjust its BodyDebug as well. * * @param game Game reference to the currently running game. * @param body The P2 Body to display debug data for. * @param settings Settings object. */ /** * The alpha value of the group container. */ constructor(game: Phaser.Game, body: Phaser.Physics.P2.Body, settings: { pixelsPerLengthUnit?: number; debugPolygons?: boolean; lineWidth?: number; alpha?: number; }); /** * The P2 Body to display debug data for. */ body: Phaser.Physics.P2.Body; /** * The canvas to render the debug info to. */ canvas: Phaser.Graphics; /** * Pixels per Length Unit. */ ppu: number; /** * Core update. */ updateSpriteTransform(): void; /** * Draws the P2 shapes to the Graphics object. */ draw(): void; } /** * Collision Group */ class CollisionGroup { /** * Collision Group * * @param bitmask The CollisionGroup bitmask. */ constructor(bitmask: number); /** * The CollisionGroup bitmask. */ mask: number; } /** * Defines a physics material */ class ContactMaterial extends p2.ContactMaterial { } /** * A constraint that tries to keep the distance between two bodies constant. */ class DistanceConstraint extends p2.DistanceConstraint { /** * A constraint that tries to keep the distance between two bodies constant. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param bodyB Second connected body. * @param distance The distance to keep between the bodies. * @param localAnchorA The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0]. * @param localAnchorB The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0]. * @param maxForce Maximum force to apply. - Default: Number.MAX_VALUE */ constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, distance: number, maxForce: number); /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } /** * Allow to access a list of created fixture (coming from Body#addPhaserPolygon) * which itself parse the input from PhysicsEditor with the custom phaser exporter. * You can access fixtures of a Body by a group index or even by providing a fixture Key. * You can set the fixture key and also the group index for a fixture in PhysicsEditor. * This gives you the power to create a complex body built of many fixtures and modify them * during runtime (to remove parts, set masks, categories & sensor properties) */ class FixtureList { /** * Allow to access a list of created fixture (coming from Body#addPhaserPolygon) * which itself parse the input from PhysicsEditor with the custom phaser exporter. * You can access fixtures of a Body by a group index or even by providing a fixture Key. * You can set the fixture key and also the group index for a fixture in PhysicsEditor. * This gives you the power to create a complex body built of many fixtures and modify them * during runtime (to remove parts, set masks, categories & sensor properties) * * @param list A list of fixtures (from Phaser.Physics.P2.Body#addPhaserPolygon) */ constructor(list: any[]); /** * A helper to flatten arrays. This is very useful as the fixtures are nested from time to time due to the way P2 creates and splits polygons. * * @param array The array to flatten. Notice: This will happen recursive not shallow. */ flatten(array: any[]): any[]; /** * Accessor to get either a list of specified fixtures by key or the whole fixture list * * @param keys A list of fixture keys */ getFixtures(keys: string): any[]; /** * Accessor to get either a single fixture by its key. * * @param key The key of the fixture. */ getFixtureByKey(key: string): any[]; /** * Accessor to get a group of fixtures by its group index. * * @param groupID The group index. */ getGroup(groupID: number): any[]; init(): void; /** * Parser for the output of Phaser.Physics.P2.Body#addPhaserPolygon */ parse(): void; /** * * * @param bit The bit to set as the collision group. * @param fixtureKey Only apply to the fixture with the given key. */ setCategory(bit: number, fictureKey: string): void; /** * * * @param bit The bit to set as the collision mask * @param fixtureKey Only apply to the fixture with the given key */ setMask(bit: number, fixtureKey: string): void; /** * * * @param material The contact material for a fixture * @param fixtureKey Only apply to the fixture with the given key */ setMaterial(material: any, fixtureKey: string): void; /** * * * @param value sensor true or false * @param fixtureKey Only apply to the fixture with the given key */ setSensor(value: boolean, fixtureKey: string): void; } /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. */ class GearConstraint extends p2.GearConstraint { /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param bodyB Second connected body. * @param angle The relative angle * @param ratio The gear ratio. - Default: 1 */ constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, angle?: number, ratio?: number); /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } /** * A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set. */ class InversePointProxy { /** * A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set. * * @param world A reference to the P2 World. * @param destination The object to bind to. */ constructor(world: Phaser.Physics.P2, destination: any); /** * The x property of this InversePointProxy get and set in pixels. */ x: number; /** * The y property of this InversePointProxy get and set in pixels. */ y: number; /** * The x property of this InversePointProxy get and set in meters. */ mx: number; /** * The y property of this InversePointProxy get and set in meters. */ my: number; } /** * Locks the relative position between two bodies. */ class LockConstraint extends p2.LockConstraint { /** * Locks the relative position between two bodies. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param bodyB Second connected body. * @param offset The offset of bodyB in bodyA's frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param angle The angle of bodyB in bodyA's frame. * @param maxForce The maximum force that should be applied to constrain the bodies. */ constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, offset?: number[], angle?: number, maxForce?: number); /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } /** * A P2 Material. * * \o/ ~ "Because I'm a Material girl" */ class Material extends p2.Material { /** * A P2 Material. * * \o/ ~ "Because I'm a Material girl" * * @param name The user defined name given to this Material. */ constructor(name: string); /** * The user defined name given to this Material. */ name: string; } /** * A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays. */ class PointProxy { /** * A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays. * * @param world A reference to the P2 World. * @param destination The object to bind to. */ constructor(world: Phaser.Physics.P2, destination: any); /** * The x property of this PointProxy get and set in pixels. */ x: number; /** * The y property of this PointProxy get and set in pixels. */ y: number; /** * The x property of this PointProxy get and set in meters. */ mx: number; /** * The x property of this PointProxy get and set in meters. */ my: number; } /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. */ class PrismaticConstraint extends p2.PrismaticConstraint { /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param bodyB Second connected body. * @param lockRotation If set to false, bodyB will be free to rotate around its anchor point. - Default: true * @param anchorA Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param anchorB Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param axis An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param maxForce The maximum force that should be applied to constrain the bodies. */ constructor(world: Phaser.Physics.P2, bodyA?: Phaser.Physics.P2.Body, bodyB?: Phaser.Physics.P2.Body, lockRotation?: boolean, anchorA?: number[], anchorB?: number[], axis?: number[], maxForce?: number); /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. * The pivot points are given in world (pixel) coordinates. */ class RevoluteConstraint extends p2.RevoluteConstraint { /** * Connects two bodies at given offset points, letting them rotate relative to each other around this point. * The pivot points are given in world (pixel) coordinates. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param pivotA The point relative to the center of mass of bodyA which bodyA is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param bodyB Second connected body. * @param pivotB The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param maxForce The maximum force that should be applied to constrain the bodies. * @param worldPivot A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value. */ constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, pivotA: number[], bodyB: Phaser.Physics.P2.Body, pivotB: number[], maxForce?: number); /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } /** * Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping. */ class Spring { /** * Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping. * * @param world A reference to the P2 World. * @param bodyA First connected body. * @param bodyB Second connected body. * @param restLength Rest length of the spring. A number > 0. - Default: 1 * @param stiffness Stiffness of the spring. A number >= 0. - Default: 100 * @param damping Damping of the spring. A number >= 0. - Default: 1 * @param worldA Where to hook the spring to body A in world coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param worldB Where to hook the spring to body B in world coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param localA Where to hook the spring to body A in local body coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32]. * @param localB Where to hook the spring to body B in local body coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32]. */ constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, restLength?: number, stiffness?: number, damping?: number, worldA?: number[], worldB?: number[], localA?: number[], localB?: number[]); /** * The actual p2 spring object. */ data: p2.LinearSpring; /** * Local reference to game. */ game: Phaser.Game; /** * Local reference to P2 World. */ world: Phaser.Physics.P2; } } } /** * This is a base Plugin template to use for any Phaser plugin development. * * ##### Callbacks * * add | active | visible | remove * -----|-------------|-------------|-------- * init | | | * | preUpdate* | | * | update* | render* | * | postUpdate* | postRender* | * | | | destroy * * Update and render calls are repeated (*). */ class Plugin implements IStateCycle { /** * This is a base Plugin template to use for any Phaser plugin development. * * ##### Callbacks * * add | active | visible | remove * -----|-------------|-------------|-------- * init | | | * | preUpdate* | | * | update* | render* | * | postUpdate* | postRender* | * | | | destroy * * Update and render calls are repeated (*). * * @param game A reference to the currently running game. * @param parent The object that owns this plugin, usually Phaser.PluginManager. */ constructor(game: Phaser.Game, parent: Phaser.PluginManager); /** * A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped. */ active: boolean; /** * A reference to the currently running game. */ game: Phaser.Game; /** * A flag to indicate if this plugin has a postRender method. */ hasPostRender: boolean; /** * A flag to indicate if this plugin has a postUpdate method. */ hasPostUpdate: boolean; /** * A flag to indicate if this plugin has a preUpdate method. */ hasPreUpdate: boolean; /** * A flag to indicate if this plugin has a render method. */ hasRender: boolean; /** * A flag to indicate if this plugin has an update method. */ hasUpdate: boolean; /** * The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null. */ parent: PIXI.DisplayObject; /** * A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped. */ visible: boolean; /** * Clear down this Plugin and null out references */ destroy(): void; /** * Post-render is called after the Game Renderer and State.render have run. * It is only called if visible is set to true. */ postRender(): void; /** * Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics). * It is only called if active is set to true. */ preUpdate(): void; /** * Render is called right after the Game Renderer completes, but before the State.render. * It is only called if visible is set to true. */ render(): void; /** * Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render. * It is only called if active is set to true. */ update(): void; } module Plugin { class SaveCPU extends Phaser.Plugin { renderOnFPS: number; renderOnPointerChange: boolean; forceRender(): void; } class AStar extends Phaser.Plugin { static VERSION: string; static COST_ORTHOGONAL: number; static COST_DIAGONAL: number; static DISTANCE_MANHATTAN: string; static DISTANCE_EUCLIDIAN: string; constructor(parent: PIXI.DisplayObject); parent: PIXI.DisplayObject; version: string; findPath(startPoint: Phaser.Point, goalPoint: Phaser.Point): Phaser.Plugin.AStar.AStarPath; isWalkable(x: number, y: number): boolean; setAStarMap(map: Phaser.Tilemap, layerName: string, tilesetName: string): Phaser.Plugin.AStar; } module AStar { class AStarNode { constructor(x: number, y: number, isWalkable: boolean); x: number; y: number; g: number; h: number; f: number; parent: Phaser.Plugin.AStar.AStarNode; travelCost: number; walkable: boolean; } interface AStarNodeArray { x: number; y: number; } class AStarPath { constructor(nodes?: AStarNodeArray[], start?: Phaser.Plugin.AStar.AStarNode, goal?: Phaser.Plugin.AStar.AStarNode); nodes: AStarNodeArray[]; start: Phaser.Plugin.AStar.AStarNode; goal: Phaser.Plugin.AStar.AStarNode; visited: Phaser.Plugin.AStar.AStarNode[]; } } class ColorHarmony extends Phaser.Plugin { getAnalogousHarmony(color: number, threshold?: number): any; getComplementHarmony(color: number): number; getSplitComplementHarmony(color: number, threshold: number): any; getTriadicHarmony(color: number): any; } class CSS3Filters extends Phaser.Plugin { constructor(parent: PIXI.DisplayObject); blur: number; brightness: number; contrast: number; grayscale: number; hueRotate: number; invert: number; opacity: number; saturate: number; sepia: number; } class TilemapWalker extends Phaser.Plugin { constructor(game: Phaser.Game, map: Phaser.Tilemap, layer?: any, x?: number, y?: number); collides: boolean; game: Phaser.Game; history: boolean; facing: number; map: Phaser.Tilemap; location: Phaser.Point; locationLayer: number; checkTile(x: number, y: number): boolean; getTileFromLocation(x: number, y: number): Phaser.Tile; getTiles(width: number, height: number, center?: boolean): any[]; getTileBehind(distance?: number): Phaser.Tile; getTileBehindLeft(distance?: number): Phaser.Tile; getTileBehindRight(distance?: number): Phaser.Tile; getTileAhead(distance?: number): Phaser.Tile; getTileAheadLeft(distance?: number): Phaser.Tile; getTileAheadRight(distance?: number): Phaser.Tile; getTileLeft(distance: number): Phaser.Tile; getTileRight(distance: number): Phaser.Tile; moveForward(): boolean; moveBackward(): boolean; moveLeft(): boolean; moveRight(): boolean; putTile(index: number): void; setLocation(x: number, y: number, layer?: any): boolean; turnLeft(): void; turnRight(): void; updateLocation(x: number, y: number): boolean; } class SamplePlugin extends Phaser.Plugin { constructor(game: Phaser.Game, parent: PIXI.DisplayObject); addSprite(sprite: Phaser.Sprite): void; update(): void; } class VirtualJoystick extends Phaser.Plugin { constructor(game: Phaser.Game, parent: any); angle: number; base: Phaser.Sprite; baseBMD: Phaser.BitmapData; baseCircle: Phaser.Circle; deltaX: number; deltaY: number; distance: number; force: number; isDragging: boolean; limit: number; limitPoint: Phaser.Point; location: Phaser.Point; nub: Phaser.Sprite; nubBMD: Phaser.BitmapData; speed: number; x: number; y: number; init(x: number, y: number, diameter?: number, limit?: number): void; move(pointer: Phaser.Pointer, x: number, y: number): void; render(): void; setVelocity(sprite: Phaser.Sprite, minSpeed?: number, maxSpeed?: number): Phaser.Sprite; startDrag(): void; stopDrag(nub: Phaser.Sprite, pointer: Phaser.Pointer): void; update(): void; } class Webcam extends Phaser.Plugin { constructor(game: Phaser.Game, parent: PIXI.DisplayObject); active: boolean; context: any; stream: any; video: HTMLVideoElement; connectCallback: (stream: any) => void; errorCallback: (e: any) => void; grab: (context: any, x: number, y: number) => void; start(width: number, height: number, context: any): void; stop(): void; update(): void; } class Juicy extends Phaser.Plugin { constructor(game: Phaser.Game); createScreenFlash(color?: string): Phaser.Plugin.Juicy.ScreenFlash; createTrail(length?: number, color?: number): Phaser.Plugin.Juicy.Trail; overScale(object: Phaser.Sprite, scale?: number, initialScale?: Phaser.Point): void; jelly(object: Phaser.Sprite, strength?: number, delay?: number, initialScale?: Phaser.Point): void; mouseStretch(object: Phaser.Sprite, strength?: number, initialScale?: Phaser.Point): void; update(): void; shake(duration?: number, strength?: number): void; } module Juicy { class Trail { constructor(game: Phaser.Game, trailLength?: number, color?: number); target: Phaser.Sprite; trailLength: number; trailWidth: number; trailScaling: boolean; trailColor: number; update(): void; addSegment(x: number, y: number): void; redrawSegments(offsetX: number, offsetY: number): void; } class ScreenFlash { constructor(game: Phaser.Game, color?: string); flash(maxAlpha?: number, duration?: number): void; } } } interface PluginConstructorOf { new (...parameters: any[]): T; } /** * The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins. */ class PluginManager implements IStateCycle { /** * The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * A reference to the currently running game. */ game: Phaser.Game; /** * An array of all the plugins being managed by this PluginManager. */ plugins: Phaser.Plugin[]; /** * Add a new Plugin into the PluginManager. * The Plugin must have 2 properties: game and parent. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager. * * @param plugin The Plugin to add into the PluginManager. This can be a function or an existing object. * @param args Additional arguments that will be passed to the Plugin.init method. * @return The Plugin that was added to the manager. */ add(plugin: PluginConstructorOf, ...parameters: any[]): T; /** * Clear down this PluginManager, calls destroy on every plugin and nulls out references. */ destroy(): void; /** * Post-render is called after the Game Renderer and State.render have run. * It only calls plugins who have visible=true. */ postRender(): void; /** * PostUpdate is the last thing to be called before the world render. * In particular, it is called after the world postUpdate, which means the camera has been adjusted. * It only calls plugins who have active=true. */ postUpdate(): void; /** * Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics). * It only calls plugins who have active=true. */ preUpdate(): void; /** * Remove a Plugin from the PluginManager. It calls Plugin.destroy on the plugin before removing it from the manager. * * @param plugin The plugin to be removed. * @param destroy Call destroy on the plugin that is removed? - Default: true */ remove(plugin: Phaser.Plugin, destroy?: boolean): void; /** * Remove all Plugins from the PluginManager. It calls Plugin.destroy on every plugin before removing it from the manager. */ removeAll(): void; /** * Render is called right after the Game Renderer completes, but before the State.render. * It only calls plugins who have visible=true. */ render(): void; /** * Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render. * It only calls plugins who have active=true. */ update(): void; } /** * A Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. * The following code creates a point at (0,0): * `var myPoint = new Phaser.Point();` * You can also use them as 2D Vectors and you'll find different vector related methods in this class. */ class Point extends PIXI.Point { /** * A Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. * The following code creates a point at (0,0): * `var myPoint = new Phaser.Point();` * You can also use them as 2D Vectors and you'll find different vector related methods in this class. * * @param x The horizontal position of this Point. * @param y The vertical position of this Point. */ constructor(x?: number, y?: number); /** * The x value of the point. */ x: number; /** * The y value of the point. */ y: number; /** * The const type of this object. */ type: number; /** * Adds the given x and y values to this Point. * * @param x The value to add to Point.x. * @param y The value to add to Point.y. * @return This Point object. Useful for chaining method calls. */ static add(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Subtracts the given x and y values from this Point. * * @param x The value to subtract from Point.x. * @param y The value to subtract from Point.y. * @return This Point object. Useful for chaining method calls. */ static subtract(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Multiplies Point.x and Point.y by the given x and y values. Sometimes known as `Scale`. * * @param x The value to multiply Point.x by. * @param y The value to multiply Point.x by. * @return This Point object. Useful for chaining method calls. */ static multiply(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Divides Point.x and Point.y by the given x and y values. * * @param x The value to divide Point.x by. * @param y The value to divide Point.x by. * @return This Point object. Useful for chaining method calls. */ static divide(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Determines whether the given objects x/y values are equal to this Point object. * * @param a The object to compare with this Point. * @return A value of true if the x and y points are equal, otherwise false. */ static equals(a: Phaser.Point, b: Phaser.Point): boolean; /** * Determines whether a set of x-y coordinates are equal to this Point's. * * @param x The x-coordinate to compare with this Point. * @param y The y-coordinate to compare with this Point. * @return A value of true if the Point's coordinates are identical to the arguments, otherwise false. */ static equalsXY(a: Phaser.Point, x: number, y: number): boolean; static fuzzyEquals(a: Phaser.Point, b: Phaser.Point, epsilon?: number): boolean; static fuzzyEqualsXY(a: Phaser.Point, x: number, y: number, epsilon?: number): boolean; /** * Returns the angle between this Point object and another object with public x and y properties. * * @param a The object to get the angle from this Point to. * @param asDegrees Return a value in radians (false) or degrees (true)? * @return The angle, where this Point is the vertex. Within [-pi, pi] or [-180deg, 180deg]. */ static angle(a: Phaser.Point, b: Phaser.Point): number; static angleSq(a: Phaser.Point, b: Phaser.Point): number; /** * Creates a negative Point. * * @param a The first Point object. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static negative(a: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Adds two 2D Points together and multiplies the result by the given scalar. * * @param a The first Point object. * @param b The second Point object. * @param s The scaling value. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static multiplyAdd(a: Phaser.Point, b: Phaser.Point, scale: number, out?: Phaser.Point): Phaser.Point; /** * Interpolates the two given Points, based on the `f` value (between 0 and 1) and returns a new Point. * * @param a The first Point object. * @param b The second Point object. * @param f The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static interpolate(a: Phaser.Point, b: Phaser.Point, alpha: number, out?: Phaser.Point): Phaser.Point; /** * Parses an object for x and/or y properties and returns a new Phaser.Point with matching values. * If the object doesn't contain those properties a Point with x/y of zero will be returned. * * @param obj The object to parse. * @param xProp The property used to set the Point.x value. - Default: 'x' * @param yProp The property used to set the Point.y value. - Default: 'y' * @return The new Point object. */ static parse(obj: any, xProp?: string, yProp?: string): Phaser.Point; /** * Make this Point perpendicular (90 degrees rotation) * @return This Point object. */ static perp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Make this Point perpendicular (-90 degrees rotation) * @return This Point object. */ static rperp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties) * * @param dest The target object. Must have visible x and y properties that represent the center of the object. * @param round Round the distance to the nearest integer (default false). * @return The distance between this Point object and the destination Point object. */ static distance(a: any, b: any, round?: boolean): number; /** * Project two Points onto another Point. * * @param a The first Point object. * @param b The second Point object. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static project(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Project two Points onto a Point of unit length. * * @param a The first Point object. * @param b The second Point object. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static projectUnit(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Right-hand normalize (make unit length) this Point. * @return This Point object. */ static normalRightHand(a: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Alters the Point object so that its length is 1, but it retains the same direction. * @return This Point object. */ static normalize(a: Phaser.Point, out?: Phaser.Point): Phaser.Point; /** * Rotates this Point around the x/y coordinates given to the desired angle. * * @param x The x coordinate of the anchor point. * @param y The y coordinate of the anchor point. * @param angle The angle in radians (unless asDegrees is true) to rotate the Point to. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @param distance An optional distance constraint between the Point and the anchor. * @return The modified point object. */ static rotate(a: Phaser.Point, x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point; /** * Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned. * * @param points The array of one or more points. * @param out Optional Point to store the value in, if not supplied a new Point object will be created. * @return The new Point object. */ static centroid(points: Phaser.Point[], out?: Phaser.Point): Phaser.Point; /** * Tests a Point or Point-like object. * * @param obj The object to test. * @return - True if the object has numeric x and y properties. */ static isPoint(obj: any): boolean; /** * Sets the `x` and `y` values of this Point object to the given values. * If you omit the `y` value then the `x` value will be applied to both, for example: * `Point.set(2)` is the same as `Point.set(2, 2)` * * Identical to {@link Phaser.Point#setTo setTo}. * * @param x The horizontal value of this point. * @param y The vertical value of this point. If not given the x value will be used in its place. * @return This Point object. Useful for chaining method calls. */ static set(obj: any, x: number, y: number): any; /** * Sorts an array of points in a clockwise direction, relative to a reference point. * * The sort is clockwise relative to the display, starting from a 12 o'clock position. * (In the Cartesian plane, it is anticlockwise, starting from the -y direction.) * * Example sequence: (0, -1), (1, 0), (0, 1), (-1, 0) * * @param points An array of Points or point-like objects (e.g., sprites). * @param center The reference point. If omitted, the {@link #centroid} (midpoint) of the points is used. * @return The sorted array. */ static sortClockwise(points: any[], center?: Phaser.Point): any[]; /** * Adds the given x and y values to this Point. * * @param x The value to add to Point.x. * @param y The value to add to Point.y. * @return This Point object. Useful for chaining method calls. */ add(x: number, y: number): Phaser.Point; /** * Returns the angle between this Point object and another object with public x and y properties. * * @param a The object to get the angle from this Point to. * @param asDegrees Return a value in radians (false) or degrees (true)? * @return The angle, where this Point is the vertex. Within [-pi, pi] or [-180deg, 180deg]. */ angle(a: Phaser.Point, asDegrees?: boolean): number; angleSq(a: Phaser.Point): number; /** * Returns the angle between this Point object and an x-y coordinate pair. * * @param x The x-coordinate * @param y The y-coordinate * @param asDegrees Return a value in radians (false) or degrees (true)? * @return The angle, where this Point is the vertex. Within [-pi, pi] or [-180deg, 180deg]. */ angleXY(x: number, y: number, asDegrees?: boolean): number; /** * Returns the arctangent of this Point. * * @param asDegrees Return a value in radians (false) or degrees (true)? * @return The angle, where the vertex is (0, 0). Within [-pi, pi] or [-180deg, 180deg]. */ atan(asDegrees?: boolean): number; /** * Math.ceil() both the x and y properties of this Point. * @return This Point object. */ ceil(): Phaser.Point; /** * Clamps this Point object values to be between the given min and max. * * @param min The minimum value to clamp this Point to. * @param max The maximum value to clamp this Point to. * @return This Point object. */ clamp(min: number, max: number): Phaser.Point; /** * Clamps the x value of this Point to be between the given min and max. * * @param min The minimum value to clamp this Point to. * @param max The maximum value to clamp this Point to. * @return This Point object. */ clampX(min: number, max: number): Phaser.Point; /** * Clamps the y value of this Point to be between the given min and max * * @param min The minimum value to clamp this Point to. * @param max The maximum value to clamp this Point to. * @return This Point object. */ clampY(min: number, max: number): Phaser.Point; /** * If this Point is not within the given object, moves it inside (at the nearest edge). * * @param rect A {@link Phaser.Rectangle} or any object with left, top, right, and bottom properties. * @return This Point object. */ clip(rect: any): Phaser.Point; /** * Creates a copy of the given Point. * * @param output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. * @return The new Point object. */ clone(output?: Phaser.Point): Phaser.Point; /** * Copies the x and y properties from any given object to this Point. * * @param source The object to copy from. * @return This Point object. */ copyFrom(source: Phaser.Point): Phaser.Point; /** * Copies the x and y properties from this Point to any given object. * * @param dest The object to copy to. * @return The dest object. */ copyTo(dest: T): T; /** * The cross product of this and another Point object. * * @param a The Point object to get the cross product combined with this Point. * @return The result. */ cross(a: Phaser.Point): number; /** * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties) * * @param dest The target object. Must have visible x and y properties that represent the center of the object. * @param round Round the distance to the nearest integer (default false). * @return The distance between this Point object and the destination Point object. */ distance(dest: Phaser.Point, round?: boolean): number; /** * Divides Point.x and Point.y by the given x and y values. * * @param x The value to divide Point.x by. * @param y The value to divide Point.x by. * @return This Point object. Useful for chaining method calls. */ divide(x: number, y: number): Phaser.Point; /** * The dot product of this and another Point object. * * @param a The Point object to get the dot product combined with this Point. * @return The result. */ dot(a: Phaser.Point): number; /** * Determines whether the given objects x/y values are equal to this Point object. * * @param a The object to compare with this Point. * @return A value of true if the x and y points are equal, otherwise false. */ equals(a: Phaser.Point): boolean; /** * Determines whether a set of x-y coordinates are equal to this Point's. * * @param x The x-coordinate to compare with this Point. * @param y The y-coordinate to compare with this Point. * @return A value of true if the Point's coordinates are identical to the arguments, otherwise false. */ equalsXY(x: number, y: number): boolean; /** * Alters the Point object so its magnitude is at least the min value. * * @param min The minimum magnitude for the Point. * @return This Point object. */ expand(min: number): Phaser.Point; /** * Math.floor() both the x and y properties of this Point. * @return This Point object. */ floor(): Phaser.Point; fuzzyEquals(a: Phaser.Point, epsilon?: number): boolean; fuzzyEqualsXY(x: number, y: number, epsilon?: number): boolean; /** * Calculates the length of the Point object. * @return The length of the Point. */ getMagnitude(): number; /** * Calculates the length squared of the Point object. * @return The length ^ 2 of the Point. */ getMagnitudeSq(): number; /** * Inverts the x and y values of this Point * @return This Point object. */ invert(): Phaser.Point; /** * Determine if this point is at 0,0. * @return True if this Point is 0,0, otherwise false. */ isZero(): boolean; /** * Alters the Point object so its magnitude is at most the max value. * * @param max The maximum magnitude for the Point. * @return This Point object. */ limit(max: number): Phaser.Point; /** * Multiplies Point.x and Point.y by the given x and y values. Sometimes known as `Scale`. * * @param x The value to multiply Point.x by. * @param y The value to multiply Point.x by. * @return This Point object. Useful for chaining method calls. */ multiply(x: number, y: number): Phaser.Point; /** * Alters the Point object so that its length is 1, but it retains the same direction. * @return This Point object. */ normalize(): Phaser.Point; /** * Right-hand normalize (make unit length) this Point. * @return This Point object. */ normalRightHand(): Phaser.Point; /** * Make this Point perpendicular (90 degrees rotation) * @return This Point object. */ perp(): Phaser.Point; /** * Rotates this Point around the x/y coordinates given to the desired angle. * * @param x The x coordinate of the anchor point. * @param y The y coordinate of the anchor point. * @param angle The angle in radians (unless asDegrees is true) to rotate the Point to. * @param asDegrees Is the given angle in radians (false) or degrees (true)? * @param distance An optional distance constraint between the Point and the anchor. * @return The modified point object. */ rotate(x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point; /** * Math.round() both the x and y properties of this Point. * @return This Point object. */ round(): Phaser.Point; /** * Make this Point perpendicular (-90 degrees rotation) * @return This Point object. */ rperp(): Phaser.Point; /** * Sets the `x` and `y` values of this Point object to the given values. * If you omit the `y` value then the `x` value will be applied to both, for example: * `Point.set(2)` is the same as `Point.set(2, 2)` * * Identical to {@link Phaser.Point#setTo setTo}. * * @param x The horizontal value of this point. * @param y The vertical value of this point. If not given the x value will be used in its place. * @return This Point object. Useful for chaining method calls. */ set(x: number, y?: number): Phaser.Point; /** * Alters the length of the Point without changing the direction. * * @param magnitude The desired magnitude of the resulting Point. * @return This Point object. */ setMagnitude(magnitude: number): Phaser.Point; /** * Sets the `x` and `y` values of this Point object to the given values. * If you omit the `y` value then the `x` value will be applied to both, for example: * `Point.setTo(2)` is the same as `Point.setTo(2, 2)` * * Identical to {@link Phaser.Point#set set}. * * @param x The horizontal value of this point. * @param y The vertical value of this point. If not given the x value will be used in its place. * @return This Point object. Useful for chaining method calls. */ setTo(x: number, y?: number): Phaser.Point; /** * Sets the `x` and `y` values of this Point object from a given polar coordinate. * * @param azimuth The angular coordinate, in radians (unless `asDegrees`). * @param radius The radial coordinate (length). - Default: 1 * @param asDegrees True if `azimuth` is in degrees. * @return This Point object. Useful for chaining method calls. */ setToPolar(azimuth: number, radius?: number, asDegrees?: boolean): Phaser.Point; /** * Subtracts the given x and y values from this Point. * * @param x The value to subtract from Point.x. * @param y The value to subtract from Point.y. * @return This Point object. Useful for chaining method calls. */ subtract(x: number, y: number): Phaser.Point; /** * Returns a string representation of this object. * @return A string representation of the instance. */ toString(): string; } /** * A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen. */ class Pointer { /** * A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen. * * @param game A reference to the currently running game. * @param id The ID of the Pointer object within the game. Each game can have up to 10 active pointers. * @param pointerMode The operational mode of this pointer, eg. CURSOR or CONTACT. - Default: (CURSOR|CONTACT) */ constructor(game: Phaser.Game, id: number, pointerMode?: number); /** * No buttons at all. */ static NO_BUTTON: number; /** * The Left Mouse button, or in PointerEvent devices a Touch contact or Pen contact. */ static LEFT_BUTTON: number; /** * The Right Mouse button, or in PointerEvent devices a Pen contact with a barrel button. */ static RIGHT_BUTTON: number; /** * The Middle Mouse button. */ static MIDDLE_BUTTON: number; /** * The X1 button. This is typically the mouse Back button, but is often reconfigured. * On Linux (GTK) this is unsupported. On Windows if advanced pointer software (such as IntelliPoint) is installed this doesn't register. */ static BACK_BUTTON: number; /** * The X2 button. This is typically the mouse Forward button, but is often reconfigured. * On Linux (GTK) this is unsupported. On Windows if advanced pointer software (such as IntelliPoint) is installed this doesn't register. */ static FORWARD_BUTTON: number; /** * The Eraser pen button on PointerEvent supported devices only. */ static ERASER_BUTTON: number; /** * An active pointer is one that is currently pressed down on the display. A Mouse is always active. */ active: boolean; /** * If this Pointer is a Mouse or Pen / Stylus then you can access its X1 (back) button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. * * Please see the DeviceButton docs for details on browser button limitations. */ backButton: Phaser.DeviceButton; /** * The button property of the most recent DOM event when this Pointer is started. * You should not rely on this value for accurate button detection, instead use the Pointer properties * `leftButton`, `rightButton`, `middleButton` and so on. */ button: any; /** * A Phaser.Circle that is centered on the x/y coordinates of this pointer, useful for hit detection. * The Circle size is 44px (Apples recommended "finger tip" size). */ circle: Phaser.Circle; /** * The horizontal coordinate of the Pointer within the application's client area at which the event occurred (as opposed to the coordinates within the page). */ clientX: number; /** * The vertical coordinate of the Pointer within the application's client area at which the event occurred (as opposed to the coordinates within the page). */ clientY: number; /** * A dirty pointer needs to re-poll any interactive objects it may have been over, regardless if it has moved or not. */ dirty: boolean; /** * How long the Pointer has been depressed on the touchscreen or *any* of the mouse buttons have been held down. * If not currently down it returns -1. * If you need to test a specific mouse or pen button then access the buttons directly, i.e. `Pointer.rightButton.duration`. */ duration: number; /** * If this Pointer is a Pen / Stylus then you can access its eraser button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. * * Please see the DeviceButton docs for details on browser button limitations. */ eraserButton: Phaser.DeviceButton; /** * A Pointer object that exists is allowed to be checked for physics collisions and overlaps. * Default: true */ exists: boolean; forceOut: boolean; /** * If this Pointer is a Mouse or Pen / Stylus then you can access its X2 (forward) button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. * * Please see the DeviceButton docs for details on browser button limitations. */ forwardButton: Phaser.DeviceButton; /** * A reference to the currently running game. */ game: Phaser.Game; justReleasePreventsOver: boolean | number; /** * The ID of the Pointer object within the game. Each game can have up to 10 active pointers. */ id: number; /** * The identifier property of the Pointer as set by the DOM event when this Pointer is started. */ identifier: number; /** * This array is erased and re-populated every time this Pointer is updated. It contains references to all * of the Game Objects that were considered as being valid for processing by this Pointer, this frame. To be * valid they must have suitable a `priorityID`, be Input enabled, visible and actually have the Pointer over * them. You can check the contents of this array in events such as `onInputDown`, but beware it is reset * every frame. * Default: [] */ interactiveCandidates: Phaser.InputHandler[]; /** * If the Pointer is touching the touchscreen, or *any* mouse or pen button is held down, isDown is set to true. * If you need to check a specific mouse or pen button then use the button properties, i.e. Pointer.rightButton.isDown. */ isDown: boolean; /** * If the Pointer is a mouse or pen / stylus this is true, otherwise false. */ isMouse: boolean; /** * If the Pointer is not touching the touchscreen, or *all* mouse or pen buttons are up, isUp is set to true. * If you need to check a specific mouse or pen button then use the button properties, i.e. Pointer.rightButton.isUp. * Default: true */ isUp: boolean; /** * If this Pointer is a Mouse or Pen / Stylus then you can access its left button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. */ leftButton: Phaser.DeviceButton; /** * If this Pointer is a Mouse or Pen / Stylus then you can access its middle button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. * * Please see the DeviceButton docs for details on browser button limitations. */ middleButton: Phaser.DeviceButton; /** * The cumulative horizontal relative movement of the Pointer in pixels since resetMovement() was called, if this is a Mouse Pointer in a locked state. */ movementX: number; /** * The cumulative vertical relative movement of the Pointer in pixels since resetMovement() was called, if this is a Mouse Pointer in a locked state.. */ movementY: number; /** * The number of milliseconds since the last click or touch event. */ msSinceLastClick: number; /** * The horizontal coordinate of the Pointer relative to whole document. */ pageX: number; /** * The vertical coordinate of the Pointer relative to whole document. */ pageY: 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; /** * The operational mode of this pointer. */ pointerMode: number; /** * A Phaser.Point object containing the current x/y values of the pointer on the display. */ position: Phaser.Point; /** * A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display. */ positionDown: Phaser.Point; /** * A Phaser.Point object containing the x/y values of the pointer when it was last released. */ positionUp: Phaser.Point; /** * A timestamp representing when the Pointer was last tapped or clicked. */ previousTapTime: number; /** * The horizontal raw relative movement of the Pointer in pixels at the last event, if this is a Mouse Pointer in a locked state. */ rawMovementX: number; /** * The vertical raw relative movement of the Pointer in pixels at the last event, if this is a Mouse Pointer in a locked state. */ rawMovementY: number; /** * If this Pointer is a Mouse or Pen / Stylus then you can access its right button directly through this property. * * The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained * button control. * * Please see the DeviceButton docs for details on browser button limitations. */ rightButton: Phaser.DeviceButton; /** * The horizontal coordinate of the Pointer relative to the screen. */ screenX: number; /** * The vertical coordinate of the Pointer relative to the screen. */ screenY: number; /** * The target property of the Pointer as set by the DOM event when this Pointer is started. */ target: any; /** * The Game Object this Pointer is currently over / touching / dragging. */ targetObject: any; /** * A timestamp representing when the Pointer first touched the touchscreen. */ timeDown: number; /** * A timestamp representing when the Pointer left the touchscreen. */ timeUp: number; /** * The total number of times this Pointer has been touched to the touchscreen. */ totalTouches: number; /** * The const type of this object. */ type: number; /** * true if the Pointer is over the game canvas, otherwise false. */ withinGame: boolean; /** * Gets the X value of this Pointer in world coordinates based on the world camera. */ worldX: number; /** * Gets the Y value of this Pointer in world coordinates based on the world camera. */ worldY: number; /** * The horizontal coordinate of the Pointer. This value is automatically scaled based on the game scale. */ x: number; /** * The vertical coordinate of the Pointer. This value is automatically scaled based on the game scale. */ y: number; /** * Add a click trampoline to this pointer. * * A click trampoline is a callback that is run on the DOM 'click' event; this is primarily * needed with certain browsers (ie. IE11) which restrict some actions like requestFullscreen * to the DOM 'click' event and rejects it for 'pointer*' and 'mouse*' events. * * This is used internally by the ScaleManager; click trampoline usage is uncommon. * Click trampolines can only be added to pointers that are currently down. * * @param name The name of the trampoline; must be unique among active trampolines in this pointer. * @param callback Callback to run/trampoline. * @param callbackContext Context of the callback. * @param callbackArgs Additional callback args, if any. Supplied as an array. */ addClickTrampoline(name: string, callback: Function, callbackContext?: any, ...callbackArgs: any[]): void; /** * The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate. * Note that calling justPressed doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid. * If you wish to check if the Pointer was pressed down just once then see the Sprite.events.onInputDown event. * * @param duration The time to check against. If none given it will use InputManager.justPressedRate. * @return true if the Pointer was pressed down within the duration given. */ justPressed(duration?: number): boolean; /** * The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate. * Note that calling justReleased doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid. * If you wish to check if the Pointer was released just once then see the Sprite.events.onInputUp event. * * @param duration The time to check against. If none given it will use InputManager.justReleasedRate. * @return true if the Pointer was released within the duration given. */ justReleased(duration?: number): boolean; /** * Called when the Pointer leaves the target area. * * @param event The event passed up from the input handler. */ leave(event: any): void; /** * Called when the Pointer is moved. * * @param event The event passed up from the input handler. * @param fromClick Was this called from the click event? */ move(event: any, fromClick?: boolean): void; /** * Resets the Pointer properties. Called by InputManager.reset when you perform a State change. */ reset(): void; /** * Resets the states of all the button booleans. */ resetButtons(): void; /** * Resets the movementX and movementY properties. Use in your update handler after retrieving the values. */ resetMovement(): void; /** * Called when the Pointer is pressed onto the touchscreen. * * @param event The DOM event from the browser. */ start(event: any): void; /** * Called when the Pointer leaves the touchscreen. * * @param event The event passed up from the input handler. */ stop(event: any): void; /** * This will change the `Pointer.targetObject` object to be the one provided. * * This allows you to have fine-grained control over which object the Pointer is targeting. * * Note that even if you set a new Target here, it is still able to be replaced by any other valid * target during the next Pointer update. * * @param newTarget The new target for this Pointer. Note this is an `InputHandler`, so don't pass a Sprite, instead pass `sprite.input` to it. * @param silent If true the new target AND the old one will NOT dispatch their `onInputOver` or `onInputOut` events. */ swapTarget(newTarget: Phaser.InputHandler, silent?: boolean): void; /** * Called by the Input Manager. */ update(): void; /** * Called when the event.buttons property changes from zero. * Contains a button bitmask. * * @param event The DOM event. */ updateButtons(event: MouseEvent): void; } /** * The pointer lock input handler. */ class PointerLock { /** * The currently running game. */ game: Phaser.Game; /** * The Input Manager. */ input: Phaser.Input; /** * The element where event listeners are added. */ element: HTMLElement; /** * Whether the input handler is active. */ active: boolean; /** * Whether the pointer is locked to the game canvas. */ locked: boolean; /** * A signal dispatched when the pointer is locked or unlocked. * Its arguments are {@link Phaser.PointerLock#locked} and the original event from the browser. */ onChange: Phaser.Signal; /** * A signal dispatched when a request to lock or unlock the pointer fails. * Its argument is the original event from the browser. */ onError: Phaser.Signal; /** * Releases the locked pointer. * Use onChange and onError to track the result of the request. */ exit(): void; /** * Requests the browser to lock the pointer to the game canvas. * Use onChange and onError to track the result of the request. */ request(): void; /** * Activates the handler, unless already active or Pointer Lock is unsupported on this device. * @return - True if the handler was started, otherwise false. */ start(): boolean; /** * Deactivates the handler. */ stop(): void; } /** * Creates a new Polygon. * * The points can be set from a variety of formats: * * - 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, ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` */ class Polygon { /** * Creates a new Polygon. * * The points can be set from a variety of formats: * * - 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, ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * @param points The points to set. */ constructor(points: Phaser.Point[] | number[]); /** * Creates a new Polygon. * * The points can be set from a variety of formats: * * - 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, ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * @param points The points to set. */ constructor(...points: Phaser.Point[]); /** * Creates a new Polygon. * * The points can be set from a variety of formats: * * - 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, ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * @param points The points to set. */ constructor(...points: number[]); /** * The area of this Polygon. */ area: number; /** * Has this Polygon been flattened by a call to `Polygon.flatten` ? */ flattened: boolean; /** * The points of this polygon. * * You can modify these with {@link Phaser.Polygon#setTo setTo}. The array of vertex points. */ points: number[] | Phaser.Point[]; /** * The base object type. */ type: number; /** * Creates a copy of the given Polygon. * This is a deep clone, the resulting copy contains new Phaser.Point objects * * @param output The polygon to update. If not specified a new polygon will be created. - Default: (new Phaser.Polygon) * @return The cloned (`output`) polygon object. */ clone(output?: Phaser.Polygon): Phaser.Polygon; /** * Checks whether the x and y coordinates are contained within this polygon. * * @param x The X value of the coordinate to test. * @param y The Y value of the coordinate to test. * @return True if the coordinates are within this polygon, otherwise false. */ contains(x: number, y: number): boolean; /** * Flattens this Polygon so the points are a sequence of numbers. * Any Point objects found are removed and replaced with two numbers. * Also sets the Polygon.flattened property to `true`. * @return This Polygon object */ flatten(): Phaser.Polygon; /** * Sets this Polygon to the given points. * * The points can be set from a variety of formats: * * - 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], ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * `setTo` may also be called without any arguments to remove all points. * * @param points The points to set. * @return This Polygon object */ setTo(points: Phaser.Point[] | number[]): void; /** * Sets this Polygon to the given points. * * The points can be set from a variety of formats: * * - 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], ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * `setTo` may also be called without any arguments to remove all points. * * @param points The points to set. * @return This Polygon object */ setTo(...points: Phaser.Point[]): void; /** * Sets this Polygon to the given points. * * The points can be set from a variety of formats: * * - 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], ...]` * - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)` * - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)` * - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)` * * `setTo` may also be called without any arguments to remove all points. * * @param points The points to set. * @return This Polygon object */ setTo(...points: number[]): void; /** * Export the points as an array of flat numbers, following the sequence [ x,y, x,y, x,y ] * * @param output The array to append the points to. If not specified a new array will be created. * @return The flattened array. */ toNumberArray(output?: number[]): number[]; } /** * A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts. * However I've tweaked it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result. * Original version at https://github.com/timohausmann/quadtree-js/ */ class QuadTree { /** * A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts. * However I've tweaked it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result. * Original version at https://github.com/timohausmann/quadtree-js/ * * @param x The top left coordinate of the quadtree. * @param y The top left coordinate of the quadtree. * @param width The width of the quadtree in pixels. * @param height The height of the quadtree in pixels. * @param maxObjects The maximum number of objects per node. - Default: 10 * @param maxLevels The maximum number of levels to iterate to. - Default: 4 * @param level Which level is this? */ constructor(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number); /** * Object that contains the quadtree bounds. */ bounds: { x: number; y: number; width: number; height: number; subWidth: number; subHeight: number; right: number; bottom: number; }; /** * The current level. */ level: number; /** * The maximum number of objects per node. * Default: 10 */ maxObjects: number; /** * The maximum number of levels to break down to. * Default: 4 */ maxLevels: number; /** * Array of quadtree children. */ objects: any[]; /** * Array of associated child nodes. */ nodes: any[]; /** * Clear the quadtree. */ clear(): void; /** * Determine which node the object belongs to. * * @param rect The bounds in which to check. * @return index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node. */ getIndex(rect: any): number; /** * Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes. * * @param body The Body object to insert into the quadtree. Can be any object so long as it exposes x, y, right and bottom properties. */ insert(body: any): void; /** * Populates this quadtree with the children of the given Group. In order to be added the child must exist and have a body property. * * @param group The Group to add to the quadtree. */ populate(group: Phaser.Group): void; /** * Handler for the populate method. * * @param sprite The Sprite to check. */ populateHandler(sprite: Phaser.Sprite): void; /** * Resets the QuadTree. * * @param x The top left coordinate of the quadtree. * @param y The top left coordinate of the quadtree. * @param width The width of the quadtree in pixels. * @param height The height of the quadtree in pixels. * @param maxObjects The maximum number of objects per node. - Default: 10 * @param maxLevels The maximum number of levels to iterate to. - Default: 4 * @param level Which level is this? */ reset(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number): void; /** * Return all objects that could collide with the given Sprite or Rectangle. * * @param source The source object to check the QuadTree against. Either a Sprite or Rectangle. * @return - Array with all detected objects. */ retrieve(source: any): any[]; /** * Split the node into 4 subnodes */ split(): void; } /** * An extremely useful repeatable random data generator. * * Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense. * * The random number genererator is based on the Alea PRNG, but is modified. * - https://github.com/coverslide/node-alea * - https://github.com/nquinlan/better-random-numbers-for-javascript-mirror * - http://baagoe.org/en/wiki/Better_random_numbers_for_javascript (original, perm. 404) */ class RandomDataGenerator { /** * An extremely useful repeatable random data generator. * * Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense. * * The random number genererator is based on the Alea PRNG, but is modified. * - https://github.com/coverslide/node-alea * - https://github.com/nquinlan/better-random-numbers-for-javascript-mirror * - http://baagoe.org/en/wiki/Better_random_numbers_for_javascript (original, perm. 404) * * @param seeds An array of values to use as the seed, or a generator state (from {#state}). */ constructor(seeds?: any[] | string); /** * Returns a random angle between -180 and 180. * @return A random number between -180 and 180. */ angle(): 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. * @return A random number between min and max. */ between(min: number, max: number): number; /** * Returns a random real number between 0 and 1. * @return A random real number between 0 and 1. */ frac(): number; /** * Returns a random integer between 0 and 2^32. * @return A random integer between 0 and 2^32. */ integer(): 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. * @return A random number between min and max. */ integerInRange(min: number, max: number): number; /** * Returns a random real number between -1 and 1. * @return A random real number between -1 and 1. */ normal(): number; /** * Returns a random member of `array`. * * @param ary An Array to pick a random member of. * @return A random member of the array. */ pick(ary: T[]): T; /** * Returns a random real number between 0 and 2^32. * @return A random real number between 0 and 2^32. */ real(): 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. * @return A random number between min and max. */ realInRange(min: number, max: number): number; /** * Returns a sign to be used with multiplication operator. * @return -1 or +1. */ sign(): number; /** * Reset the seed of the random data generator. * * _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. */ sow(seeds: any[]): void; /** * 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. * * 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. * @return The current state of the generator. */ state(state?: string): string; /** * 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. * @return A random timestamp between min and max. */ timestamp(min: number, max: number): number; /** * Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368 * @return A valid RFC4122 version4 ID hex string */ uuid(): string; /** * Returns a random member of `array`, favoring the earlier entries. * * @param ary An Array to pick a random member of. * @return A random member of the array. */ weightedPick(ary: T[]): T; } /** * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. * If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created. */ class Rectangle { /** * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. * If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created. * * @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. Should always be either zero or a positive value. * @param height The height of the Rectangle. Should always be either zero or a positive value. */ constructor(x?: number, y?: number, width?: number, height?: number); /** * 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. */ bottom: number; /** * The location of the Rectangles bottom right corner as a Point object. Gets or sets the location of the Rectangles bottom right corner as a Point object. */ bottomRight: Phaser.Point; /** * The location of the Rectangles bottom left corner as a Point object. Gets or sets the location of the Rectangles bottom left corner as a Point object. */ bottomLeft: Phaser.Point; /** * The x coordinate of the center of the Rectangle. */ centerX: number; /** * The y coordinate of the center of the Rectangle. */ centerY: number; /** * Determines whether or not this Rectangle object is empty. A Rectangle object is empty if its width or height is less than or equal to 0. * If set to true then all of the Rectangle properties are set to 0. Gets or sets the Rectangles empty state. */ empty: boolean; /** * Half of the height of the Rectangle. */ halfHeight: number; /** * Half of the width of the Rectangle. */ halfWidth: number; /** * The height of the Rectangle. This value should never be set to a negative. */ height: 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. */ left: number; /** * The perimeter size of the Rectangle. This is the sum of all 4 sides. */ perimeter: number; /** * A random value between the left and right values (inclusive) of the Rectangle. */ randomX: number; /** * A random value between the top and bottom values (inclusive) of the Rectangle. */ randomY: 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. */ right: 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. */ top: number; /** * The location of the Rectangles top left corner as a Point object. */ topLeft: Phaser.Point; /** * The location of the Rectangles top right corner as a Point object. The location of the Rectangles top left corner as a Point object. */ topRight: Phaser.Point; /** * The const type of this object. */ type: number; /** * The volume of the Rectangle derived from width * height. */ volume: number; /** * The width of the Rectangle. This value should never be set to a negative. */ width: number; /** * The x coordinate of the top-left corner of the Rectangle. */ x: number; /** * The y coordinate of the top-left corner of the Rectangle. */ y: number; /** * Calculates the Axis Aligned Bounding Box (or aabb) from an array of points. * * @param points The array of one or more points. * @param out Optional Rectangle to store the value in, if not supplied a new Rectangle object will be created. * @return The new Rectangle object. */ static aabb(points: Phaser.Point[], out?: Phaser.Rectangle): Phaser.Rectangle; /** * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. * * @param output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. */ static clone(a: Phaser.Rectangle, output?: Phaser.Rectangle): Phaser.Rectangle; /** * Determines whether the specified coordinates are contained within the region defined by this Rectangle object. * * @param x The x coordinate of the point to test. * @param y The y coordinate of the point to test. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ static contains(a: Phaser.Rectangle, x: number, y: number): boolean; /** * Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter. * * @param a The Rectangle object. * @param point The point object being checked. Can be Point or any object with .x and .y values. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ static containsPoint(a: Phaser.Rectangle, point: Phaser.Point): boolean; /** * Determines whether the specified coordinates are contained within the region defined by the given raw values. * * @param rx The x coordinate of the top left of the area. * @param ry The y coordinate of the top left of the area. * @param rw The width of the area. * @param rh The height of the area. * @param x The x coordinate of the point to test. * @param y The y coordinate of the point to test. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ static containsRaw(rx: number, ry: number, rw: number, rh: number, x: number, y: number): boolean; /** * Determines whether the first Rectangle object is fully contained within the second Rectangle object. * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first. * * @param b The second Rectangle object. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ static containsRect(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean; /** * Returns a new Rectangle object with the same values for the left, top, width, and height properties as the original object. * * @param a An object with `left`, `top`, `width`, and `height` properties. * @param output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. */ static createFromBounds(a: any, output?: Phaser.Rectangle): Phaser.Rectangle; /** * Determines whether the two Rectangles are equal. * This method compares the x, y, width and height properties of each Rectangle. * * @param b The second Rectangle object. * @return A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false. */ static equals(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean; /** * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value. * * @param dx The amount to be added to the left side of the Rectangle. * @param dy The amount to be added to the bottom side of the Rectangle. * @return This Rectangle object. */ static inflate(a: Phaser.Rectangle, dx: number, dy: number): Phaser.Rectangle; /** * Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter. * * @param a The Rectangle object. * @param point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object. * @return The Rectangle object. */ static inflatePoint(a: Phaser.Rectangle, point: Phaser.Point): Phaser.Rectangle; /** * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0. * * @param b The second Rectangle object. * @param out Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0. */ static intersection(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle; /** * Determines whether this Rectangle and another given Rectangle intersect with each other. * This method checks the x, y, width, and height properties of the two Rectangles. * * @param b The second Rectangle object. * @return A value of true if the specified object intersects with this Rectangle object; otherwise false. */ static intersects(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean; /** * Determines whether the coordinates given intersects (overlaps) with this Rectangle. * * @param left The x coordinate of the left of the area. * @param right The right coordinate of the area. * @param top The y coordinate of the area. * @param bottom The bottom coordinate of the area. * @param tolerance A tolerance value to allow for an intersection test with padding, default to 0 * @return A value of true if the specified object intersects with the Rectangle; otherwise false. */ static intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean; /** * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties. * * @param output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. * @return The size of the Rectangle object. */ static size(a: Phaser.Rectangle, output?: Phaser.Point): Phaser.Point; /** * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles. * * @param b The second Rectangle object. * @param out Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return A Rectangle object that is the union of the two Rectangles. */ static union(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle; /** * Runs Math.ceil() on both the x and y values of this Rectangle. */ ceil(): void; /** * Runs Math.ceil() on the x, y, width and height values of this Rectangle. */ ceilAll(): void; /** * Centers this Rectangle so that the center coordinates match the given x and y values. * * @param x The x coordinate to place the center of the Rectangle at. * @param y The y coordinate to place the center of the Rectangle at. * @return This Rectangle object */ centerOn(x: number, y: number): Phaser.Rectangle; /** * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. * * @param output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. */ clone(output?: Phaser.Rectangle): Phaser.Rectangle; /** * Determines whether the specified coordinates are contained within the region defined by this Rectangle object. * * @param x The x coordinate of the point to test. * @param y The y coordinate of the point to test. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ contains(x: number, y: number): boolean; /** * Determines whether the first Rectangle object is fully contained within the second Rectangle object. * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first. * * @param b The second Rectangle object. * @return A value of true if the Rectangle object contains the specified point; otherwise false. */ containsRect(b: Phaser.Rectangle): boolean; /** * Copies the x, y, width and height properties from any given object to this Rectangle. * * @param source The object to copy from. * @return This Rectangle object. */ copyFrom(source: any): Phaser.Rectangle; /** * Copies the left, top, width and height properties from any given object to this Rectangle. * * @param source The object to copy from. * @return This Rectangle object. */ copyFromBounds(source: any): Phaser.Rectangle; /** * Copies the x, y, width and height properties from this Rectangle to any given object. * * @param source The object to copy to. * @return This object. */ copyTo(dest: any): any; /** * Determines whether the two Rectangles are equal. * This method compares the x, y, width and height properties of each Rectangle. * * @param b The second Rectangle object. * @return A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false. */ equals(b: Phaser.Rectangle): boolean; /** * Runs Math.floor() on both the x and y values of this Rectangle. */ floor(): void; /** * Runs Math.floor() on the x, y, width and height values of this Rectangle. */ floorAll(): void; /** * Returns a point based on the given position constant, which can be one of: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * This method returns the same values as calling Rectangle.bottomLeft, etc, but those * calls always create a new Point object, where-as this one allows you to use your own. * * @param position One of the Phaser position constants, such as `Phaser.TOP_RIGHT`. * @param out A Phaser.Point that the values will be set in. * If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object. * @return An object containing the point in its `x` and `y` properties. */ getPoint(position: number, out: Phaser.Point): Phaser.Point; /** * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value. * * @param dx The amount to be added to the left side of the Rectangle. * @param dy The amount to be added to the bottom side of the Rectangle. * @return This Rectangle object. */ inflate(dx: number, dy: number): Phaser.Rectangle; /** * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0. * * @param b The second Rectangle object. * @param out Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0. */ intersection(b: Phaser.Rectangle, out: Phaser.Rectangle): Phaser.Rectangle; /** * Determines whether this Rectangle and another given Rectangle intersect with each other. * This method checks the x, y, width, and height properties of the two Rectangles. * * @param b The second Rectangle object. * @return A value of true if the specified object intersects with this Rectangle object; otherwise false. */ intersects(b: Phaser.Rectangle, tolerance: number): boolean; /** * Determines whether the coordinates given intersects (overlaps) with this Rectangle. * * @param left The x coordinate of the left of the area. * @param right The right coordinate of the area. * @param top The y coordinate of the area. * @param bottom The bottom coordinate of the area. * @param tolerance A tolerance value to allow for an intersection test with padding, default to 0 * @return A value of true if the specified object intersects with the Rectangle; otherwise false. */ intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean; /** * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts. * * @param dx Moves the x value of the Rectangle object by this amount. * @param dy Moves the y value of the Rectangle object by this amount. * @return This Rectangle object. */ offset(dx: number, dy: number): Phaser.Rectangle; /** * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter. * * @param point A Point object to use to offset this Rectangle object. * @return This Rectangle object. */ offsetPoint(point: Phaser.Point): Phaser.Rectangle; /** * Returns a uniformly distributed random point from anywhere within this Rectangle. * * @param out A Phaser.Point, or any object with public x/y properties, that the values will be set in. * If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object. * @return An object containing the random point in its `x` and `y` properties. */ random(out?: Phaser.Point): Phaser.Point; /** * Resize the Rectangle by providing a new width and height. * The x and y positions remain unchanged. * * @param width The width of the Rectangle. Should always be either zero or a positive value. * @param height The height of the Rectangle. Should always be either zero or a positive value. * @return This Rectangle object */ resize(width: number, height: number): Phaser.Rectangle; /** * Sets the members of Rectangle to the specified values. * * @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. Should always be either zero or a positive value. * @param height The height of the Rectangle. Should always be either zero or a positive value. * @return This Rectangle object */ setTo(x: number, y: number, width: number, height: number): Phaser.Rectangle; /** * Scales the width and height of this Rectangle by the given amounts. * * @param x The amount to scale the width of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the width, etc. * @param y The amount to scale the height of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the height, etc. * @return This Rectangle object */ scale(x: number, y?: number): Phaser.Rectangle; /** * Creates or positions four {@link Phaser.Line} lines representing the Rectangle's sides. * * @param top * @param right * @param bottom * @param left * @return An array containing four lines (if no arguments were given), or null. */ sides(top?: Phaser.Line, right?: Phaser.Line, bottom?: Phaser.Line, left?: Phaser.Line): Phaser.Line[]; /** * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties. * * @param output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. * @return The size of the Rectangle object. */ size(output?: Phaser.Point): Phaser.Point; /** * Returns a string representation of this object. * @return A string representation of the instance. */ toString(): string; /** * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles. * * @param b The second Rectangle object. * @param out Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return A Rectangle object that is the union of the two Rectangles. */ union(b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle; } /** * A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and * render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time. */ class RenderTexture extends PIXI.Texture { /** * A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and * render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time. * * @param game Current game instance. * @param width The width of the render texture. - Default: 100 * @param height The height of the render texture. - Default: 100 * @param key The key of the RenderTexture in the Cache, if stored there. - Default: '' * @param scaleMode One of the Phaser.scaleModes consts. - Default: Phaser.scaleModes.DEFAULT * @param resolution The resolution of the texture being generated. - Default: 1 */ constructor(game: Phaser.Game, width?: number, height?: number, key?: string, scaleMode?: Phaser.scaleModes, resolution?: number); /** * This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering, * irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases) */ crop: PIXI.Rectangle; /** * A reference to the currently running game. */ game: Phaser.Game; /** * The key of the RenderTexture in the Cache, if stored there. */ key: string; /** * Base Phaser object type. */ type: number; /** * Clears the RenderTexture. */ clear(): void; /** * This function will draw the display object to the RenderTexture. * * In versions of Phaser prior to 2.4.0 the second parameter was a Phaser.Point object. * This is now a Matrix allowing you much more control over how the Display Object is rendered. * If you need to replicate the earlier behavior please use Phaser.RenderTexture.renderXY instead. * * If you wish for the displayObject to be rendered taking its current scale, rotation and translation into account then either * pass `null`, leave it undefined or pass `displayObject.worldTransform` as the matrix value. * * @param displayObject The display object to render to this texture. * @param matrix Optional matrix to apply to the display object before rendering. If null or undefined it will use the worldTransform matrix of the given display object. * @param clear If true the texture will be cleared before the display object is drawn. */ render(displayObject: PIXI.DisplayObject, matrix?: Phaser.Matrix, clear?: boolean): void; /** * This function will draw the display object to the RenderTexture at the given coordinates. * * When the display object is drawn it takes into account scale and rotation. * * If you don't want those then use RenderTexture.renderRawXY instead. * * @param displayObject The display object to render to this texture. * @param x The x position to render the object at. * @param y The y position to render the object at. * @param clear If true the texture will be cleared before the display object is drawn. */ renderXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void; /** * This function will draw the display object to the RenderTexture at the given coordinates. * * When the display object is drawn it doesn't take into account scale, rotation or translation. * * If you need those then use RenderTexture.renderXY instead. * * @param displayObject The display object to render to this texture. * @param x The x position to render the object at. * @param y The y position to render the object at. * @param clear If true the texture will be cleared before the display object is drawn. */ renderRawXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void; } /** * Abstracts away the use of RAF or setTimeOut for the core game update loop. */ class RequestAnimationFrame { /** * Abstracts away the use of RAF or setTimeOut for the core game update loop. * * @param game A reference to the currently running game. * @param forceSetTimeOut Tell Phaser to use setTimeOut even if raf is available. */ constructor(game: Phaser.Game, forceSetTimeOut?: boolean); /** * Tell Phaser to use setTimeOut even if raf is available. */ forceSetTimeOut: boolean; /** * The currently running game. */ game: Phaser.Game; /** * true if RequestAnimationFrame is running, otherwise false. */ isRunning: boolean; /** * Is the browser using requestAnimationFrame? */ isRAF(): boolean; /** * Is the browser using setTimeout? */ isSetTimeOut(): boolean; /** * Starts the requestAnimationFrame running or setTimeout if unavailable in browser */ start(): boolean; /** * Stops the requestAnimationFrame from running. */ stop(): void; /** * The update method for the requestAnimationFrame */ updateRAF(rafTime: number): void; /** * The update method for the setTimeout. */ updateSetTimeout(time: number): void; } /** * A Retro Font is similar to a BitmapFont, in that it uses a texture to render the text. However unlike a BitmapFont every character in a RetroFont * is the same size. This makes it similar to a sprite sheet. You typically find font sheets like this from old 8/16-bit games and demos. */ class RetroFont extends Phaser.RenderTexture { /** * A Retro Font is similar to a BitmapFont, in that it uses a texture to render the text. However unlike a BitmapFont every character in a RetroFont * is the same size. This makes it similar to a sprite sheet. You typically find font sheets like this from old 8/16-bit games and demos. * * @param game Current game instance. * @param key The font set graphic set as stored in the Game.Cache. * @param characterWidth The width of each character in the font set. * @param characterHeight The height of each character in the font set. * @param chars The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements. * @param charsPerRow The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth. * @param xSpacing If the characters in the font set have horizontal spacing between them set the required amount here. * @param ySpacing If the characters in the font set have vertical spacing between them set the required amount here. * @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. * @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. */ constructor(game: Phaser.Game, key: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow?: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number); /** * Align each line of multi-line text in the center. */ static ALIGN_CENTER: string; /** * Align each line of multi-line text to the left. */ static ALIGN_LEFT: string; /** * Align each line of multi-line text to the right. */ static ALIGN_RIGHT: string; /** * Text Set 1 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ */ static TEXT_SET1: string; /** * Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ */ static TEXT_SET2: string; /** * Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 */ static TEXT_SET3: string; /** * Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 */ static TEXT_SET4: string; /** * Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789 */ static TEXT_SET5: string; /** * Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.' */ static TEXT_SET6: string; /** * Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39 */ static TEXT_SET7: string; /** * Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ */ static TEXT_SET8: string; /** * Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?! */ static TEXT_SET9: string; /** * Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ */ static TEXT_SET10: string; /** * Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789 */ static TEXT_SET11: string; /** * Alignment of the text when multiLine = true or a fixedWidth is set. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. */ align: string; /** * Automatically convert any text to upper case. Lots of old bitmap fonts only contain upper-case characters, so the default is true. * Default: true */ autoUpperCase: boolean; /** * The height of each character in the font set. */ characterHeight: number; /** * The number of characters per row in the font set. */ characterPerRow: number; /** * If the characters in the font set have horizontal spacing between them set the required amount here. */ characterSpacingX: number; /** * If the characters in the font set have vertical spacing between them set the required amount here. */ characterSpacingY: number; /** * The width of each character in the font set. */ characterWidth: number; /** * Adds horizontal spacing between each character of the font, in pixels. */ customSpacingX: number; /** * Adds vertical spacing between each line of multi-line text, set in pixels. */ customSpacingY: number; /** * If you need this RetroFont image to have a fixed width you can set the width in this value. * If text is wider than the width specified it will be cropped off. */ fixedWidth: number; /** * A reference to the image stored in the Game.Cache that contains the font. */ fontSet: Image; /** * The FrameData representing this Retro Font. */ frameData: Phaser.FrameData; /** * If set to true all carriage-returns in text will form new lines (see align). If false the font will only contain one single line of text (the default) */ multiLine: boolean; /** * If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. */ offsetX: number; /** * If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. */ offsetY: number; /** * Sets if the stamp is smoothed or not. */ smoothed: boolean; /** * The image that is stamped to the RenderTexture for each character in the font. */ stamp: Phaser.Image; /** * Set this value to update the text in this sprite. Carriage returns are automatically stripped out if multiLine is false. Text is converted to upper case if autoUpperCase is true. */ text: string; /** * Updates the texture with the new text. */ buildRetroFontText(): void; /** * Works out the longest line of text in _text and returns its length * @return The length of the longest line of text. */ getLongestLine(): number; /** * Internal function that takes a single line of text (2nd parameter) and pastes it into the BitmapData at the given coordinates. * Used by getLine and getMultiLine * * @param line The single line of text to paste. * @param x The x coordinate. * @param y The y coordinate. * @param customSpacingX Custom X spacing. */ pasteLine(line: string, x: number, y: number, customSpacingX: number): void; /** * Internal helper function that removes all unsupported characters from the _text String, leaving only characters contained in the font set. * * @param stripCR Should it strip carriage returns as well? - Default: true * @return A clean version of the string. */ removeUnsupportedCharacters(stripCR?: boolean): string; /** * If you need this RetroFont to have a fixed width and custom alignment you can set the width here. * If text is wider than the width specified it will be cropped off. * * @param width Width in pixels of this RetroFont. Set to zero to disable and re-enable automatic resizing. * @param lineAlignment Align the text within this width. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. - Default: 'left' */ setFixedWidth(width: number, lineAlignment?: string): void; /** * A helper function that quickly sets lots of variables at once, and then updates the text. * * @param content The text of this sprite. * @param multiLine Set to true if you want to support carriage-returns in the text and create a multi-line sprite instead of a single line. * @param characterSpacing To add horizontal spacing between each character specify the amount in pixels. * @param lineSpacing To add vertical spacing between each line of text, set the amount in pixels. * @param lineAlignment Align each line of multi-line text. Set to RetroFont.ALIGN_LEFT, RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. - Default: 'left' * @param allowLowerCase Lots of bitmap font sets only include upper-case characters, if yours needs to support lower case then set this to true. */ setText(content: string, multiLine?: boolean, characterSpacing?: number, lineSpacing?: number, lineAlignment?: string, allowLowerCase?: boolean): void; /** * Updates the x and/or y offset that the font is rendered from. This updates all of the texture frames, so be careful how often it is called. * Note that the values given for the x and y properties are either ADDED to or SUBTRACTED from (if negative) the existing offsetX/Y values of the characters. * So if the current offsetY is 8 and you want it to start rendering from y16 you would call updateOffset(0, 8) to add 8 to the current y offset. * * @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. * @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. */ updateOffset(x?: number, y?: number): void; } /** * A Rope is a Sprite that has a repeating texture. * * The texture will automatically wrap on the edges as it moves. * * Please note that Ropes cannot have an input handler. */ class Rope extends PIXI.Rope { /** * A Rope is a Sprite that has a repeating texture. * * The texture will automatically wrap on the edges as it moves. * * Please note that Ropes cannot have an input handler. * * @param game A reference to the currently running game. * @param x The x coordinate (in world space) to position the Rope at. * @param y The y coordinate (in world space) to position the Rope at. * @param key This is the image or texture used by the Rope during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. * @param frame If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param points An array of {Phaser.Point}. */ constructor(game: Phaser.Game, x: number, y: number, key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video, frame?: string | number, points?: Phaser.Point[]); /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated * properties and methods via it. * * By default Game Objects won't add themselves to any physics system and their `body` property will be `null`. * * To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object * and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`. * * You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group. * * Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5, * so the physics body is centered on the Game Object. * * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. */ body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * If this is set to `true` the Game Object checks if it is within the World bounds each frame. * * When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event. * * If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event. * * It also optionally kills the Game Object if `outOfBoundsKill` is `true`. * * When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ checkWorldBounds: boolean; /** * The Rectangle used to crop the texture this Game Object uses. * Set this property via `crop`. * If you modify this property directly you must call `updateCrop` in order to have the change take effect. */ cropRect: Phaser.Rectangle; /** * The components this Game Object has installed. */ components: any; /** * Does this texture require a custom render call? (as set by BitmapData, Video, etc) */ customRender: boolean; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; /** * Returns the delta x value. The difference between world.x now and in the previous frame. * * The value will be positive if the Game Object has moved to the right or negative if to the left. */ deltaX: number; /** * Returns the delta y value. The difference between world.y now and in the previous frame. * * The value will be positive if the Game Object has moved down or negative if up. */ deltaY: number; /** * Returns the delta z value. The difference between rotation now and in the previous frame. The delta value. */ deltaZ: number; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * Controls if this Game Object is processed by the core game loop. * If this Game Object has a physics body it also controls if its physics body is updated or not. * When `exists` is set to `false` it will remove its physics body from the physics world if it has one. * It also toggles the `visible` property to false as well. * * Setting `exists` to true will add its physics body back in to the physics world, if it has one. * It will also set the `visible` property to `true`. */ exists: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * Gets or sets the current frame index of the texture being used to render this Game Object. * * To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use, * for example: `player.frame = 4`. * * If the frame index given doesn't exist it will revert to the first frame found in the texture. * * If you are using a texture atlas then you should use the `frameName` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frame: string | number; /** * Gets or sets the current frame name of the texture being used to render this Game Object. * * To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use, * for example: `player.frameName = "idle"`. * * If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning. * * If you are using a sprite sheet then you should use the `frame` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frameName: string; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; input: Phaser.InputHandler; inputEnabled: boolean; /** * Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds. */ inWorld: boolean; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * The lifespan allows you to give a Game Object a lifespan in milliseconds. * * Once the Game Object is 'born' you can set this to a positive value. * * It is automatically decremented by `game.time.delta` each frame. * When it reaches zero it will call the `kill` method. * * Very handy for particles, bullets, collectibles, or any other short-lived entity. */ lifespan: number; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false. */ outOfBoundsKill: boolean; /** * Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object, * which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result. * * This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result. * * Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency. * It should be fine for low-volume testing where physics isn't required. * * @param displayObject The display object to check against. * @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object. */ overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; points: Phaser.Point[]; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The segments that make up the rope body as an array of Phaser.Rectangles */ segments: Phaser.Rectangle[]; /** * Enable or disable texture smoothing for this Game Object. * * It only takes effect if the Game Object is using an image based texture. * * Smoothing is enabled by default. */ smoothed: boolean; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The const type of this object. */ type: number; /** * The callback that will apply any scale limiting to the worldTransform. */ transformCallback: Function; /** * The context under which `transformCallback` is called. */ transformCallbackContext: any; /** * The minimum scale this Game Object will scale down to. * * It allows you to prevent a parent from scaling this Game Object lower than the given value. * * Set it to `null` to remove the limit. */ scaleMin: Phaser.Point; /** * The maximum scale this Game Object will scale up to. * * It allows you to prevent a parent from scaling this Game Object higher than the given value. * * Set it to `null` to remove the limit. */ scaleMax: Phaser.Point; /** * A Rope will call its updateAnimation function on each update loop if it has one. Set to a function if you'd like the rope to animate during the update phase. Set to false or null to remove it. */ updateAnimation: Function; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The horizontal position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ x: number; /** * The vertical position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ y: number; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Brings this Game Object to the top of its parent's display list (the last position). * Visually this means it will render over the top of all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will bring it to the top of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ bringToTop(): Phaser.Rope; /** * Adjust scaling limits, if set, to this Game Object. * * @param wt The updated worldTransform matrix. */ checkTransform(wt: Phaser.Matrix): void; /** * Crop allows you to crop the texture being used to display this Game Object. * Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly. * * Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method, * or by modifying `cropRect` property directly and then calling `updateCrop`. * * The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object * so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties. * * A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`, * in which case the values are duplicated to a local object. * * @param rect The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle. * @param copy If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect. */ crop(rect: Phaser.Rectangle, copy?: boolean): void; /** * Destroy this DisplayObject. * * Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask. * * Also iteratively calls `destroy` on any children. */ destroy(destroyChildren?: boolean): void; /** * Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false. * * It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal. * * Note that killing a Game Object is a way for you to quickly recycle it in an object pool, * it doesn't destroy the object or free it up from memory. * * If you don't need this Game Object any more you should call `destroy` instead. * @return This instance. */ kill(): Phaser.Rope; /** * Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache. * * If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead. * * You should only use `loadTexture` if you want to replace the base texture entirely. * * Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU. * * You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. * Doing this then sets the key to be the `frame` argument (the frame is set to zero). * * This allows you to create sprites using `load.image` during development, and then change them * to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' * and swapping it to be the key of the atlas data. * * Note: You cannot use a RenderTexture as a texture for a TileSprite. * * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true */ loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void; /** * Moves this Game Object up one place in its parent's display list. * This call has no effect if the Game Object is already at the top of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object up within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveUp(): Phaser.Rope; /** * Moves this Game Object down one place in its parents display list. * This call has no effect if the Game Object is already at the bottom of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveDown(): Phaser.Rope; /** * Plays an Animation. * * The animation should have previously been created via `animations.add`. * * If the animation is already playing calling this again won't do anything. * If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`. * * @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'. * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return A reference to playing Animation. */ play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Automatically called by World.preUpdate. */ preUpdate(): void; /** * Internal method called by the World postUpdate cycle. */ postUpdate(): void; /** * Resets the Rope. This places the Rope at the given x/y world coordinates and then * sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state. * If the Rope has a physics body that too is reset. * * @param x The x coordinate (in world space) to position the Sprite at. * @param y The y coordinate (in world space) to position the Sprite at. * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.Rope; /** * Resizes the Frame dimensions that the Game Object uses for rendering. * * You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData * it can be useful to adjust the dimensions directly in this way. * * @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object. * @param width The new width of the texture. * @param height The new height of the texture. */ resizeFrame(parent: any, width: number, height: number): void; /** * Resets the texture frame dimensions that the Game Object uses for rendering. */ resetFrame(): void; /** * Brings a 'dead' Game Object back to life, optionally resetting its health value in the process. * * A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true. * * It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal. * * @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100 * @return This instance. */ revive(health?: number): Phaser.Rope; /** * Sends this Game Object to the bottom of its parent's display list (the first position). * Visually this means it will render below all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will send it to the bottom of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ sendToBack(): Phaser.Rope; /** * Sets the texture frame the Game Object uses for rendering. * * This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes. * * @param frame The Frame to be used by the texture. */ setFrame(frame: Phaser.Frame): void; /** * Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent. * * For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored * and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to. * * By setting these values you can carefully control how Game Objects deal with responsive scaling. * * If only one parameter is given then that value will be used for both scaleMin and scaleMax: * `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1 * * If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y: * `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2 * * If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly, * or pass `null` for the `maxX` and `maxY` parameters. * * Call `setScaleMinMax(null)` to clear all previously set values. * * @param minX The minimum horizontal scale value this Game Object can scale down to. * @param minY The minimum vertical scale value this Game Object can scale down to. * @param maxX The maximum horizontal scale value this Game Object can scale up to. * @param maxY The maximum vertical scale value this Game Object can scale up to. */ setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void; // minX: null | number /** * If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property, * or the rectangle it references, then you need to update the crop frame by calling this method. */ updateCrop(): void; /** * Override and use this function in your own custom objects to handle any update requirements you may have. */ update(): void; } /** * The Rounded Rectangle object is an area defined by its position and has nice rounded corners, * as indicated by its top-left corner point (x, y) and by its width and its height. */ class RoundedRectangle { /** * The x coordinate of the top-left corner of the Rectangle. */ x: number; /** * The y coordinate of the top-left corner of the Rectangle. */ y: number; /** * The width of the Rectangle. This value should never be set to a negative. */ width: number; /** * The height of the Rectangle. This value should never be set to a negative. */ height: number; /** * The radius of the rounded corners. */ radius: number; /** * The const type of this object. */ type: number; /** * Returns a new RoundedRectangle object with the same values for the x, y, width, height and * radius properties as this RoundedRectangle object. */ clone(): RoundedRectangle; /** * Determines whether the specified coordinates are contained within the region defined by this Rounded Rectangle object. * * @param x The x coordinate of the point to test. * @param y The y coordinate of the point to test. * @return A value of true if the RoundedRectangle Rectangle object contains the specified point; otherwise false. */ contains(x: number, y: number): boolean; } /** * Signals are what Phaser uses to handle events and event dispatching. * You can listen for a Signal by binding a callback / function to it. * This is done by using either `Signal.add` or `Signal.addOnce`. * * For example you can listen for a touch or click event from the Input Manager * by using its `onDown` Signal: * * `game.input.onDown.add(function() { ... });` * * Rather than inline your function, you can pass a reference: * * `game.input.onDown.add(clicked, this);` * `function clicked () { ... }` * * In this case the second argument (`this`) is the context in which your function should be called. * * Now every time the InputManager dispatches the `onDown` signal (or event), your function * will be called. * * Multiple callbacks can be bound to the same signal. * They're ordered first by their `priority` arguments and then by the order in which they were added. * If a callback calls {@link Phaser.Signal#halt halt} or returns `false`, any remaining callbacks are skipped. * * Very often a Signal will send arguments to your function. * This is specific to the Signal itself. * If you're unsure then check the documentation, or failing that simply do: * * `Signal.add(function() { console.log(arguments); })` * * and it will log all of the arguments your function received from the Signal. * * Sprites have lots of default signals you can listen to in their Events class, such as: * * `sprite.events.onKilled` * * Which is called automatically whenever the Sprite is killed. * There are lots of other events, see the Events component for a list. * * As well as listening to pre-defined Signals you can also create your own: * * `var mySignal = new Phaser.Signal();` * * This creates a new Signal. You can bind a callback to it: * * `mySignal.add(myCallback, this);` * * and then finally when ready you can dispatch the Signal: * * `mySignal.dispatch(your arguments);` * * And your callback will be invoked. See the dispatch method for more details. */ class Signal { /** * Is the Signal active? Only active signals will broadcast dispatched events. * * Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use {@link Phaser.Signal#halt halt}. * Default: true */ active: boolean; boundDispatch: Function; /** * Memorize the previously dispatched event? * * If an event has been memorized it is automatically dispatched when a new listener is added with {@link Phaser.Signal#add add} or {@link Phaser.Signal#addOnce addOnce}. * Use {@link Phaser.Signal#forget forget} to clear any currently memorized event. */ memorize: boolean; /** * Add an event listener for this signal. * * An event listener is a callback with a related context and priority. * * You can optionally provide extra arguments which will be passed to the callback after any internal parameters. * * For example: `Phaser.Key.onDown` when dispatched will send the Phaser.Key object that caused the signal as the first parameter. * Any arguments you've specified after `priority` will be sent as well: * * `fireButton.onDown.add(shoot, this, 0, 'lazer', 100);` * * When onDown dispatches it will call the `shoot` callback passing it: `Phaser.Key, 'lazer', 100`. * * Where the first parameter is the one that Key.onDown dispatches internally and 'lazer', * and the value 100 were the custom arguments given in the call to 'add'. * * If the callback calls {@link Phaser.Signal#halt halt} or returns `false`, any remaining callbacks bound to this Signal are skipped. * * @param listener The function to call when this Signal is dispatched. * @param listenerContext The context under which the listener will be executed (i.e. the object that should represent the `this` variable). * @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0) * @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none) * @return An Object representing the binding between the Signal and listener. */ add(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding; /** * Add a one-time listener - the listener is automatically removed after the first execution. * * If there is as {@link Phaser.Signal#memorize memorized} event then it will be dispatched and * the listener will be removed immediately. * * @param listener The function to call when this Signal is dispatched. * @param listenerContext The context under which the listener will be executed (i.e. the object that should represent the `this` variable). * @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0) * @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none) * @return An Object representing the binding between the Signal and listener. */ addOnce(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding; /** * Dispatch / broadcast the event to all listeners. * * To create an instance-bound dispatch for this Signal, use {@link Phaser.Signal#boundDispatch boundDispatch}. * * @param params Parameters that should be passed to each handler. */ dispatch(...params: any[]): void; /** * Dispose the signal - no more events can be dispatched. * * This removes all event listeners and clears references to external objects. * Calling methods on a disposed objects results in undefined behavior. */ dispose(): void; /** * Forget the currently {@link Phaser.Signal#memorize memorized} event, if any. */ forget(): void; /** * Gets the total number of listeners attached to this Signal. * @return Number of listeners attached to the Signal. */ getNumListeners(): number; /** * Stop propagation of the event, blocking the dispatch to next listener on the queue. * * This should be called only during event dispatch as calling it before/after dispatch won't affect another broadcast. * See {@link Phaser.Signal#active active} to enable/disable the signal entirely. */ halt(): void; /** * Check if a specific listener is attached. * * @param listener Signal handler function. * @param context Context on which listener will be executed (object that should represent the `this` variable inside listener function). * @return If Signal has the specified listener. */ has(listener: Function, context?: any): boolean; /** * Remove a single event listener. * * @param listener Handler function that should be removed. * @param context Execution context (since you can add the same handler multiple times if executing in a different context). * @return Listener handler function. */ remove(listener: Function, context?: any): Function; /** * Remove all event listeners. * * @param context If specified only listeners for the given context will be removed. */ removeAll(context?: any): void; /** * A string representation of the object. * @return String representation of the object. */ toString(): string; /** * * * @param listener Signal handler function. * @param fnName Function name. */ validateListener(listener: Function, fnName: string): void; } /** * Object that represents a binding between a Signal and a listener function. * This is an internal constructor and shouldn't be created directly. * Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes. */ class SignalBinding { /** * Object that represents a binding between a Signal and a listener function. * This is an internal constructor and shouldn't be created directly. * Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes. * * @param signal Reference to Signal object that listener is currently bound to. * @param listener Handler function bound to the signal. * @param isOnce If binding should be executed just once. * @param listenerContext Context on which listener will be executed (object that should represent the `this` variable inside listener function). * @param priority The priority level of the event listener. (default = 0). * @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none) */ constructor(signal: Phaser.Signal, listener: Function, isOnce: boolean, listenerContext?: any, priority?: number, ...args: any[]); /** * If binding is active and should be executed. * Default: true */ active: boolean; /** * The number of times the handler function has been called. */ callCount: number; /** * Context on which listener will be executed (object that should represent the `this` variable inside listener function). */ context: any; /** * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters). */ params: any[]; /** * Call listener passing arbitrary parameters. * If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch. * * @param paramsArr Array of parameters that should be passed to the listener. * @return Value returned by the listener. */ execute(paramsArr?: any[]): void; /** * Detach binding from signal. * alias to: @see mySignal.remove(myBinding.getListener()); * @return Handler function bound to the signal or `null` if binding was previously detached. */ detach(): Function; /** * * @return True if binding is still bound to the signal and has a listener. */ isBound(): boolean; /** * * @return If SignalBinding will only be executed once. */ isOnce(): boolean; /** * * @return Handler function bound to the signal. */ getListener(): Function; /** * * @return Signal that listener is currently bound to. */ getSignal(): Phaser.Signal; /** * * @return String representation of the object. */ toString(): string; } /** * A single Phaser Gamepad */ class SinglePad { /** * A single Phaser Gamepad * * @param game Current game instance. * @param padParent The parent Phaser.Gamepad object (all gamepads reside under this) */ constructor(game: Phaser.Game, padParent: any); /** * The context under which the callbacks are run. */ callbackContext: any; /** * Whether or not this particular gamepad is connected or not. */ connected: boolean; /** * Dead zone for axis feedback - within this value you won't trigger updates. */ deadZone: number; /** * Local reference to game. */ game: Phaser.Game; /** * The gamepad index as per browsers data */ index: number; /** * This callback is invoked every time an axis is changed. */ onAxisCallback: Function; /** * This callback is invoked every time this gamepad is connected */ onConnectCallback: Function; /** * This callback is invoked every time this gamepad is disconnected */ onDisconnectCallback: Function; /** * This callback is invoked every time a button is pressed down. */ onDownCallback: Function; /** * This callback is invoked every time a button is changed to a value where value > 0 and value < 1. */ onFloatCallback: Function; /** * This callback is invoked every time a gamepad button is released. */ onUpCallback: Function; /** * Returns value of requested axis. * * @param axisCode The index of the axis to check * @return Axis value if available otherwise false */ axis(axisCode: number): number; /** * Add callbacks to this Gamepad to handle connect / disconnect / button down / button up / axis change / float value buttons. * * @param context The context under which the callbacks are run. * @param callbacks Object that takes six different callbak methods: * onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback */ addCallbacks(context: any, callbacks: any): void; /** * Returns the value of a gamepad button. Intended mainly for cases when you have floating button values, for example * analog trigger buttons on the XBOX 360 controller. * * @param buttonCode The buttonCode of the button to check. * @return Button value if available otherwise null. Be careful as this can incorrectly evaluate to 0. */ buttonValue(buttonCode: number): number; /** * Gamepad connect function, should be called by Phaser.Gamepad. * * @param rawPad The raw gamepad object */ connect(rawPad: any): void; /** * Destroys this object and associated callback references. */ destroy(): void; /** * Gamepad disconnect function, should be called by Phaser.Gamepad. */ disconnect(): void; /** * Gets a DeviceButton object from this controller to be stored and referenced locally. * The DeviceButton object can then be polled, have events attached to it, etc. * * @param buttonCode The buttonCode of the button, i.e. Phaser.Gamepad.BUTTON_0, Phaser.Gamepad.XBOX360_A, etc. * @return The DeviceButton object which you can store locally and reference directly. */ getButton(buttonCode: number): Phaser.DeviceButton; /** * Returns true if the button is pressed down. * * @param buttonCode The buttonCode of the button to check. * @return True if the button is pressed down. */ isDown(buttonCode: number): boolean; /** * Returns true if the button is not currently pressed. * * @param buttonCode The buttonCode of the button to check. * @return True if the button is not currently pressed down. */ isUp(buttonCode: number): boolean; /** * Returns the "just pressed" state of a button from this gamepad. Just pressed is considered true if the button was pressed down within the duration given (default 250ms). * * @param buttonCode The buttonCode of the button to check for. * @param duration The duration below which the button is considered as being just pressed. - Default: 250 * @return True if the button is just pressed otherwise false. */ justPressed(buttonCode: number, duration?: number): boolean; /** * Returns the "just released" state of a button from this gamepad. Just released is considered as being true if the button was released within the duration given (default 250ms). * * @param buttonCode The buttonCode of the button to check for. * @param duration The duration below which the button is considered as being just released. - Default: 250 * @return True if the button is just released otherwise false. */ justReleased(buttonCode: number, duration?: number): boolean; /** * Main update function called by Phaser.Gamepad. */ pollStatus(): void; /** * Handles changes in axis. * * @param axisState State of the relevant axis */ processAxisChange(axisState: any): void; /** * Handles button down press. * * @param buttonCode Which buttonCode of this button * @param value Button value */ processButtonDown(buttonCode: number, value: any): void; /** * Handles buttons with floating values (like analog buttons that acts almost like an axis but still registers like a button) * * @param buttonCode Which buttonCode of this button * @param value Button value (will range somewhere between 0 and 1, but not specifically 0 or 1. */ processButtonFloat(buttonCode: number, value: any): void; /** * Handles button release. * * @param buttonCode Which buttonCode of this button * @param value Button value */ processButtonUp(buttonCode: number, value: any): void; /** * Reset all buttons/axes of this gamepad. */ reset(): void; } /** * The Sound class constructor. */ class Sound { /** * The Sound class constructor. * * @param game Reference to the current game instance. * @param key Asset key for the sound. * @param volume Default value for the volume, between 0 and 1. - Default: 1 * @param loop Whether or not the sound will loop. */ constructor(game: Phaser.Game, key: string, volume?: number, loop?: boolean, connect?: boolean); /** * Whether the sound should start automatically. */ autoplay: boolean; /** * This will allow you to have multiple instances of this Sound playing at once. This is only useful when running under Web Audio, and we recommend you implement a local pooling system to not flood the sound channels. */ allowMultiple: boolean; /** * Reference to the AudioContext instance. */ context: any; /** * The string ID of the currently playing marker, if any. */ currentMarker: string; /** * The current time of sound playback in ms. */ currentTime: number; /** * Destroys this sound and all associated events and removes it from the SoundManager. * * @param remove If true this Sound is automatically removed from the SoundManager. - Default: true */ destroy(remove?: boolean): void; /** * The duration of the current sound marker in seconds. */ duration: number; /** * The duration of the current sound marker in ms. */ durationMS: number; /** * If defined this Sound won't connect to the SoundManager master gain node, but will instead connect to externalNode. */ externalNode: any; /** * The tween that fades the audio, set via Sound.fadeIn and Sound.fadeOut. */ fadeTween: Phaser.Tween; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The gain node in a Web Audio system. */ gainNode: any; /** * Returns true if the sound file has decoded. */ isDecoded: boolean; /** * Returns true if the sound file is still decoding. */ isDecoding: boolean; /** * Whether the sound is currently playing. */ isPlaying: boolean; /** * Asset key for the sound. */ key: string; /** * Whether or not the sound or current sound marker will loop. */ loop: boolean; /** * The sound markers. */ markers: any; /** * The master gain node in a Web Audio system. */ masterGainNode: any; /** * Gets or sets the muted state of this sound. */ mute: boolean; /** * Name of the sound. */ name: string; /** * The onDecoded event is dispatched when the sound has finished decoding (typically for mp3 files). It passes one argument, this sound. */ onDecoded: Phaser.Signal; onEndedHandler: () => void; /** * The onFadeComplete event is dispatched when this sound finishes fading either in or out. It passes two arguments: this sound and its current {@link Phaser.Sound#volume volume}. */ onFadeComplete: Phaser.Signal; /** * The onLoop event is dispatched when this sound loops during playback. It passes one argument, this sound. */ onLoop: Phaser.Signal; /** * The onMarkerComplete event is dispatched when a marker within this sound completes playback. It passes two arguments: the {@link Phaser.Sound#currentMarker currentMarker} and this sound. */ onMarkerComplete: Phaser.Signal; /** * The onMute event is dispatched when this sound is muted. It passes one argument, this sound. */ onMute: Phaser.Signal; /** * The onPause event is dispatched when this sound is paused. It passes one argument, this sound. */ onPause: Phaser.Signal; /** * The onPlay event is dispatched each time this sound is played (but not looped). It passes one argument, this sound. */ onPlay: Phaser.Signal; /** * The onResume event is dispatched when this sound is resumed from a paused state. It passes one argument, this sound. */ onResume: Phaser.Signal; /** * The onStop event is dispatched when this sound stops playback or when a non-looping marker completes. It passes two arguments: this sound and any {@link #currentMarker marker} that was playing. */ onStop: Phaser.Signal; /** * When playing this sound, always start from the beginning. */ override: boolean; /** * Whether the sound is paused. */ paused: boolean; /** * The position the sound had reached when it was paused in ms. */ pausedPosition: number; /** * The clock time (ms) at which the sound was paused. */ pausedTime: number; /** * Playback is pending (delayed) because the audio isn't decoded or is touch-locked. */ pendingPlayback: boolean; /** * Marks the Sound for deletion from SoundManager after playing once. Useful for playing several identical sounds overlapping without flooding the sound channel */ playOnce: boolean; /** * The position of the current sound marker in seconds. */ position: number; /** * The time the sound starts playing, in game-time coordinates (ms). */ startTime: number; /** * The time the sound stopped in ms. */ stopTime: number; /** * The total duration of the sound in seconds. */ totalDuration: number; /** * Whether this sound is being played via the Audio tag. */ usingAudioTag: boolean; /** * Whether this sound is being played with Web Audio. */ usingWebAudio: boolean; /** * Gets or sets the volume of this sound, a value between 0 and 1. The value given is clamped to the range 0 to 1. */ volume: number; /** * Adds a marker into the current Sound. A marker is represented by a unique key and a start time and duration. * This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback. * * @param name A unique name for this marker, i.e. 'explosion', 'gunshot', etc. * @param start The start point of this marker in the audio file, given in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc. * @param duration The duration of the marker in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc. - Default: 1 * @param volume The volume the sound will play back at, between 0 (silent) and 1 (full volume). - Default: 1 * @param loop Sets if the sound will loop or not. */ addMarker(name: string, start: number, duration: number, volume?: number, loop?: boolean): void; /** * Destroys this sound and all associated events and removes it from the SoundManager. * * @param remove If true this Sound is automatically removed from the SoundManager. - Default: true */ destroy(): void; /** * Starts this sound playing (or restarts it if already doing so) and sets the volume to zero. * Then increases the volume from 0 to 1 over the duration specified. * * At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter, * and the final volume (1) as the second parameter. * * @param duration The time in milliseconds over which the Sound should fade in. - Default: 1000 * @param loop Should the Sound be set to loop? Note that this doesn't cause the fade to repeat. * @param marker The marker to start at; defaults to the current (last played) marker. To start playing from the beginning specify specify a marker of `''`. - Default: (current marker) */ fadeIn(duration?: number, loop?: boolean, marker?: string): void; /** * Decreases the volume of this Sound from its current value to 0 over the duration specified. * At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter, * and the final volume (0) as the second parameter. * * @param duration The time in milliseconds over which the Sound should fade out. - Default: 1000 */ fadeOut(duration?: number): void; /** * Fades the volume of this Sound from its current value to the given volume over the duration specified. * At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter, * and the final volume (volume) as the second parameter. * * @param duration The time in milliseconds during which the Sound should fade out. - Default: 1000 * @param volume The volume which the Sound should fade to. This is a value between 0 and 1. */ fadeTo(duration?: number, volume?: number): void; /** * Loops this entire sound. If you need to loop a section of it then use Sound.play and the marker and loop parameters. * * @param volume Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified). - Default: 1 * @return This sound instance. */ loopFull(volume?: number): Phaser.Sound; /** * Pauses the sound. */ pause(): void; /** * Play this sound, or a marked section of it. * * @param marker If you want to play a marker then give the key here, otherwise leave blank to play the full sound. - Default: '' * @param position The starting position to play the sound from - this is ignored if you provide a marker. * @param volume Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified). - Default: 1 * @param loop Loop when finished playing? If not using a marker / audio sprite the looping will be done via the WebAudio loop property, otherwise it's time based. * @param forceRestart If the sound is already playing you can set forceRestart to restart it from the beginning. - Default: true * @param onPlay Dispatch the `onPlay` signal. - Default: true * @return This sound instance. */ play(marker?: string, position?: number, volume?: number, loop?: boolean, forceRestart?: boolean): Phaser.Sound; /** * Removes a marker from the sound. * * @param name The key of the marker to remove. */ removeMarker(name: string): void; /** * Restart the sound, or a marked section of it. * * @param marker If you want to play a marker then give the key here, otherwise leave blank to play the full sound. - Default: '' * @param position The starting position to play the sound from - this is ignored if you provide a marker. * @param volume Volume of the sound you want to play. - Default: 1 * @param loop Loop when it finished playing? */ restart(marker: string, position: number, volume?: number, loop?: boolean): void; /** * Resumes the sound. */ resume(): void; /** * Called automatically when this sound is unlocked. * * @param key The Phaser.Cache key of the sound file to check for decoding. */ soundHasUnlocked(key: string): void; /** * Stop playing this sound. */ stop(): void; /** * Called automatically by Phaser.SoundManager. */ update(): void; } /** * The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it. * Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files. * 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: http://hpr.dogphilosophy.net/test/ * * If you are reloading a Phaser Game on a page that never properly refreshes (such as in an AngularJS project) then you will quickly run out * of AudioContext nodes. If this is the case create a global var called {@link PhaserGlobal} on the window object before creating the game. The active * AudioContext will then be saved to `window.PhaserGlobal.audioContext` when the Phaser game is destroyed, and re-used when it starts again. * * Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio. * When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system. * The solution is to use a lower encoding rate such as 44100 Hz. Sometimes the audio context will * be created with a sampleRate of 48000. If this happens and audio distorts you should re-create the context. */ class SoundManager { /** * The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it. * Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files. * 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: http://hpr.dogphilosophy.net/test/ * * If you are reloading a Phaser Game on a page that never properly refreshes (such as in an AngularJS project) then you will quickly run out * of AudioContext nodes. If this is the case create a global var called {@link PhaserGlobal} on the window object before creating the game. The active * AudioContext will then be saved to `window.PhaserGlobal.audioContext` when the Phaser game is destroyed, and re-used when it starts again. * * Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio. * When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system. * The solution is to use a lower encoding rate such as 44100 Hz. Sometimes the audio context will * be created with a sampleRate of 48000. If this happens and audio distorts you should re-create the context. * * @param game Reference to the current game instance. */ constructor(game: Phaser.Game); /** * The number of audio channels to use in playback. * Default: 32 */ channels: number; /** * Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node. * Default: true */ connectToMaster: boolean; /** * The AudioContext being used for playback. */ context: any; /** * Local reference to game. */ game: Phaser.Game; /** * Gets or sets the muted state of the SoundManager. This effects all sounds in the game. */ mute: boolean; /** * Set to true to have all sound muted when the Phaser game pauses (such as on loss of focus), * or set to false to keep audio playing, regardless of the game pause state. You may need to * do this should you wish to control audio muting via external DOM buttons or similar. * Default: true */ muteOnPause: boolean; /** * True if audio been disabled via the PhaserGlobal (useful if you need to use a 3rd party audio library) or the device doesn't support any audio. */ noAudio: boolean; /** * The event dispatched when a sound decodes (typically only for mp3 files) */ onSoundDecode: Phaser.Signal; /** * This signal is dispatched whenever the global volume changes. The new volume is passed as the only parameter to your callback. */ onVolumeChange: Phaser.Signal; /** * This signal is dispatched when the SoundManager is globally muted, either directly via game code or as a result of the game pausing. */ onMute: Phaser.Signal; /** * This signal is dispatched when the SoundManager is globally un-muted, either directly via game code or as a result of the game resuming from a pause. */ onUnMute: Phaser.Signal; /** * true if the audio system is currently locked awaiting a touch event. */ touchLocked: boolean; /** * True the SoundManager and device are both using the Audio tag instead of Web Audio. */ usingAudioTag: boolean; /** * True the SoundManager and device are both using Web Audio. */ usingWebAudio: boolean; /** * Gets or sets the global volume of the SoundManager, a value between 0 and 1. The value given is clamped to the range 0 to 1. */ volume: number; /** * Adds a new Sound into the SoundManager. * * @param key Asset key for the sound. * @param volume Default value for the volume. - Default: 1 * @param loop Whether or not the sound will loop. * @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true * @return The new sound instance. */ add(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound; /** * Adds a new AudioSprite into the SoundManager. * * @param key Asset key for the sound. * @return The new AudioSprite instance. */ addSprite(key: string): Phaser.AudioSprite; /** * Initialises the sound manager. */ boot(): void; /** * Decode a sound by its asset key. * * @param key Assets key of the sound to be decoded. * @param sound Its buffer will be set to decoded data. */ decode(key: string, sound?: Phaser.Sound): void; /** * Stops all the sounds in the game, then destroys them and finally clears up any callbacks. */ destroy(): void; /** * Pauses all the sounds in the game. */ pauseAll(): void; /** * Adds a new Sound into the SoundManager and starts it playing. * * @param key Asset key for the sound. * @param volume Default value for the volume. - Default: 1 * @param loop Whether or not the sound will loop. * @return The new sound instance. */ play(key: string, volume?: number, loop?: boolean): Phaser.Sound; /** * Removes a Sound from the SoundManager. The removed Sound is destroyed before removal. * * @param sound The sound object to remove. * @return True if the sound was removed successfully, otherwise false. */ remove(sound: Phaser.Sound): boolean; /** * Removes all Sounds from the SoundManager. * The removed Sounds are destroyed before removal. */ removeAll(): void; /** * Removes all Sounds from the SoundManager that have an asset key matching the given value. * The removed Sounds are destroyed before removal. * * @param key The key to match when removing sound objects. * @return The number of matching sound objects that were removed. */ removeByKey(key: string): number; /** * Resumes every sound in the game. */ resumeAll(): void; /** * This method allows you to give the SoundManager a list of Sound files, or keys, and a callback. * Once all of the Sound files have finished decoding the callback will be invoked. * The amount of time spent decoding depends on the codec used and file size. * If all of the files given have already decoded the callback is triggered immediately. * * @param files An array containing either Phaser.Sound objects or their key strings as found in the Phaser.Cache. * @param callback The callback which will be invoked once all files have finished decoding. * @param callbackContext The context in which the callback will run. */ setDecodedCallback(files: string[] | Phaser.Sound[], callback: Function, callbackContext?: any): void; /** * Sets the Input Manager touch callback to be SoundManager.unlock. * Required for iOS audio device unlocking. Mostly just used internally. */ setTouchLock(): void; /** * Stops all the sounds in the game. */ stopAll(): void; /** * Enables the audio, usually after the first touch. * @return True if the callback should be removed, otherwise false. */ unlock(): boolean; /** * Updates every sound in the game, checks for audio unlock on mobile and monitors the decoding watch list. */ update(): void; } /** * Sprites are the lifeblood of your game, used for nearly everything visual. * * At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas. * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. */ class Sprite extends PIXI.Sprite { /** * Sprites are the lifeblood of your game, used for nearly everything visual. * * At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas. * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. * * @param game A reference to the currently running game. * @param x The x coordinate (in world space) to position the Sprite at. * @param y The y coordinate (in world space) to position the Sprite at. * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. If this argument is omitted, the sprite will receive {@link Phaser.Cache.DEFAULT the default texture} (as if you had passed '__default'), but its `key` will remain empty. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ constructor(game: Phaser.Game, x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number); /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * The anchor sets the origin point of the texture. * The default (0, 0) is the top left. * (0.5, 0.5) is the center. * (1, 1) is the bottom right. * * You can modify the default values in PIXI.Sprite.defaultAnchor. */ anchor: Phaser.Point; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated * properties and methods via it. * * By default Game Objects won't add themselves to any physics system and their `body` property will be `null`. * * To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object * and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`. * * You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group. * * Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5, * so the physics body is centered on the Game Object. * * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. */ body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * The local center x coordinate of the Game Object. * This is the same as `(x - offsetX) + (width / 2)`. */ centerX: number; /** * The local center y coordinate of the Game Object. * This is the same as `(y - offsetY) + (height / 2)`. */ centerY: number; /** * If this is set to `true` the Game Object checks if it is within the World bounds each frame. * * When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event. * * If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event. * * It also optionally kills the Game Object if `outOfBoundsKill` is `true`. * * When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ checkWorldBounds: boolean; /** * The components this Game Object has installed. */ components: any; /** * The Rectangle used to crop the texture this Game Object uses. * Set this property via `crop`. * If you modify this property directly you must call `updateCrop` in order to have the change take effect. */ cropRect: Phaser.Rectangle; /** * Does this texture require a custom render call? (as set by BitmapData, Video, etc) */ customRender: boolean; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; /** * Returns the delta x value. The difference between world.x now and in the previous frame. * * The value will be positive if the Game Object has moved to the right or negative if to the left. */ deltaX: number; /** * Returns the delta y value. The difference between world.y now and in the previous frame. * * The value will be positive if the Game Object has moved down or negative if up. */ deltaY: number; /** * Returns the delta z value. The difference between rotation now and in the previous frame. The delta value. */ deltaZ: number; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}). * Default: true */ exists: boolean; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * Gets or sets the current frame index of the texture being used to render this Game Object. * * To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use, * for example: `player.frame = 4`. * * If the frame index given doesn't exist it will revert to the first frame found in the texture. * * If you are using a texture atlas then you should use the `frameName` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frame: string | number; /** * Gets or sets the current frame name of the texture being used to render this Game Object. * * To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use, * for example: `player.frameName = "idle"`. * * If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning. * * If you are using a sprite sheet then you should use the `frame` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frameName: string; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The Game Objects health value. This is a handy property for setting and manipulating health on a Game Object. * * It can be used in combination with the `damage` method or modified directly. * Default: 1 */ health: number; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; /** * Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds. */ inWorld: boolean; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * The lifespan allows you to give a Game Object a lifespan in milliseconds. * * Once the Game Object is 'born' you can set this to a positive value. * * It is automatically decremented by `game.time.delta` each frame. * When it reaches zero it will call the `kill` method. * * Very handy for particles, bullets, collectibles, or any other short-lived entity. */ lifespan: number; /** * The Game Objects maximum health value. This works in combination with the `heal` method to ensure * the health value never exceeds the maximum. * Default: 100 */ maxHealth: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false. */ outOfBoundsKill: boolean; /** * If this and the `autoCull` property are both set to `true`, then the `kill` method * is called as soon as the Game Object leaves the camera bounds. */ outOfCameraBoundsKill: boolean; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; physicsEnabled: boolean; /** * The const physics body type of this object. */ physicsType: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject * at its default size. A value of 0.5 would scale this DisplayObject by half, and so on. * * The value of this property does not reflect any scaling happening further up the display list. * To obtain that value please see the `worldScale` property. */ scale: Phaser.Point; /** * The minimum scale this Game Object will scale down to. * * It allows you to prevent a parent from scaling this Game Object lower than the given value. * * Set it to `null` to remove the limit. */ scaleMin: Phaser.Point; /** * The maximum scale this Game Object will scale up to. * * It allows you to prevent a parent from scaling this Game Object higher than the given value. * * Set it to `null` to remove the limit. */ scaleMax: Phaser.Point; /** * Enable or disable texture smoothing for this Game Object. * * It only takes effect if the Game Object is using an image based texture. * * Smoothing is enabled by default. */ smoothed: boolean; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The const type of this object. */ type: number; /** * A canvas that contains the tinted version of the Sprite (in Canvas mode, WebGL doesn't populate this) * Default: null */ tintedTexture: HTMLCanvasElement; /** * The callback that will apply any scale limiting to the worldTransform. */ transformCallback: Function; /** * The context under which `transformCallback` is called. */ transformCallbackContext: any; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The horizontal position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ x: number; /** * The vertical position of the DisplayObject, in pixels, relative to its parent. * If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead. */ y: number; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Brings this Game Object to the top of its parent's display list (the last position). * Visually this means it will render over the top of all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will bring it to the top of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ bringToTop(): Phaser.Sprite; /** * Crop allows you to crop the texture being used to display this Game Object. * Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly. * * Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method, * or by modifying `cropRect` property directly and then calling `updateCrop`. * * The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object * so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties. * * A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`, * in which case the values are duplicated to a local object. * * @param rect The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle. * @param copy If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect. */ crop(rect: Phaser.Rectangle, copy: boolean): void; /** * Adjust scaling limits, if set, to this Game Object. * * @param wt The updated worldTransform matrix. */ checkTransform(wt: Phaser.Matrix): void; /** * Damages the Game Object. This removes the given amount of health from the `health` property. * * If health is taken below or is equal to zero then the `kill` method is called. * * @param amount The amount to subtract from the current `health` value. * @return This instance. */ damage(amount: number): Phaser.Sprite; /** * Destroy this DisplayObject. * * Removes any cached sprites, sets renderable flag to false, and nulls filters, bounds and mask. * * Also iteratively calls `destroy` on any children. */ destroy(destroyChildren?: boolean): void; drawPolygon(): void; /** * Heal the Game Object. This adds the given amount of health to the `health` property. * * @param amount The amount to add to the current `health` value. The total will never exceed `maxHealth`. * @return This instance. */ heal(amount: number): Phaser.Sprite; /** * Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false. * * It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal. * * Note that killing a Game Object is a way for you to quickly recycle it in an object pool, * it doesn't destroy the object or free it up from memory. * * If you don't need this Game Object any more you should call `destroy` instead. * @return This instance. */ kill(): Phaser.Sprite; /** * Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache. * * If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead. * * You should only use `loadTexture` if you want to replace the base texture entirely. * * Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU. * * You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. * Doing this then sets the key to be the `frame` argument (the frame is set to zero). * * This allows you to create sprites using `load.image` during development, and then change them * to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' * and swapping it to be the key of the atlas data. * * Note: You cannot use a RenderTexture as a texture for a TileSprite. * * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true */ loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void; /** * Moves this Game Object up one place in its parent's display list. * This call has no effect if the Game Object is already at the top of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object up within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveUp(): Phaser.Sprite; /** * Moves this Game Object down one place in its parents display list. * This call has no effect if the Game Object is already at the bottom of the display list. * * If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ moveDown(): Phaser.Sprite; /** * Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object, * which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result. * * This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result. * * Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency. * It should be fine for low-volume testing where physics isn't required. * * @param displayObject The display object to check against. * @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object. */ overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean; /** * Plays an Animation. * * The animation should have previously been created via `animations.add`. * * If the animation is already playing calling this again won't do anything. * If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`. * * @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'. * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return A reference to playing Animation. */ play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Internal method called by the World postUpdate cycle. */ postUpdate(): void; /** * Automatically called by World.preUpdate. * @return True if the Sprite was rendered, otherwise false. */ preUpdate(): void; /** * Resets the Game Object. * * This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`, * `visible` and `renderable` to true. * * If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value. * * If this Game Object has a Physics Body it will reset the Body. * * @param x The x coordinate (in world space) to position the Game Object at. * @param y The y coordinate (in world space) to position the Game Object at. * @param health The health to give the Game Object if it has the Health component. - Default: 1 * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.Sprite; /** * Resets the texture frame dimensions that the Game Object uses for rendering. */ resetFrame(): void; /** * Resizes the Frame dimensions that the Game Object uses for rendering. * * You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData * it can be useful to adjust the dimensions directly in this way. * * @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object. * @param width The new width of the texture. * @param height The new height of the texture. */ resizeFrame(parent: any, width: number, height: number): void; /** * Brings a 'dead' Game Object back to life, optionally resetting its health value in the process. * * A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true. * * It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal. * * @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100 * @return This instance. */ revive(health?: number): Phaser.Sprite; /** * Sends this Game Object to the bottom of its parent's display list (the first position). * Visually this means it will render below all other children of the same parent. * * If this Game Object hasn't been added to a custom Group then this method will send it to the bottom of the Game World, * because the World is the root Group from which all Game Objects descend. * @return This instance. */ sendToBack(): Phaser.Sprite; /** * Sets the texture frame the Game Object uses for rendering. * * This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes. * * @param frame The Frame to be used by the texture. */ setFrame(frame: Phaser.Frame): void; /** * Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent. * * For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored * and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to. * * By setting these values you can carefully control how Game Objects deal with responsive scaling. * * If only one parameter is given then that value will be used for both scaleMin and scaleMax: * `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1 * * If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y: * `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2 * * If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly, * or pass `null` for the `maxX` and `maxY` parameters. * * Call `setScaleMinMax(null)` to clear all previously set values. * * @param minX The minimum horizontal scale value this Game Object can scale down to. * @param minY The minimum vertical scale value this Game Object can scale down to. * @param maxX The maximum horizontal scale value this Game Object can scale up to. * @param maxY The maximum vertical scale value this Game Object can scale up to. */ setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void; // minX: null | number /** * Override this method in your own custom objects to handle any update requirements. * It is called immediately after `preUpdate` and before `postUpdate`. * Remember if this Game Object has any children you should call update on those too. */ update(): void; /** * If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property, * or the rectangle it references, then you need to update the crop frame by calling this method. */ updateCrop(): void; } /** * The SpriteBatch class is a really fast version of the DisplayObjectContainer built purely for speed, so use when you need a lot of sprites or particles. * It's worth mentioning that by default sprite batches are used through-out the renderer, so you only really need to use a SpriteBatch if you have over * 1000 sprites that all share the same texture (or texture atlas). It's also useful if running in Canvas mode and you have a lot of un-rotated or un-scaled * Sprites as it skips all of the Canvas setTransform calls, which helps performance, especially on mobile devices. * * Please note that any Sprite that is part of a SpriteBatch will not have its bounds updated, so will fail checks such as outOfBounds. */ class SpriteBatch extends Phaser.Group { /** * The SpriteBatch class is a really fast version of the DisplayObjectContainer built purely for speed, so use when you need a lot of sprites or particles. * It's worth mentioning that by default sprite batches are used through-out the renderer, so you only really need to use a SpriteBatch if you have over * 1000 sprites that all share the same texture (or texture atlas). It's also useful if running in Canvas mode and you have a lot of un-rotated or un-scaled * Sprites as it skips all of the Canvas setTransform calls, which helps performance, especially on mobile devices. * * Please note that any Sprite that is part of a SpriteBatch will not have its bounds updated, so will fail checks such as outOfBounds. * * @param game A reference to the currently running game. * @param parent The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If `undefined` or `null` it will use game.world. * @param name A name for this Group. Not used internally but useful for debugging. - Default: group * @param addToStage If set to true this Group will be added directly to the Game.Stage instead of Game.World. */ constructor(game: Phaser.Game, parent: PIXI.DisplayObjectContainer, name?: string, addedToStage?: boolean); /** * Internal Phaser Type value. */ type: number; } /** * The Stage controls root level display objects upon which everything is displayed. * It also handles browser visibility handling and the pausing due to loss of focus. */ class Stage extends PIXI.DisplayObjectContainer { /** * The Stage controls root level display objects upon which everything is displayed. * It also handles browser visibility handling and the pausing due to loss of focus. * * @param game Game reference to the currently running game. */ constructor(game: Phaser.Game); /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The name of this object. * Default: _stage_root */ name: string; /** * By default if the browser tab loses focus the game will pause. * You can stop that behavior by setting this property to true. * Note that the browser can still elect to pause your game if it wishes to do so, * for example swapping to another browser tab. This will cause the RAF callback to halt, * effectively pausing your game, even though no in-game pause event is triggered if you enable this property. */ disableVisibilityChange: boolean; /** * If exists is true the Stage and all children are updated, otherwise it is skipped. * Default: true */ exists: boolean; /** * Reset each frame, keeps a count of the total number of objects updated. */ currentRenderOrderID: number; /** * Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000' */ backgroundColor: any; /** * Enable or disable texture smoothing for all objects on this Stage. Only works for bitmap/image textures. Smoothing is enabled by default. Set to true to smooth all sprites rendered on this Stage, or false to disable smoothing (great for pixel art) */ smoothed: boolean; /** * Adds an existing object to the Stage. * * The child is automatically added to the front of the Stage, and is displayed above every previous child. * Or if the _optional_ `index` is specified, the child is added at the location specified by the index value, * this allows you to control child ordering. * * If the object was already on the Stage, it is simply returned, and nothing else happens to it. * * @param child The display object to add as a child. * @param silent Unused. Kept for compatibility with {@link Phaser.Group#add}. * @param index The index to insert the object to. * @return The child that was added to the group. */ add(child: any, silent?: boolean, index?: number): any; /** * Parses a Game configuration object. * * @param config The configuration object to parse. */ parseConfig(config: any): void; /** * This is called automatically after the plugins preUpdate and before the State.update. * Most objects have preUpdate methods and it's where initial movement and positioning is done. */ preUpdate(): void; /** * This is called automatically after the State.update, but before particles or plugins update. */ update(): void; /** * This is called automatically before the renderer runs and after the plugins have updated. * In postUpdate this is where all the final physics calculations and object positioning happens. * The objects are processed in the order of the display list. */ postUpdate(): void; /** * Updates the transforms for all objects on the display list. * This overrides the Pixi default as we don't need the interactionManager, but do need the game property check. */ updateTransform(): void; /** * Starts a page visibility event listener running, or window.onpagehide/onpageshow if not supported by the browser. * Also listens for window.onblur and window.onfocus. */ checkVisibility(): void; /** * This method is called when the document visibility is changed. * * - `blur` and `pagehide` events trigger {@link Phaser.Game#onBlur}. They {@link Phaser.Game#gamePaused pause the game} unless {@link Phaser.Stage#disableVisibilityChange disableVisibilityChange} is on. * - `click`, `focus`, and `pageshow` trigger {@link Phaser.Game#onFocus}. They {@link Phaser.Game#gameResumed resume the game} unless {@link Phaser.Stage#disableVisibilityChange disableVisibilityChange} is on. * - `visibilitychange` (hidden) and CocoonJS's `onSuspended` {@link Phaser.Game#gamePaused pause the game} unless {@link Phaser.Stage#disableVisibilityChange disableVisibilityChange} is on. * - `visibilitychange` (visible) and CocoonJS's `onActivated` {@link Phaser.Game#gameResumed resume the game} unless {@link Phaser.Stage#disableVisibilityChange disableVisibilityChange} is on. * * @param event Its type will be used to decide whether the game should be paused or not. */ visibilityChange(event: Event): void; /** * Sets the background color for the Stage. * * The color can be given as a hex string (`'#RRGGBB'`), a CSS color string (`'rgb(r,g,b)'`), or a numeric value (`0xRRGGBB`). * * An alpha channel is _not_ supported and will be ignored. * * If you've set your game to be {@link Phaser.Game#transparent transparent} then calls to setBackgroundColor are ignored. * * If {@link Phaser.Game#clearBeforeRender} is off then the background color won't appear. * * @param color The color of the background. */ setBackgroundColor(backgroundColor: number | string): void; /** * Destroys the Stage and removes event listeners. */ destroy(): void; } interface ResizeCallback { (scale: ScaleManager, parentBounds: Rectangle): any; } /** * The ScaleManager object handles the the scaling, resizing, and alignment of the * Game size and the game Display canvas. * * The Game size is the logical size of the game; the Display canvas has size as an HTML element. * * The calculations of these are heavily influenced by the bounding Parent size which is the computed * dimensions of the Display canvas's Parent container/element - the _effective CSS rules of the * canvas's Parent element play an important role_ in the operation of the ScaleManager. * * The Display canvas - or Game size, depending {@link Phaser.ScaleManager#scaleMode scaleMode} - is updated to best utilize the Parent size. * When in Fullscreen mode or with {@link Phaser.ScaleManager#parentIsWindow parentIsWindow} the Parent size is that of the visual viewport (see {@link Phaser.ScaleManager#getParentBounds getParentBounds}). * * #### Parent and Display canvas containment guidelines: * * - Style the Parent element (of the game canvas) to control the Parent size and * thus the Display canvas's size and layout. * * - The Parent element's CSS styles should _effectively_ apply maximum (and minimum) bounding behavior. * * - The Parent element should _not_ apply a padding as this is not accounted for. * If a padding is required apply it to the Parent's parent or apply a margin to the Parent. * If you need to add a border, margin or any other CSS around your game container, then use a parent element and * apply the CSS to this instead, otherwise you'll be constantly resizing the shape of the game container. * * - The Display canvas layout CSS styles (i.e. margins, size) should not be altered/specified as * they may be updated by the ScaleManager. * * #### Example Uses * * - ##### Fixed game size; scale canvas proportionally to fill its container * * Use `scaleMode` SHOW_ALL. * * - ##### Fixed game size; stretch canvas to fill its container (uncommon) * * Use `scaleMode` EXACT_FIT. * * - ##### Fixed game size; scale canvas proportionally by some other criteria * * Use `scaleMode` USER_SCALE. Examine `parentBounds` in the {@link #setResizeCallback resize callback} and call {@link Phaser.ScaleManager#setUserScale setUserScale} if necessary. * * - ##### Fluid game/canvas size * * Use `scaleMode` RESIZE. Examine the game or canvas size from the {@link Phaser.ScaleManager#onSizeChange onSizeChange} signal **or** the {@link Phaser.State#resize} callback and reposition game objects if necessary. * * - ##### Preferred orientation * * Call {@link Phaser.ScaleManager#forceOrientation forceOrientation} with the preferred orientation and use any of the {@link Phaser.ScaleManager#onOrientationChange onOrientationChange}, {@link Phaser.ScaleManager#enterIncorrectOrientation enterIncorrectOrientation}, or {@link Phaser.ScaleManager#leaveIncorrectOrientation leaveIncorrectOrientation} signals. */ class ScaleManager { /** * Create a new ScaleManager object - this is done automatically by {@link Phaser.Game} * * The `width` and `height` constructor parameters can either be a number which represents pixels or a string that represents a percentage: e.g. `800` (for 800 pixels) or `"80%"` for 80%. * * @param game A reference to the currently running game. * @param width The width of the game. See above. * @param height The height of the game. See above. */ constructor(game: Phaser.Game, width: number | string, height: number | string); /** * A scale mode that stretches content to fill all available space - see {@link Phaser.ScaleManager#scaleMode scaleMode}. */ static EXACT_FIT: number; /** * A scale mode that prevents any scaling - see {@link Phaser.ScaleManager#scaleMode scaleMode}. */ static NO_SCALE: number; /** * A scale mode that shows the entire game while maintaining proportions - see {@link Phaser.ScaleManager#scaleMode scaleMode}. */ static SHOW_ALL: number; /** * A scale mode that causes the Game size to change - see {@link Phaser.ScaleManager#scaleMode scaleMode}. */ static RESIZE: number; /** * A scale mode that allows a custom scale factor - see {@link Phaser.ScaleManager#scaleMode scaleMode}. */ static USER_SCALE: number; /** * Names of the scale modes, indexed by value. */ static MODES: string[]; /** * The aspect ratio of the scaled Display canvas. */ aspectRatio: number; /** * The bounds of the scaled game. The x/y will match the offset of the canvas element and the width/height the scaled width and height. */ bounds: Rectangle; /** * The DOM element that is considered the Parent bounding element, if any. * * This `null` if {@link Phaser.ScaleManager#parentIsWindow parentIsWindow} is true or if fullscreen mode is entered and {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget} is specified. * It will also be null if there is no game canvas or if the game canvas has no parent. */ boundingParent: HTMLElement; /** * Various compatibility settings. * A value of "(auto)" indicates the setting is configured based on device and runtime information. * * A {@link Phaser.ScaleManager#refresh refresh} may need to be performed after making changes. */ compatibility: { canExpandParent: boolean; clickTrampoline: string; forceMinimumDocumentHeight: boolean; noMargins: boolean; orientationFallback: boolean; scrollTo: Point; supportsFullScreen: boolean; }; /** * Returns the current scale mode - for normal or fullscreen operation. * * See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed. */ currentScaleMode: number; /** * Provides access to some cross-device DOM functions. */ dom: Phaser.DOM; /** * This signal is dispatched when the browser enters an incorrect orientation, as defined by {@link Phaser.ScaleManager#forceOrientation forceOrientation}. * * This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused. */ enterIncorrectOrientation: Signal; /** * The native browser events from Fullscreen API changes. */ event: any; /** * If true, the game should only run in a landscape orientation. * Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}. */ forceLandscape: boolean; /** * If true, the game should only run in a portrait * Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}. */ forcePortrait: boolean; /** * The scaling method used by the ScaleManager when in fullscreen. * * See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed. */ fullScreenScaleMode: number; /** * If specified, this is the DOM element on which the Fullscreen API enter request will be invoked. * The target element must have the correct CSS styling and contain the Display canvas. * * The elements style will be modified (ie. the width and height might be set to 100%) * but it will not be added to, removed from, or repositioned within the DOM. * An attempt is made to restore relevant style changes when fullscreen mode is left. * * For pre-2.2.0 behavior set `game.scale.fullScreenTarget = game.canvas`. */ fullScreenTarget: HTMLElement; /** * A reference to the currently running game. */ game: Phaser.Game; /** * _EXPERIMENTAL:_ A responsive grid on which you can align game objects. */ grid: Phaser.FlexGrid; /** * This boolean provides you with a way to determine if the browser is in Full Screen * mode (via the Full Screen API), and Phaser was the one responsible for activating it. * * It's possible that ScaleManager.isFullScreen returns `true` even if Phaser wasn't the * one that made the browser go full-screen, so this flag lets you determine that. */ hasPhaserSetFullScreen: boolean; /** * Target height (in pixels) of the Display canvas. */ height: number; /** * True if {@link Phaser.ScaleManager#forceLandscape forceLandscape} or {@link Phaser.ScaleManager#forcePortrait forcePortrait} are set and do not agree with the browser orientation. * * This value is not updated immediately. */ incorrectOrientation: boolean; /** * Returns true if the browser is in fullscreen mode, otherwise false. */ isFullScreen: boolean; /** * Returns true if the game dimensions are landscape (width > height). * This is especially useful to check when using the RESIZE scale mode * but wanting to maintain game orientation on desktop browsers, * where typically the screen orientation will always be landscape regardless of the browser viewport. */ isGameLandscape: boolean; /** * Returns true if the game dimensions are portrait (height > width). * This is especially useful to check when using the RESIZE scale mode * but wanting to maintain game orientation on desktop browsers, * where typically the screen orientation will always be landscape regardless of the browser viewport. */ isGamePortrait: boolean; /** * Returns true if the screen orientation is in portrait mode. */ isPortrait: boolean; /** * Returns true if the screen orientation is in landscape mode. */ isLandscape: boolean; /** * This signal is dispatched when the browser leaves an incorrect orientation, as defined by {@link Phaser.ScaleManager#forceOrientation forceOrientation}. * * This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused. */ leaveIncorrectOrientation: Signal; /** * The Display canvas is aligned by adjusting the margins; the last margins are stored here. */ margin: { left: number; top: number; right: number; bottom: number; x: number; y: number; }; /** * Maximum height the canvas should be scaled to (in pixels). * If null it will scale to whatever height the browser can handle. * Change with {@link Phaser.ScaleManager#setMinMax setMinMax}. */ maxHeight: number; /** * Maximum width the canvas should be scaled to (in pixels). * If null it will scale to whatever width the browser can handle. * Change with {@link Phaser.ScaleManager#setMinMax setMinMax}. */ maxWidth: number; /** * Minimum height the canvas should be scaled to (in pixels). * Change with {@link Phaser.ScaleManager#setMinMax setMinMax}. */ minHeight: number; /** * Minimum width the canvas should be scaled to (in pixels). * Change with {@link Phaser.ScaleManager#setMinMax setMinMax}. */ minWidth: number; /** * The offset coordinates of the Display canvas from the top-left of the browser window. * The is used internally by Phaser.Pointer (for Input) and possibly other types. */ offset: Point; /** * This signal is dispatched when fullscreen mode is ready to be initialized but * before the fullscreen request. * * The signal is passed two arguments: `scale` (the ScaleManager), and an object in the form `{targetElement: DOMElement}`. * * The `targetElement` is the {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget} element, * if such is assigned, or a new element created by {@link Phaser.ScaleManager#createFullScreenTarget createFullScreenTarget}. * * Custom CSS styling or resets can be applied to `targetElement` as required. * * If `targetElement` is _not_ the same element as {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget}: * - After initialization the Display canvas is moved onto the `targetElement` for * the duration of the fullscreen mode, and restored to it's original DOM location when fullscreen is exited. * - The `targetElement` is moved/re-parented within the DOM and may have its CSS styles updated. * * The behavior of a pre-assigned target element is covered in {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget}. */ onFullScreenInit: Phaser.Signal; /** * This signal is dispatched when the browser enters or leaves fullscreen mode, if supported. * * The signal is supplied with a single argument: `scale` (the ScaleManager). Use `scale.isFullScreen` to determine * if currently running in Fullscreen mode. */ onFullScreenChange: Phaser.Signal; /** * This signal is dispatched when the browser fails to enter fullscreen mode; * or if the device does not support fullscreen mode and `startFullScreen` is invoked. * * The signal is supplied with a single argument: `scale` (the ScaleManager). */ onFullScreenError: Phaser.Signal; /** * This signal is dispatched when the orientation changes _or_ the validity of the current orientation changes. * * The signal is supplied with the following arguments: * - `scale` - the ScaleManager object * - `prevOrientation`, a string - The previous orientation as per {@link Phaser.ScaleManager#screenOrientation screenOrientation}. * - `wasIncorrect`, a boolean - True if the previous orientation was last determined to be incorrect. * * Access the current orientation and validity with `scale.screenOrientation` and `scale.incorrectOrientation`. * Thus the following tests can be done: * * // The orientation itself changed: * scale.screenOrientation !== prevOrientation * // The orientation just became incorrect: * scale.incorrectOrientation && !wasIncorrect * * It is possible that this signal is triggered after {@link Phaser.ScaleManager#forceOrientation forceOrientation} so the orientation * correctness changes even if the orientation itself does not change. * * This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused. */ onOrientationChange: Phaser.Signal; /** * This signal is dispatched when the size of the Display canvas changes _or_ the size of the Game changes. * When invoked this is done _after_ the Canvas size/position have been updated. * * The callback is supplied with three arguments: the Scale Manager, canvas {@link Phaser.ScaleManager#width width}, and canvas {@link Phaser.ScaleManager#height height}. (Game dimensions can be found in `scale.game.width` and `scale.game.height`.) * * This signal is _only_ called when a change occurs and a reflow may be required. * For example, if the canvas does not change sizes because of CSS settings (such as min-width) * then this signal will _not_ be triggered. * * Use this to handle responsive game layout options. * * This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused. */ onSizeChange: Signal; /** * When enabled the Display canvas will be horizontally-aligned _in the Parent container_ (or {@link Phaser.ScaleManager#parentIsWindow window}). * * To align horizontally across the page the Display canvas should be added directly to page; * or the parent container should itself be horizontally aligned. * * Horizontal alignment is not applicable with the {@link Phaser.ScaleManager.RESIZE RESIZE} scaling mode. * Default: false */ pageAlignHorizontally: boolean; /** * When enabled the Display canvas will be vertically-aligned _in the Parent container_ (or {@link Phaser.ScaleManager#parentIsWindow window}). * * To align vertically the Parent element should have a _non-collapsible_ height, such that it will maintain * a height _larger_ than the height of the contained Game canvas - the game canvas will then be scaled vertically * _within_ the remaining available height dictated by the Parent element. * * One way to prevent the parent from collapsing is to add an absolute "min-height" CSS property to the parent element. * If specifying a relative "min-height/height" or adjusting margins, the Parent height must still be non-collapsible (see note). * * _Note_: In version 2.2 the minimum document height is _not_ automatically set to the viewport/window height. * To automatically update the minimum document height set {@link Phaser.ScaleManager#compatibility compatibility.forceMinimumDocumentHeight} to true. * * Vertical alignment is not applicable with the {@link Phaser.ScaleManager.RESIZE RESIZE} scaling mode. * Default: false */ pageAlignVertically: boolean; /** * The _original_ DOM element for the parent of the Display canvas. * This may be different in fullscreen - see {@link Phaser.ScaleManager#createFullScreenTarget createFullScreenTarget}. * * This is set automatically based on the `parent` argument passed to {@link Phaser.Game}. * * This should only be changed after moving the Game canvas to a different DOM parent. */ parentNode: HTMLElement; /** * True if the the browser window (instead of the display canvas's DOM parent) should be used as the bounding parent. * * This is set automatically based on the `parent` argument passed to {@link Phaser.Game}. * * The {@link Phaser.ScaleManager#parentNode parentNode} property is generally ignored while this is in effect. */ parentIsWindow: boolean; /** * The scale of the game in relation to its parent container. */ parentScaleFactor: Point; /** * The _current_ scale factor based on the game dimensions vs. the scaled dimensions. */ scaleFactor: Point; /** * The _current_ inversed scale factor. The displayed dimensions divided by the game dimensions. */ scaleFactorInversed: Point; /** * The scaling method used by the ScaleManager when not in fullscreen. * *
*
{@link Phaser.ScaleManager.NO_SCALE}
*
* The Game display area will not be scaled - even if it is too large for the canvas/screen. * This mode _ignores_ any applied scaling factor and displays the canvas at the Game size. *
*
{@link Phaser.ScaleManager.EXACT_FIT}
*
* The Game display area will be _stretched_ to fill the entire size of the canvas's parent element and/or screen. * Proportions are not maintained. *
*
{@link Phaser.ScaleManager.SHOW_ALL}
*
* Show the entire game display area while _maintaining_ the original aspect ratio. *
*
{@link Phaser.ScaleManager.RESIZE}
*
* The dimensions of the game display area are changed to match the size of the parent container. * That is, this mode _changes the Game size_ to match the display size. *

* Any manually set Game size (see {@link Phaser.ScaleManager#setGameSize setGameSize}) is ignored while in effect. *

*
{@link Phaser.ScaleManager.USER_SCALE}
*
* The game Display is scaled according to the user-specified scale set by {@link Phaser.ScaleManager#setUserScale setUserScale}. *

* This scale can be adjusted in the {@link Phaser.ScaleManager#setResizeCallback resize callback} * for flexible custom-sizing needs. *

*
*/ scaleMode: number; /** * The _last known_ orientation of the screen, as defined in the Window Screen Web API. * See {@link Phaser.DOM.getScreenOrientation} for possible values. */ screenOrientation: string; /** * The aspect ratio of the original game dimensions. */ sourceAspectRatio: number; /** * The maximum time (in ms) between dimension update checks for the Canvas's parent element (or window). * Update checks normally happen quicker in response to other events. * Default: 2000 */ trackParentInterval: number; /** * Target width (in pixels) of the Display canvas. */ width: number; /** * The edges on which to constrain the game Display/canvas in _addition_ to the restrictions of the parent container. * * The properties are strings and can be '', 'visual', 'layout', or 'layout-soft'. * - If 'visual', the edge will be constrained to the Window / displayed screen area * - If 'layout', the edge will be constrained to the CSS Layout bounds * - An invalid value is treated as 'visual' * Default: {"right":"layout","bottom":""} */ windowConstraints: { bottom: string; right: string; }; /** * Shorthand for setting {@link Phaser.ScaleManager#pageAlignHorizontally pageAlignHorizontally} and {@link Phaser.ScaleManager#pageAlignVertically pageAlignVertically}. * * @param horizontal Value for {@link #pageAlignHorizontally}. Pass `null` to leave unchanged. * @param vertical Value for {@link #pageAlignVertically}. Omit or pass `null` to leave unchanged. */ align(horizontal?: boolean, vertical?: boolean): void; /** * Start the ScaleManager. */ boot(): void; /** * Creates a fullscreen target. This is called automatically as as needed when entering * fullscreen mode and the resulting element is supplied to {@link Phaser.ScaleManager#onFullScreenInit onFullScreenInit}. * * Use {@link Phaser.ScaleManager#onFullScreenInit onFullScreenInit} to customize the created object. */ createFullScreenTarget(): HTMLDivElement; /** * Destroys the ScaleManager and removes any event listeners. * This should probably only be called when the game is destroyed. */ destroy(): void; /** * Force the game to run in only one orientation. * * This enables generation of incorrect orientation signals and affects resizing but does not otherwise rotate or lock the orientation. * * Orientation checks are performed via the Screen Orientation API, if available in browser. This means it will check your monitor * orientation on desktop, or your device orientation on mobile, rather than comparing actual game dimensions. If you need to check the * viewport dimensions instead and bypass the Screen Orientation API then set: `ScaleManager.compatibility.orientationFallback = 'viewport'` * * @param forceLandscape true if the game should run in landscape mode only. * @param forcePortrait true if the game should run in portrait mode only. */ forceOrientation(forceLandscape: boolean, forcePortrait?: boolean): void; /** * Returns the computed Parent size/bounds that the Display canvas is allowed/expected to fill. * * If in fullscreen mode or without parent (see {@link Phaser.ScaleManager#parentIsWindow parentIsWindow}), * this will be the bounds of the visual viewport itself. * * This function takes the {@link Phaser.ScaleManager#windowConstraints windowConstraints} into consideration - if the parent is partially outside * the viewport then this function may return a smaller than expected size. * * Values are rounded to the nearest pixel. * * @param target The rectangle to update; a new one is created as needed. - Default: (new Rectangle) * @param parent Ignore {@link #boundingParent} and use this node instead. * @return The established parent bounds. */ getParentBounds(target?: Rectangle, parent?: HTMLElement): Rectangle; /** * Load configuration settings. * * @param config The game configuration object. */ parseConfig(config: any): void; /** * The ScaleManager.preUpdate is called automatically by the core Game loop. */ preUpdate(): void; /** * Update method while paused. */ pauseUpdate(): void; /** * The "refresh" methods informs the ScaleManager that a layout refresh is required. * * The ScaleManager automatically queues a layout refresh (eg. updates the Game size or Display canvas layout) * when the browser is resized, the orientation changes, or when there is a detected change * of the Parent size. Refreshing is also done automatically when public properties, * such as {@link Phaser.ScaleManager#scaleMode scaleMode}, are updated or state-changing methods are invoked. * * The "refresh" method _may_ need to be used in a few (rare) situtations when * * - a device change event is not correctly detected; or * - the Parent size changes (and an immediate reflow is desired); or * - the ScaleManager state is updated by non-standard means; or * - certain {@link Phaser.ScaleManager#compatibility compatibility} properties are manually changed. * * The queued layout refresh is not immediate but will run promptly in an upcoming `preRender`. */ refresh(): void; /** * Set the actual Game size. * Use this instead of directly changing `game.width` or `game.height`. * * The actual physical display (Canvas element size) depends on various settings including * - Scale mode * - Scaling factor * - Size of Canvas's parent element or CSS rules such as min-height/max-height; * - The size of the Window * * @param width _Game width_, in pixels. * @param height _Game height_, in pixels. */ setGameSize(width: number, height: number): void; /** * Sets the callback that will be invoked before sizing calculations. * * Typically this is triggered when the Scale Manager has detected a change to the canvas's boundaries: * the browser window has been resized, the device has been rotated, or the parent container's size has changed. * At this point the Scale Manager has not resized the game or canvas yet (and may not resize them at all * after it makes its sizing calculations). You can read the size of the parent container from the * `parentBounds` argument to the callback. * * This is the appropriate place to call {@link Phaser.ScaleManager#setUserScale setUserScale} if needing custom dynamic scaling. * * The callback is supplied with two arguments `scale` and `parentBounds` where `scale` is the ScaleManager * and `parentBounds`, a Phaser.Rectangle, is the size of the Parent element. * * This callback * - May be invoked even though the parent container or canvas sizes have not changed * - Unlike {@link Phaser.ScaleManager#onSizeChange onSizeChange}, it runs _before_ the canvas is guaranteed to be updated * - Will be invoked from `preUpdate`, _even when_ the game is paused * * See {@link Phaser.ScaleManager#onSizeChange onSizeChange} for a better way of reacting to layout updates. * * @param callback The callback that will be called each time a window.resize event happens or if set, the parent container resizes. * @param context The context in which the callback will be called. */ setResizeCallback(callback: ResizeCallback, context: any): void; /** * Set a User scaling factor used in the USER_SCALE scaling mode. * * The target canvas size is computed by: * * canvas.width = (game.width * hScale) - hTrim * canvas.height = (game.height * vScale) - vTrim * * This method can be used in the {@link Phaser.ScaleManager#setResizeCallback resize callback}. Set `queueUpdate` and `force` to false if the resize callback is being called repeatedly. * * @param hScale Horizontal scaling factor. * @param vScale Vertical scaling factor. * @param hTrim Horizontal trim, applied after scaling. * @param vTrim Vertical trim, applied after scaling. * @param queueUpdate Queue a size/bounds check at next preUpdate - Default: true * @param force Force a resize during the next preUpdate - Default: true */ setUserScale(hScale: number, vScale: number, hTrim?: number, vTrim?: number, queueUpdate?: boolean, force?: boolean): void; /** * Set the min and max dimensions for the Display canvas. * * _Note:_ The min/max dimensions are only applied in some cases * - When the device is not in an incorrect orientation; or * - The scale mode is EXACT_FIT when not in fullscreen * * @param minWidth The minimum width the game is allowed to scale down to. * @param minHeight The minimum height the game is allowed to scale down to. * @param maxWidth The maximum width the game is allowed to scale up to; only changed if specified. * @param maxHeight The maximum height the game is allowed to scale up to; only changed if specified. */ setMinMax(minWidth: number, minHeight: number, maxWidth?: number, maxHeight?: number): void; /** * Calculates and sets the game dimensions based on the given width and height. * * This should _not_ be called when in fullscreen mode. * * @param width The width of the game. * @param height The height of the game. */ setupScale(width: number, height: number): void; /** * Calculates and sets the game dimensions based on the given width and height. * * This should _not_ be called when in fullscreen mode. * * @param width The width of the game. * @param height The height of the game. */ setupScale(width: string, height: string): void; /** * Takes a Sprite or Image object and scales it to fit the given dimensions. * Scaling happens proportionally without distortion to the sprites texture. * The letterBox parameter controls if scaling will produce a letter-box effect or zoom the * sprite until it fills the given values. Note that with letterBox set to false the scaled sprite may spill out over either * the horizontal or vertical sides of the target dimensions. If you wish to stop this you can crop the Sprite. * * @param sprite The sprite we want to scale. * @param width The target width that we want to fit the sprite in to. If not given it defaults to ScaleManager.width. * @param height The target height that we want to fit the sprite in to. If not given it defaults to ScaleManager.height. * @param letterBox True if we want the `fitted` mode. Otherwise, the function uses the `zoom` mode. * @return The scaled sprite. */ scaleSprite(sprite: Sprite, width?: number, height?: number, letterBox?: boolean): Sprite; /** * Takes a Sprite or Image object and scales it to fit the given dimensions. * Scaling happens proportionally without distortion to the sprites texture. * The letterBox parameter controls if scaling will produce a letter-box effect or zoom the * sprite until it fills the given values. Note that with letterBox set to false the scaled sprite may spill out over either * the horizontal or vertical sides of the target dimensions. If you wish to stop this you can crop the Sprite. * * @param sprite The sprite we want to scale. * @param width The target width that we want to fit the sprite in to. If not given it defaults to ScaleManager.width. * @param height The target height that we want to fit the sprite in to. If not given it defaults to ScaleManager.height. * @param letterBox True if we want the `fitted` mode. Otherwise, the function uses the `zoom` mode. * @return The scaled sprite. */ scaleSprite(sprite: Image, width?: number, height?: number, letterBox?: boolean): Sprite; /** * Display the game in the browser's fullscreen mode. * * This _must_ be called from a user-input Pointer or Mouse event (and possibly a {@link https://www.chromestatus.com/feature/6131337345892352 "user gesture"}), e.g., * * - {@link Phaser.Events#onInputUp} * - {@link Phaser.Input#onUp} or {@link Phaser.Input#onTap} * - `click`, `mousedown`, `mouseup`, `pointerup`, or `touchend` * * Games within an iframe will also be blocked from fullscreen unless the iframe has the `allowfullscreen` attribute. * * The {@link https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API Fullscreen API} must be {@link http://caniuse.com/#search=fullscreen supported by the browser} for this to work - it is not the same as setting * the game size to fill the browser window. See {@link Phaser.ScaleManager#compatibility compatibility.supportsFullScreen} to check if the current * device is reported to support fullscreen mode. * * The {@link Phaser.ScaleManager#fullScreenFailed fullScreenFailed} signal will be dispatched if the fullscreen change request failed or the game does not support the Fullscreen API. * * Safari blocks access to keyboard events in fullscreen mode (as a security measure). * * @param antialias Changes the anti-alias feature of the canvas before jumping in to fullscreen (false = retain pixel art, true = smooth art). If not specified then no change is made. Only works in CANVAS mode. * @param allowTrampoline Internal argument. If `false` click trampolining is suppressed. * @param options Options passed to requestFullscreen(). - Default: {navigationUI: 'hide'} * @return Returns true if the device supports fullscreen mode and fullscreen mode was attempted to be started. (It might not actually start, wait for the signals.) */ startFullScreen(antialias?: boolean, allowTrampoline?: boolean): boolean; /** * Stops / exits fullscreen mode, if active. * @return Returns true if the browser supports fullscreen mode and fullscreen mode will be exited. */ stopFullScreen(): boolean; } /** * DOM utility class. * * Provides a useful Window and Element functions as well as cross-browser compatibility buffer. * * Some code originally derived from {@link https://github.com/ryanve/verge verge}. * Some parts were inspired by the research of Ryan Van Etten, released under MIT License 2013. */ class DOM { /** * The bounds of the Visual viewport, as discussed in * {@link http://www.quirksmode.org/mobile/viewports.html A tale of two viewports — part one} * with one difference: the viewport size _excludes_ scrollbars, as found on some desktop browsers. * * Supported mobile: * iOS/Safari, Android 4, IE10, Firefox OS (maybe not Firefox Android), Opera Mobile 16 * * The properties change dynamically. */ static visualBounds: Phaser.Rectangle; /** * The bounds of the Layout viewport, as discussed in * {@link http://www.quirksmode.org/mobile/viewports2.html A tale of two viewports — part two}; * but honoring the constraints as specified applicable viewport meta-tag. * * The bounds returned are not guaranteed to be fully aligned with CSS media queries (see * {@link http://www.matanich.com/2013/01/07/viewport-size/ What size is my viewport?}). * * This is _not_ representative of the Visual bounds: in particular the non-primary axis will * generally be significantly larger than the screen height on mobile devices when running with a * constrained viewport. * * The properties change dynamically. */ static layoutBounds: Phaser.Rectangle; /** * The size of the document / Layout viewport. * * This incorrectly reports the dimensions in IE. * * The properties change dynamically. */ static documentBounds: Phaser.Rectangle; /** * Calibrates element coordinates for `inLayoutViewport` checks. * * @param coords An object containing the following properties: `{top: number, right: number, bottom: number, left: number}` * @param cushion A value to adjust the coordinates by. * @return The calibrated element coordinates */ static calibrate(coords: any, cushion?: number): any; /** * Get the Visual viewport aspect ratio (or the aspect ratio of an object or element) * * @param object The object to determine the aspect ratio for. Must have public `width` and `height` properties or methods. - Default: (visualViewport) * @return The aspect ratio. */ static getAspectRatio(object: any): number; /** * Returns the device screen orientation. * * Orientation values: 'portrait-primary', 'landscape-primary', 'portrait-secondary', 'landscape-secondary'. * * Order of resolving: * - Screen Orientation API, or variation of - Future track. Most desktop and mobile browsers. * - Screen size ratio check - If fallback is 'screen', suited for desktops. * - Viewport size ratio check - If fallback is 'viewport', suited for mobile. * - window.orientation - If fallback is 'window.orientation', works iOS and probably most Android; non-recommended track. * - Media query * - Viewport size ratio check (probably only IE9 and legacy mobile gets here..) * * See * - https://w3c.github.io/screen-orientation/ (conflicts with mozOrientation/msOrientation) * - https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation (mozOrientation) * - http://msdn.microsoft.com/en-us/library/ie/dn342934(v=vs.85).aspx * - https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Testing_media_queries * - http://stackoverflow.com/questions/4917664/detect-viewport-orientation * - http://www.matthewgifford.com/blog/2011/12/22/a-misconception-about-window-orientation * * @param primaryFallback Specify 'screen', 'viewport', or 'window.orientation'. - Default: (none) */ static getScreenOrientation(primaryFallback?: string): string; /** * A cross-browser element.getBoundingClientRect method with optional cushion. * * Returns a plain object containing the properties `top/bottom/left/right/width/height` with respect to the top-left corner of the current viewport. * Its properties match the native rectangle. * The cushion parameter is an amount of pixels (+/-) to cushion the element. * It adjusts the measurements such that it is possible to detect when an element is near the viewport. * * @param element The element or stack (uses first item) to get the bounds for. * @param cushion A +/- pixel adjustment amount. * @return A plain object containing the properties `top/bottom/left/right/width/height` or `false` if a non-valid element is given. */ static getBounds(element: any, cushion?: number): any; /** * Get the [absolute] position of the element relative to the Document. * * The value may vary slightly as the page is scrolled due to rounding errors. * * @param element The targeted element that we want to retrieve the offset. * @param point The point we want to take the x/y values of the offset. * @return - A point objet with the offsetX and Y as its properties. */ static getOffset(element: any, point?: Point): Point; /** * Tests if the given DOM element is within the Layout viewport. * * The optional cushion parameter allows you to specify a distance. * * inLayoutViewport(element, 100) is `true` if the element is in the viewport or 100px near it. * inLayoutViewport(element, -100) is `true` if the element is in the viewport or at least 100px near it. * * @param element The DOM element to check. If no element is given it defaults to the Phaser game canvas. * @param cushion The cushion allows you to specify a distance within which the element must be within the viewport. * @return True if the element is within the viewport, or within `cushion` distance from it. */ static inLayoutViewport(element: any, cushion?: number): boolean; } /** * This is a base State class which can be extended if you are creating your own game. * It provides quick access to common functions such as the camera, cache, input, match, sound and more. * * #### Callbacks * * | start | preload | loaded | paused | stop | * |-------|-------------|------------|--------------|----------| * | init | | | | | * | | preload | create | paused | | * | | loadUpdate* | update* | pauseUpdate* | | * | | | postUpdate*| | | * | | | preRender* | | | * | | loadRender* | render* | render* | | * | | | | resumed | | * | | | | | shutdown | * * Update and render calls (*) are repeated. * * If your State has a constructor, it will be invoked exactly once, during {@link {@link Phaser.StateManager#add}. */ class State { /** * A reference to the GameObjectFactory which can be used to add new objects to the World. */ add: Phaser.GameObjectFactory; /** * A reference to the game cache which contains any loaded or generated assets, such as images, sound and more. */ cache: Phaser.Cache; /** * A handy reference to World.camera. */ camera: Phaser.Camera; /** * This is a reference to the currently running Game. */ game: Phaser.Game; /** * A reference to the Input Manager. */ input: Phaser.Input; /** * The string based identifier given to the State when added into the State Manager. */ key: string; /** * A reference to the Loader, which you mostly use in the preload method of your state to load external assets. */ load: Phaser.Loader; /** * A reference to the GameObjectCreator which can be used to make new objects. */ make: Phaser.GameObjectCreator; /** * The Particle Manager. It is called during the core gameloop and updates any Particle Emitters it has created. */ particles: Phaser.Particles; /** * A reference to the physics manager which looks after the different physics systems available within Phaser. */ physics: Phaser.Physics; /** * A reference to the seeded and repeatable random data generator. */ rnd: Phaser.RandomDataGenerator; /** * A reference to the Scale Manager which controls the way the game scales on different displays. */ scale: Phaser.ScaleManager; /** * A reference to the Sound Manager which can create, play and stop sounds, as well as adjust global volume. */ sound: Phaser.SoundManager; /** * A reference to the Stage. */ stage: Phaser.Stage; /** * A reference to the State Manager, which controls state changes. */ state: Phaser.StateManager; /** * A reference to the game clock and timed events system. */ time: Phaser.Time; /** * A reference to the tween manager. */ tweens: Phaser.TweenManager; /** * A reference to the game world. All objects live in the Game World and its size is not bound by the display resolution. */ world: Phaser.World; /** * create is called once preload has completed, this includes the loading of any assets from the Loader. * If you don't have a preload method then create is the first method called in your State. * * @param game */ create(game: Phaser.Game): void; /** * init is the very first function called when your State starts up. It's called before preload, create or anything else. * If you need to route the game away to another State you could do so here, or if you need to prepare a set of variables * or objects before the preloading starts. * * @param args Any extra arguments passed to {@link Phaser.StateManager#start} or {@link Phaser.StateManager#restart}. */ init(...args: any[]): void; /** * loadRender is called during the Loader process. This only happens if you've set one or more assets to load in the preload method. * The difference between loadRender and render is that any objects you render in this method you must be sure their assets exist. * * @param game */ loadRender(game: Phaser.Game): void; /** * loadUpdate is called during the Loader process. This only happens if you've set one or more assets to load in the preload method. * * @param game */ loadUpdate(game: Phaser.Game): void; /** * This method will be called if the core game loop is paused. * * @param game */ paused(game: Phaser.Game): void; /** * pauseUpdate is called while the game is paused instead of preUpdate, update and postUpdate. * * @param game */ pauseUpdate(game: Phaser.Game): void; /** * preload is called first. Normally you'd use this to load your game assets (or those needed for the current State) * You shouldn't create any objects in this method that require assets that you're also loading in this method, as * they won't yet be available. * * @param game */ preload(game: Phaser.Game): void; /** * The preRender method is called after all Game Objects have been updated, but before any rendering takes place. * * @param game */ preRender(game: Phaser.Game): void; /** * Nearly all display objects in Phaser render automatically, you don't need to tell them to render. * However the render method is called AFTER the game renderer and plugins have rendered, so you're able to do any * final post-processing style effects here. Note that this happens before plugins postRender takes place. * * @param game */ render(game: Phaser.Game): void; /** * If your game is set to Scalemode RESIZE then each time the browser resizes it will call this function, passing in the new width and height. * * @param width * @param height */ resize(width: number, height: number): void; /** * This method will be called when the core game loop resumes from a paused state. * * @param game */ resumed(game: Phaser.Game): void; /** * This method will be called when the State is shutdown (i.e. you switch to another state from this one). * * @param game */ shutdown(game: Phaser.Game): void; /** * The update method is left empty for your own use. * It is called during the core game loop AFTER debug, physics, plugins and the Stage have had their preUpdate methods called. * It is called BEFORE Stage, Tweens, Sounds, Input, Physics, Particles and Plugins have had their postUpdate methods called. * * @param game */ update(game: Phaser.Game): void; } interface IStateCycle { preUpdate(): void; update(): void; render(): void; postRender(): void; destroy(): void; } /** * The State Manager is responsible for loading, setting up and switching game states. */ class StateManager { /** * The State Manager is responsible for loading, setting up and switching game states. * * @param game A reference to the currently running game. * @param pendingState A State object to seed the manager with. */ constructor(game: Phaser.Game, pendingState?: Phaser.State); /** * True if the current state has had its `create` method run (if it has one, if not this is true by default). */ created: boolean; /** * The current active State object. */ current: string; /** * A reference to the currently running game. */ game: Phaser.Game; /** * This is called when the state preload has finished and creation begins. */ onCreateCallback: Function; /** * This is called when the state is set as the active state. */ onInitCallback: Function; /** * This is called when the State is rendered during the preload phase. */ onLoadRenderCallback: Function; /** * This is called when the State is updated during the preload phase. */ onLoadUpdateCallback: Function; /** * This is called when the game is paused. */ onPausedCallback: Function; /** * This is called every frame while the game is paused. */ onPauseUpdateCallback: Function; /** * This is called when the state starts to load assets. */ onPreloadCallback: Function; /** * This is called before the state is rendered and before the stage is cleared but after all game objects have had their final properties adjusted. */ onPreRenderCallback: Function; /** * This is called post-render. It doesn't happen during preload (see onLoadRenderCallback). */ onRenderCallback: Function; /** * This is called when the game is resumed from a paused state. */ onResumedCallback: Function; /** * This is called if ScaleManager.scalemode is RESIZE and a resize event occurs. It's passed the new width and height. */ onResizeCallback: Function; /** * This is called when the state is shut down (i.e. swapped to another state). */ onShutDownCallback: Function; /** * This is called when the state is updated, every game loop. It doesn't happen during preload (@see onLoadUpdateCallback). */ onUpdateCallback: Function; /** * The object containing Phaser.States. */ states: any; /** * onStateChange is a Phaser.Signal that is dispatched whenever the game changes state. * * It is dispatched only when the new state is started, which isn't usually at the same time as StateManager.start * is called because state swapping is done in sync with the game loop. It is dispatched *before* any of the new states * methods (init, preload, create, etc.) are called, and *after* the previous state's shutdown method has been run. * * The callback you specify is sent two parameters: the string based key of the new state, * and the second parameter is the string based key of the old / previous state. */ onStateChange: Phaser.Signal; /** * Adds a new State into the StateManager. You must give each State a unique key by which you'll identify it. * * The State can be any of * * - a plain JavaScript object containing at least one required callback (see {@link Phaser.StateManager#checkState checkState}) * - an instance of {@link Phaser.State} * - an instance of a class extending Phaser.State * - a constructor function (class) * * If a function is given a new state object will be created by calling it, passing the current {@link Phaser.Game game} as the first argument. * * @param key A unique key you use to reference this state, i.e. "MainMenu", "Level1". * @param state The state you want to switch to. * @param autoStart If true the State will be started immediately after adding it. */ add(key: string, state: any, autoStart?: boolean): void; /** * Checks if a given phaser state is valid. A State is considered valid if it has at least one of the core functions: preload, create, update or render. * * @param key The key of the state you want to check. * @return true if the State has the required functions, otherwise false. */ checkState(key: string): boolean; /** * This method clears the current State, calling its shutdown callback. The process also removes any active tweens, * resets the camera, resets input, clears physics, removes timers and if set clears the world and cache too. */ clearCurrentState(): void; /** * Removes all StateManager callback references to the State object, nulls the game reference and clears the States object. * You don't recover from this without rebuilding the Phaser instance again. */ destroy(): void; /** * Gets the current State. */ getCurrentState(): Phaser.State; /** * Links game properties to the State given by the key. * * @param key State key. */ link(key: string): void; loadComplete(): void; preRender(): void; /** * preUpdate is called right at the start of the game loop. It is responsible for changing to a new state that was requested previously. */ preUpdate(): void; render(): void; /** * Delete the given state. * * @param key A unique key you use to reference this state, i.e. "MainMenu", "Level1". */ remove(key: string): void; resume(): void; /** * Restarts the current State. State.shutDown will be called (if it exists) before the State is restarted. * * @param clearWorld Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly) - Default: true * @param clearCache Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well. * @param args Additional parameters that will be passed to the State.init function if it has one. */ restart(clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void; resize(width: number, height: number): void; /** * Start the given State. If a State is already running then State.shutDown will be called (if it exists) before switching to the new State. * * @param key The key of the state you want to start. * @param clearWorld Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly) - Default: true * @param clearCache Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well. * @param args Additional parameters that will be passed to the State.init function (if it has one). */ start(key: string, clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void; update(): void; /** * Nulls all State level Phaser properties, including a reference to Game. * * @param key State key. */ unlink(key: string): void; } interface PhaserTextStyle { font?: string; fill?: any; align?: string; stroke?: string; strokeThickness?: number; wordWrap?: boolean; wordWrapWidth?: number; maxLines?: number; shadowOffsetX?: number; shadowOffsetY?: number; shadowColor?: string; shadowBlur?: number; valign?: string; tab?: number; tabs?: number; fontSize?: number; fontStyle?: string; fontVariant?: string; fontWeight?: string | number; backgroundColor?: string; boundsAlignH?: string; boundsAlignV?: string; } /** * Create a new game object for displaying Text. * * This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view. * Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded. * * See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts across mobile browsers. */ class Text extends Phaser.Sprite { /** * Create a new game object for displaying Text. * * This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view. * Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded. * * See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts across mobile browsers. * * @param game Current game instance. * @param x X position of the new text object. * @param y Y position of the new text object. * @param text The actual text that will be written. * @param style The style properties to be set on the Text. * @param style.font The style and size of the font. - Default: 'bold 20pt Arial' * @param style.fontStyle The style of the font (eg. 'italic'): overrides the value in `style.font`. - Default: (from font) * @param style.fontVariant The variant of the font (eg. 'small-caps'): overrides the value in `style.font`. - Default: (from font) * @param style.fontWeight The weight of the font (eg. 'bold'): overrides the value in `style.font`. - Default: (from font) * @param style.fontSize The size of the font (eg. 32 or '32px'): overrides the value in `style.font`. - Default: (from font) * @param style.backgroundColor A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable. * @param style.fill A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. - Default: 'black' * @param style.align Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that). - Default: 'left' * @param style.boundsAlignH Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'. - Default: 'left' * @param style.boundsAlignV Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'. - Default: 'top' * @param style.stroke A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'. - Default: 'black' * @param style.strokeThickness A number that represents the thickness of the stroke. Default is 0 (no stroke). * @param style.wordWrap Indicates if word wrap should be used. * @param style.wordWrapWidth The width in pixels at which text will wrap. - Default: 100 * @param style.maxLines The maximum number of lines to be shown for wrapped text. * @param style.tabs The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop. */ constructor(game: Phaser.Game, x: number, y: number, text: string, style?: PhaserTextStyle); static fontPropertiesCanvas: any; static fontPropertiesContext: any; static fontPropertiesCache: any; /** * Controls the horizontal alignment for multiline text. * Can be: 'left', 'center' or 'right'. * Does not affect single lines of text. For that please see `setTextBounds`. */ align: string; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * Should the linePositionX and Y values be automatically rounded before rendering the Text? * You may wish to enable this if you want to remove the effect of sub-pixel aliasing from text. */ autoRound: boolean; /** * Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'. */ boundsAlignH: string; /** * Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'. */ boundsAlignV: string; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * The canvas element that the text is rendered. */ canvas: HTMLCanvasElement; /** * An array of the color values as specified by {@link Phaser.Text#addColor addColor}. */ colors: string[]; /** * The context of the canvas element that the text is rendered to. */ context: CanvasRenderingContext2D; /** * Change the font used. * * This is equivalent of the `font` property specified to {@link Phaser.Text#setStyle setStyle}, except * that unlike using `setStyle` this will not change any current font fill/color settings. * * The CSS font string can also be individually altered with the `font`, `fontSize`, `fontWeight`, `fontStyle`, and `fontVariant` properties. */ cssFont: string; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}). * Default: true */ exists: boolean; /** * A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. */ fill: any; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * Change the font family that the text will be rendered in, such as 'Arial'. * * Multiple CSS font families and generic fallbacks can be specified as long as * {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-family CSS font-family rules} are followed. * * To change the entire font string use {@link Phaser.Text#cssFont cssFont} instead: eg. `text.cssFont = 'bold 20pt Arial'`. */ font: string; /** * The size of the font. * * If the font size is specified in pixels (eg. `32` or `'32px`') then a number (ie. `32`) representing * the font size in pixels is returned; otherwise the value with CSS unit is returned as a string (eg. `'12pt'`). */ fontSize: number | string; /** * The style of the font: 'normal', 'italic', 'oblique' */ fontStyle: string; /** * An array of the font styles values as specified by {@link Phaser.Text#addFontStyle addFontStyle}. */ fontStyles: string[]; /** * The variant the font: 'normal', 'small-caps' */ fontVariant: string; /** * The weight of the font: 'normal', 'bold', or {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-weight a valid CSS font weight}. */ fontWeight: string | number; /** * An array of the font weights values as specified by {@link Phaser.Text#addFontWeight addFontWeight}. */ fontWeights: (string | number)[]; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; /** * Additional spacing (in pixels) between each line of text if multi-line. */ lineSpacing: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * 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 Phaser is unable to accurately determine the true font dimensions. */ padding: Phaser.Point; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The const physics body type of this object. */ physicsType: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; /** * The rotation the Game Object was in set to in the previous frame. Value is in radians. */ previousRotation: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The resolution of the canvas the text is rendered to. * This defaults to match the resolution of the renderer, but can be changed on a per Text object basis. */ resolution: number; /** * The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene). */ shadowBlur: number; /** * The color of the shadow, as given in CSS rgba format. Set the alpha component to 0 to disable the shadow. */ shadowColor: string; /** * Sets if the drop shadow is applied to the Text fill. */ shadowFill: boolean; /** * The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be. */ shadowOffsetX: number; /** * The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be. */ shadowOffsetY: number; /** * Sets if the drop shadow is applied to the Text stroke. */ shadowStroke: boolean; /** * 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. */ splitRegExp: any; /** * A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'. */ stroke: string; /** * An array of the stroke color values as specified by {@link Phaser.Text#addStrokeColor addStrokeColor}. */ strokeColors: string[]; /** * A number that represents the thickness of the stroke. Default is 0 (no stroke) */ strokeThickness: number; /** * The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject * at its default size. A value of 0.5 would scale this DisplayObject by half, and so on. * * The value of this property does not reflect any scaling happening further up the display list. * To obtain that value please see the `worldScale` property. */ scale: Phaser.Point; tab: number; /** * The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. * Can be an integer or an array of varying tab sizes, one tab per element. * For example if you set tabs to 100 then when Text encounters a tab it will jump ahead 100 pixels. * If you set tabs to be `[100,200]` then it will set the first tab at 100px and the second at 200px. */ tabs: number | number[]; /** * The text used to measure the font's width and height * Default: '|MÉq' */ testString: string; /** * The text to be displayed by this Text object. * Use a \n to insert a carriage return and split the text. * The text will be rendered with any style currently set. */ text: string; /** * The textBounds property allows you to specify a rectangular region upon which text alignment is based. * See `Text.setTextBounds` for more details. */ textBounds: Phaser.Rectangle; /** * The const type of this object. */ type: number; /** * Will this Text object use Basic or Advanced Word Wrapping? * * Advanced wrapping breaks long words if they are the first of a line, and repeats the process as necessary. * White space is condensed (e.g., consecutive spaces are replaced with one). * Lines are trimmed of white space before processing. * * It throws an error if wordWrapWidth is less than a single character. */ useAdvancedWrap: boolean; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * Indicates if word wrap should be used. */ wordWrap: boolean; /** * The width at which text will wrap. */ wordWrapWidth: number; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Set specific colors for certain characters within the Text. * * It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position. * The position value is the index of the character in the Text string to start applying this color to. * Once set the color remains in use until either another color or the end of the string is encountered. * For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow. * * If you wish to change the stroke color see addStrokeColor instead. * * @param color A canvas fillstyle that will be used on the text eg `red`, `#00FF00`, `rgba()`. * @param position The index of the character in the string to start applying this color value from. * @return This Text instance. */ addColor(color: string, position: number): Phaser.Text; /** * Set specific font styles for certain characters within the Text. * * It works by taking a font style value, which is a typical string such as `normal`, `italic` or `oblique`. * The position value is the index of the character in the Text string to start applying this font style to. * Once set the font style remains in use until either another font style or the end of the string is encountered. * For example if the Text was `Photon Storm` and you did `Text.addFontStyle('italic', 6)` it would font style in the word `Storm` in italic. * * If you wish to change the text font weight see addFontWeight instead. * * @param style A canvas font-style that will be used on the text style eg `normal`, `italic`, `oblique`. * @param position The index of the character in the string to start applying this font style value from. * @return This Text instance. */ addFontStyle(style: string, position: number): Phaser.Text; /** * Set specific font weights for certain characters within the Text. * * It works by taking a font weight value, which is a typical string such as `normal`, `bold`, `bolder`, etc. * The position value is the index of the character in the Text string to start applying this font weight to. * Once set the font weight remains in use until either another font weight or the end of the string is encountered. * For example if the Text was `Photon Storm` and you did `Text.addFontWeight('bold', 6)` it would font weight in the word `Storm` in bold. * * If you wish to change the text font style see addFontStyle instead. * * @param style A canvas font-weight that will be used on the text weight eg `normal`, `bold`, `bolder`, `lighter`, etc. * @param position The index of the character in the string to start applying this font weight value from. * @return This Text instance. */ addFontWeight(weight: string, position: number): Phaser.Text; /** * Set specific stroke colors for certain characters within the Text. * * It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position. * The position value is the index of the character in the Text string to start applying this color to. * Once set the color remains in use until either another color or the end of the string is encountered. * For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow. * * This has no effect if stroke is disabled or has a thickness of 0. * * If you wish to change the text fill color see addColor instead. * * @param color A canvas fillstyle that will be used on the text stroke eg `red`, `#00FF00`, `rgba()`. * @param position The index of the character in the string to start applying this color value from. * @return This Text instance. */ addStrokeColor(color: string, position: number): Phaser.Text; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Clears any text fill or stroke colors that were set by `addColor` or `addStrokeColor`. * @return This Text instance. */ clearColors(): Phaser.Text; /** * Clears any text styles or weights font that were set by `addFontStyle` or `addFontWeight`. * @return This Text instance. */ clearFontValues(): Phaser.Text; /** * Converts individual font components (see `fontToComponents`) to a short CSS font string. * * @param components Font components. */ componentsToFont(components: any): string; /** * Destroy this Text object, removing it from the group it belongs to. * * @param destroyChildren Should every child of this object have its destroy method called? - Default: true */ destroy(destroyChildren?: boolean): void; /** * Converting a short CSS-font string into the relevant components. * * @param font a CSS font string */ fontToComponents(font: string): any; /** * Internal method called by the World postUpdate cycle. */ postUpdate(): void; /** * Converts the given array into a tab delimited string and then updates this Text object. * This is mostly used when you want to display external data using tab stops. * * The array can be either single or multi dimensional depending on the result you need: * * `[ 'a', 'b', 'c' ]` would convert in to `"a\tb\tc"`. * * Where as: * * `[ * [ 'a', 'b', 'c' ], * [ 'd', 'e', 'f'] * ]` * * would convert in to: `"a\tb\tc\nd\te\tf"` * * @param list The array of data to convert into a string. * @return This Text instance. */ parseList(list: any[]): Phaser.Text; /** * Runs the given text through the Text.runWordWrap function and returns * the results as an array, where each element of the array corresponds to a wrapped * line of text. * * Useful if you wish to control pagination on long pieces of content. * * @param text The text for which the wrapping will be calculated. * @return An array of strings with the pieces of wrapped text. */ precalculateWordWrap(text: string): string[]; /** * Automatically called by World.preUpdate. */ preUpdate(): void; /** * Renders a line of text that contains tab characters if Text.tab > 0. * Called automatically by updateText. * * @param line The line of text to render. * @param x The x position to start rendering from. * @param y The y position to start rendering from. * @param fill If true uses fillText, if false uses strokeText. */ renderTabLine(line: string, x: number, y: number, fill?: boolean): void; /** * Sets a drop shadow effect on the Text. You can specify the horizontal and vertical distance of the drop shadow with the `x` and `y` parameters. * The color controls the shade of the shadow (default is black) and can be either an `rgba` or `hex` value. * The blur is the strength of the shadow. A value of zero means a hard shadow, a value of 10 means a very soft shadow. * To remove a shadow already in place you can call this method with no parameters set. * * @param x The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be. * @param y The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be. * @param color The color of the shadow, as given in CSS rgba or hex format. Set the alpha component to 0 to disable the shadow. - Default: 'rgba(0,0,0,1)' * @param blur The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene). * @param shadowStroke Apply the drop shadow to the Text stroke (if set). - Default: true * @param shadowFill Apply the drop shadow to the Text fill (if set). - Default: true * @return This Text instance. */ setShadow(x?: number, y?: number, color?: any, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.Text; /** * Set the style of the text by passing a single style object to it. * * @param style The style properties to be set on the Text. * @param style.font The style and size of the font. - Default: 'bold 20pt Arial' * @param style.fontStyle The style of the font (eg. 'italic'): overrides the value in `style.font`. - Default: (from font) * @param style.fontVariant The variant of the font (eg. 'small-caps'): overrides the value in `style.font`. - Default: (from font) * @param style.fontWeight The weight of the font (eg. 'bold'): overrides the value in `style.font`. - Default: (from font) * @param style.fontSize The size of the font (eg. 32 or '32px'): overrides the value in `style.font`. - Default: (from font) * @param style.backgroundColor A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable. * @param style.fill A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. - Default: 'black' * @param style.align Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that). - Default: 'left' * @param style.boundsAlignH Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'. - Default: 'left' * @param style.boundsAlignV Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'. - Default: 'top' * @param style.stroke A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'. - Default: 'black' * @param style.strokeThickness A number that represents the thickness of the stroke. Default is 0 (no stroke). * @param style.wordWrap Indicates if word wrap should be used. * @param style.wordWrapWidth The width in pixels at which text will wrap. - Default: 100 * @param style.maxLines The maximum number of lines to be shown for wrapped text. * @param style.tabs The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop. * @param update Immediately update the Text object after setting the new style? Or wait for the next frame. * @return This Text instance. */ setStyle(style?: PhaserTextStyle, update?: boolean): Phaser.Text; /** * The text to be displayed by this Text object. * Use a \n to insert a carriage return and split the text. * The text will be rendered with any style currently set. * * Use the optional `immediate` argument if you need the Text display to update immediately. * * If not it will re-create the texture of this Text object during the next time the render * loop is called. * * @param text The text to be displayed. Set to an empty string to clear text that is already present. * @param immediate Update the texture used by this Text object immediately (true) or automatically during the next render loop (false). * @return This Text instance. */ setText(text: string, immediate?: boolean): Phaser.Text; /** * The Text Bounds is a rectangular region that you control the dimensions of into which the Text object itself is positioned, * regardless of the number of lines in the text, the font size or any other attribute. * * Alignment is controlled via the properties `boundsAlignH` and `boundsAlignV` within the Text.style object, or can be directly * set through the setters `Text.boundsAlignH` and `Text.boundsAlignV`. Bounds alignment is independent of text alignment. * * For example: If your game is 800x600 in size and you set the text bounds to be 0,0,800,600 then by setting boundsAlignH to * 'center' and boundsAlignV to 'bottom' the text will render in the center and at the bottom of your game window, regardless of * how many lines of text there may be. Even if you adjust the text content or change the style it will remain at the bottom center * of the text bounds. * * This is especially powerful when you need to align text against specific coordinates in your game, but the actual text dimensions * may vary based on font (say for multi-lingual games). * * If `Text.wordWrapWidth` is greater than the width of the text bounds it is clamped to match the bounds width. * * Call this method with no arguments given to reset an existing textBounds. * * It works by calculating the final position based on the Text.canvas size, which is modified as the text is updated. Some fonts * have additional padding around them which you can mitigate by tweaking the Text.padding property. It then adjusts the `pivot` * property based on the given bounds and canvas size. This means if you need to set the pivot property directly in your game then * you either cannot use `setTextBounds` or you must place the Text object inside another DisplayObject on which you set the pivot. * * @param x The x coordinate of the Text Bounds region. * @param y The y coordinate of the Text Bounds region. * @param width The width of the Text Bounds region. * @param height The height of the Text Bounds region. * @return This Text instance. */ setTextBounds(x?: number, y?: number, width?: number, height?: number): Phaser.Text; /** * Override this function to handle any special update requirements. */ update(): void; /** * Updates the internal `style.font` if it now differs according to generation from components. * * @param components Font components. */ updateFont(components: any): void; /** * Updates a line of text, applying fill and stroke per-character colors or style and weight per-character font if applicable. */ updateLine(text: string, x?: number, y?: number): void; /** * Sets the Shadow on the Text.context based on the Style settings, or disables it if not enabled. * This is called automatically by Text.updateText. * * @param state If true the shadow will be set to the Style values, otherwise it will be set to zero. */ updateShadow(state?: boolean): void; /** * Updates the texture based on the canvas dimensions. */ updateTexture(): void; } /** * A Tile is a representation of a single tile within the Tilemap. */ class Tile { /** * A Tile is a representation of a single tile within the Tilemap. * * @param layer The layer in the Tilemap data that this tile belongs to. * @param index The index of this tile type in the core map data. * @param x The x coordinate of this tile. * @param y The y coordinate of this tile. * @param width Width of the tile. * @param height Height of the tile. */ constructor(layer: any, index: number, x: number, y: Number, width: number, height: number); /** * The alpha value at which this tile is drawn to the canvas. */ alpha: number; /** * The sum of the y and height properties. */ bottom: number; callback: Function; callbackContext: any; /** * The width of the tile in pixels. */ centerX: number; /** * The height of the tile in pixels. */ centerY: number; /** * True if this tile can collide on any of its faces or has a collision callback set. */ canCollide: boolean; /** * Indicating collide with any object on the bottom. */ collideDown: boolean; /** * Indicating collide with any object on the left. */ collideLeft: boolean; collideNone: boolean; /** * Indicating collide with any object on the right. */ collideRight: boolean; /** * Tile collision callback. */ collisionCallback: Function; /** * The context in which the collision callback will be called. */ collisionCallbackContext: any; /** * True if this tile can collide on any of its faces. */ collides: boolean; /** * Indicating collide with any object on the top. */ collideUp: boolean; debug: boolean; /** * Is the bottom of this tile an interesting edge? */ faceBottom: boolean; /** * Is the left of this tile an interesting edge? */ faceLeft: boolean; /** * Is the right of this tile an interesting edge? */ faceRight: boolean; /** * Is the top of this tile an interesting edge? */ faceTop: boolean; game: Phaser.Game; /** * The height of the tile in pixels. */ height: number; /** * The index of this tile within the map data corresponding to the tileset, or -1 if this represents a blank/null tile. */ index: number; /** * The layer in the Tilemap data that this tile belongs to. */ layer: any; /** * The x value in pixels. */ left: number; /** * Tile specific properties. */ properties: any; /** * The sum of the x and width properties. */ right: number; /** * Has this tile been walked / turned into a poly? */ scanned: boolean; /** * The y value. */ top: number; /** * The width of the tile in pixels. */ width: number; /** * The x map coordinate of this tile. */ worldX: number; /** * The y map coordinate of this tile. */ worldY: number; /** * The x map coordinate of this tile. */ x: number; /** * The y map coordinate of this tile. */ y: number; /** * Copies the tile data and properties from the given tile to this tile. * * @param tile The tile to copy from. */ copy(tile: Phaser.Tile): Phaser.Tile; /** * Check if the given x and y world coordinates are within this Tile. * * @param x The x coordinate to test. * @param y The y coordinate to test. * @return True if the coordinates are within this Tile, otherwise false. */ containsPoint(x: number, y: number): boolean; /** * Clean up memory. */ destroy(): void; /** * Check for intersection with this tile. * * @param x The x axis in pixels. * @param y The y axis in pixels. * @param right The right point. * @param bottom The bottom point. */ intersects(x: number, y: number, right: number, bottom: number): boolean; isInterested(collides: boolean, faces: boolean): boolean; /** * Reset collision status flags. */ resetCollision(): void; /** * 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. */ setCollision(left: boolean, right: boolean, up: boolean, down: boolean): void; /** * Set a callback to be called when this tile is hit by an object. * The callback must true true for collision processing to take place. * * @param callback Callback function. * @param context Callback will be called within this context. */ setCollisionCallback(callback: Function, context: any): void; } /** * Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file. * * Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org * * To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key. * When using CSV data you must provide the key and the tileWidth and tileHeight parameters. * If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here. * 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 it. * A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself. * A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around. */ class Tilemap { /** * Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file. * * Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org * * To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key. * When using CSV data you must provide the key and the tileWidth and tileHeight parameters. * If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here. * 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 it. * A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself. * A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around. * * @param game Game reference to the currently running game. * @param key The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`. * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 */ constructor(game: Phaser.Game, key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number); static CSV: number; static TILED_JSON: number; static NORTH: number; static EAST: number; static SOUTH: number; static WEST: number; /** * An array of collision data (polylines, etc). */ collision: any[]; /** * An array of tile indexes that collide. */ collideIndexes: any[]; /** * The current layer. */ currentLayer: number; /** * Map data used for debug values only. */ debugMap: any[]; /** * If set then console.log is used to dump out useful layer creation debug data. */ enableDebug: boolean; /** * The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON. */ format: number; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The height of the map (in tiles). */ height: number; /** * The height of the map in pixels based on height * tileHeight. */ heightInPixels: number; /** * An array of Tiled Image Layers. */ images: any[]; /** * An array of Image Collections. */ imagecollections: ImageCollection[]; /** * The key of this map data in the Phaser.Cache. */ key: string; /** * The current layer object. */ layer: Phaser.TilemapLayer[]; /** * An array of Tilemap layer data. */ layers: any[]; /** * An array of Tiled Object Layers. */ objects: any[]; /** * The orientation of the map data (as specified in Tiled), usually 'orthogonal'. */ orientation: string; /** * Map specific properties as specified in Tiled. */ properties: any; rayStepRate: number; /** * The base height of the tiles in the map (in pixels). */ tileHeight: number; /** * The super array of Tiles. */ tiles: Phaser.Tile[]; /** * An array of Tilesets. */ tilesets: Phaser.Tileset[]; /** * The base width of the tiles in the map (in pixels). */ tileWidth: number; /** * The version of the map data (as specified in Tiled, usually 1). */ version: number; /** * The width of the map (in tiles). */ width: number; /** * The width of the map in pixels based on width * tileWidth. */ widthInPixels: number; /** * 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 tileset 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 tileset parameter. * You can also pass in a BitmapData which can be used instead of an Image. * @param tileWidth The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value, if that isn't set then 32. - Default: 32 * @param tileHeight The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value, if that isn't set then 32. - Default: 32 * @param tileMargin The width of the tiles in the Tileset Image. * @param tileSpacing The height of the tiles in the Tileset Image. * @param gid If adding multiple tilesets to a blank/dynamic map, specify the starting GID the set will use here. * @return Returns the Tileset object that was created or updated, or null if it failed. */ addTilesetImage(tileset: string, key?: string | Phaser.BitmapData, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, gid?: number): Phaser.Tileset; /** * Internal function. * * @param layer The index of the TilemapLayer to operate on. */ calculateFaces(layer: number): void; /** * Copies all of the tiles in the given rectangular block into the tilemap data buffer. * * @param x X position of the top left of the area to copy (given in tiles, not pixels) * @param y Y position of the top left of the area to copy (given in tiles, not pixels) * @param width The width of the area to copy (given in tiles, not pixels) * @param height The height of the area to copy (given in tiles, not pixels) * @param layer The layer to copy the tiles from. * @return An array of the tiles that were copied. */ copy(x: number, y: number, width: number, height: number, layer?: any): Phaser.Tile[]; /** * Creates an empty map of the given dimensions and one blank layer. If layers already exist they are erased. * * @param name The name of the default layer of the map. * @param width The width of the map in tiles. * @param height The height of the map in tiles. * @param tileWidth The width of the tiles the map uses for calculations. * @param tileHeight The height of the tiles the map uses for calculations. * @param group Optional Group to add the layer to. If not specified it will be added to the World group. * @return The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly. */ create(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer; /** * Creates a new and empty layer on this Tilemap. By default TilemapLayers are fixed to the camera. * * @param name The name of this layer. Must be unique within the map. * @param width The width of the layer in tiles. * @param height The height of the layer in tiles. * @param tileWidth The width of the tiles the layer uses for calculations. * @param tileHeight The height of the tiles the layer uses for calculations. * @param group Optional Group to add the layer to. If not specified it will be added to the World group. * @return The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly. */ createBlankLayer(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer; /** * Creates a Sprite for every {@link http://doc.mapeditor.org/reference/tmx-map-format/#object object} matching the `gid` argument. You can optionally specify the group that the Sprite will be created in. If none is * given it will be created in the World. All properties from the map data objectgroup are copied across to the Sprite, 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. You could also give it a value like: `body.velocity.x: 100` to set it moving automatically. * * The `gid` argument is matched against: * * 1. For a tile object, the tile identifier (`gid`); or * 2. The object's unique ID (`id`); or * 3. The object's `name` (a string) * * @param name The name of the Object Group to create Sprites from. * @param gid The object's tile reference (gid), unique ID (id) or name. * @param key The Game.cache key of the image that this Sprite will use. * @param frame If the Sprite image contains multiple frames you can specify which one to use here. * @param exists The default exists state of the Sprite. - Default: true * @param autoCull The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range. * @param group Group to add the Sprite to. If not specified it will be added to the World group. - Default: Phaser.World * @param CustomClass If you wish to create your own class, rather than Phaser.Sprite, pass the class here. Your class must extend Phaser.Sprite and have the same constructor parameters. - Default: Phaser.Sprite * @param adjustY By default the Tiled map editor uses a bottom-left coordinate system. Phaser uses top-left. So most objects will appear too low down. This parameter moves them up by their height. - Default: true * @param adjustSize By default the width and height of the objects are transferred to the sprite. This parameter controls that behavior. - Default: true */ createFromObjects(name: string, gid: number, key: string, frame?: any, exists?: boolean, autoCull?: boolean, group?: Phaser.Group, CustomClass?: any, adjustY?: boolean, adjustSize?: boolean): void; /** * Creates a Sprite for every object matching the given tile indexes in the map data. * You can specify the group that the Sprite will be created in. If none is given it will be created in the World. * You can optional specify if the tile will be replaced with another after the Sprite is 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 tiles 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 -1 to remove the tile. Set to `null` to make no change (leave the tile as is). * @param key The Game.cache key of the image that this Sprite will use. * @param layer The layer to operate on. * @param group Group to add the Sprite to. If not specified it will be added to the World group. - Default: Phaser.World * @param properties An object that contains the default properties for your newly created Sprite. This object will be iterated and any matching Sprite property will be set. * @return The number of Sprites that were created. */ createFromTiles(tiles: any, replacements: any, key: string, layer?: any, group?: Phaser.Group, properties?: any): number; /** * Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera. * The `layer` parameter 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. * If you wish to create a blank layer to put your own tiles on then see Tilemap.createBlankLayer. * * @param layer The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents. * @param width The rendered width of the layer, should never be wider than Game.width. If not given it will be set to Game.width. * @param height The rendered height of the layer, should never be wider than Game.height. If not given it will be set to Game.height. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return The TilemapLayer object. This is an extension of Phaser.Sprite and can be moved around the display list accordingly. */ createLayer(layer: any, width?: number, height?: number, group?: Phaser.Group): Phaser.TilemapLayer; /** * Removes all layer data from this tile map and nulls the game reference. * Note: You are responsible for destroying any TilemapLayer objects you generated yourself, as Tilemap doesn't keep a reference to them. */ destroy(): void; /** * Dumps the tilemap data out to the console. */ dump(): void; /** * Fills the given area with the specified tile. * Only the tile indexes are modified. * * @param index The index of the tile that the area will be filled with. * @param x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ fill(index: number, x: number, y: number, width: number, height: number, layer?: any): void; /** * For each tile in the given area defined by x/y and width/height run the given callback. * * @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 x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ forEach(callback: Function, context: any, x: number, y: Number, width: number, height: number, layer?: any): void; /** * Gets the image index based on its name. * * @param name The name of the image to get. * @return The index of the image in this tilemap, or null if not found. */ getImageIndex(name: string): number; /** * Gets the layer index based on the layers name. * * @param location The local array to search. * @param name The name of the array element to get. * @return The index of the element in the array, or null if not found. */ getIndex(location: any[], name: string): number; /** * Gets the TilemapLayer index as used in the setCollision calls. * * @param layer The layer to operate on. If not given will default to this.currentLayer. * @return The TilemapLayer index. */ getLayer(layer: any): number; /** * Gets the layer index based on its name. * * @param name The name of the layer to get. * @return The index of the layer in this tilemap, or null if not found. */ getLayerIndex(name: string): number; getObjectIndex(name: string): number; /** * Gets a tile from the Tilemap Layer. The coordinates are given in tile values. * * @param x X position to get the tile from (given in tile units, not pixels) * @param y Y position to get the tile from (given in tile units, not pixels) * @param layer The layer to get the tile from. * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. * @return The tile at the given coordinates or null if no tile was found or the coordinates were invalid. */ getTile(x: number, y: number, layer?: any, nonNull?: boolean): Phaser.Tile; /** * Gets the tile above the tile coordinates given. * Mostly used as an internal function by calculateFaces. * * @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer(). * @param x The x coordinate to get the tile from. In tiles, not pixels. * @param y The y coordinate to get the tile from. In tiles, not pixels. */ getTileAbove(layer: number, x: number, y: number): Phaser.Tile; /** * Gets the tile below the tile coordinates given. * Mostly used as an internal function by calculateFaces. * * @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer(). * @param x The x coordinate to get the tile from. In tiles, not pixels. * @param y The y coordinate to get the tile from. In tiles, not pixels. */ getTileBelow(layer: number, x: number, y: number): Phaser.Tile; /** * Gets the tile to the left of the tile coordinates given. * Mostly used as an internal function by calculateFaces. * * @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer(). * @param x The x coordinate to get the tile from. In tiles, not pixels. * @param y The y coordinate to get the tile from. In tiles, not pixels. */ getTileLeft(layer: number, x: number, y: number): Phaser.Tile; /** * Gets the tile to the right of the tile coordinates given. * Mostly used as an internal function by calculateFaces. * * @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer(). * @param x The x coordinate to get the tile from. In tiles, not pixels. * @param y The y coordinate to get the tile from. In tiles, not pixels. */ getTileRight(layer: number, x: number, y: number): Phaser.Tile; /** * Gets the tileset index based on its name. * * @param name The name of the tileset to get. * @return The index of the tileset in this tilemap, or null if not found. */ getTilesetIndex(name: string): number; /** * Gets a tile from the Tilemap layer. The coordinates are given in pixel values. * * @param x X position to get the tile from (given in pixels) * @param y Y position to get the tile from (given in pixels) * @param tileWidth The width of the tiles. If not given the map default is used. * @param tileHeight The height of the tiles. If not given the map default is used. * @param layer The layer to get the tile from. * @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1. * @return The tile at the given coordinates. */ getTileWorldXY(x: number, y: number, tileWidth?: number, tileHeight?: number, layer?: number | string | Phaser.TilemapLayer, nonNull?: boolean): Phaser.Tile; /** * Checks if there is a tile at the given location. * * @param x X position to check if a tile exists at (given in tile units, not pixels) * @param y Y position to check if a tile exists at (given in tile units, not pixels) * @param layer The layer to set as current. * @return True if there is a tile at the given location, otherwise false. */ hasTile(x: number, y: number, layer: Phaser.TilemapLayer): boolean; /** * Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy. * * @param x X position of the top left of the area to paste to (given in tiles, not pixels) * @param y Y position of the top left of the area to paste to (given in tiles, not pixels) * @param tileblock The block of tiles to paste. * @param layer The layer to paste the tiles into. */ paste(x: number, y: number, tileblock: Phaser.Tile[], layer?: any): void; /** * Puts a tile of the given index value at the coordinate specified. * If you pass `null` as the tile it will pass your call over to Tilemap.removeTile instead. * * @param tile The index of this tile to set or a Phaser.Tile object. If a Tile object, all of its data will be copied. If null the tile is removed from the map. * @param x X position to place the tile (given in tile units, not pixels) * @param y Y position to place the tile (given in tile units, not pixels) * @param layer The layer to modify. * @return The Tile object that was created or added to this map. */ putTile(tile: any, x: number, y: number, layer?: any): Phaser.Tile; /** * Puts a tile into the Tilemap layer. The coordinates are given in pixel values. * * @param tile The index of this tile to set or a Phaser.Tile object. * @param x X position to insert the tile (given in pixels) * @param y Y position to insert the tile (given in pixels) * @param tileWidth The width of the tile in pixels. * @param tileHeight The height of the tile in pixels. * @param layer The layer to modify. * @return The Tile object that was created or added to this map. */ putTileWorldXY(tile: any, x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): void; /** * Randomises a set of tiles in a given area. * Only the tile indexes are modified. * * @param x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ random(x: number, y: number, width: number, height: number, layer?: any): void; /** * Removes all layers from this tile map. */ removeAllLayers(): void; /** * Removes the tile located at the given coordinates and updates the collision data. * * @param x X position to place the tile (given in tile units, not pixels) * @param y Y position to place the tile (given in tile units, not pixels) * @param layer The layer to modify. * @return The Tile object that was removed from this map. */ removeTile(x: number, y: number, layer?: any): Phaser.Tile; /** * Removes the tile located at the given coordinates and updates the collision data. The coordinates are given in pixel values. * * @param x X position to insert the tile (given in pixels) * @param y Y position to insert the tile (given in pixels) * @param tileWidth The width of the tile in pixels. * @param tileHeight The height of the tile in pixels. * @param layer The layer to modify. * @return The Tile object that was removed from this map. */ removeTileWorldXY(x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): Phaser.Tile; /** * Scans the given area for tiles with an index matching `source` and updates their index to match `dest`. * Only the tile indexes are modified. * * @param source The tile index value to scan for. * @param dest The tile index value to replace found tiles with. * @param x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ replace(source: number, dest: number, x: number, y: number, width: number, height: number, layer?: any): void; /** * Searches the entire map layer for the first tile or all tiles matching the given index. * When `all` is false (the default), it returns a Phaser.Tile object or null. * When `all` is true, it returns an array Phaser.Tile objects, or none (an empty array). * 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 layer to get the tile from. * @param all If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. * @return A matching tile, or null (when `all` is false); or an array of zero or more tiles (when `all` is true). */ searchTileIndex(index: number, skip?: number, reverse?: boolean, layer?: any): Phaser.Tile; /** * Sets collision on the given tile or tiles. 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). * * Collision-enabled tiles can be collided against Sprites using {@link Phaser.Physics.Arcade#collide}. * * You can verify the collision faces by enabling {@link Phaser.TilemapLayer#debug}. * * @param indexes Either a single tile index, or an array of tile IDs to be checked for collision. * @param collides If true it will enable collision. If false it will clear collision. - Default: true * @param layer The layer to operate on. If not given will default to this.currentLayer. * @param recalculate Recalculates the tile faces after the update. - Default: true */ setCollision(indexes: any, collides?: boolean, layer?: any, recalculate?: boolean): void; /** * Sets collision on a range of tiles where the tile IDs increment sequentially. * 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 layer The layer to operate on. If not given will default to this.currentLayer. * @param recalculate Recalculates the tile faces after the update. - Default: true */ setCollisionBetween(start: number, stop: number, collides?: boolean, layer?: any, recalculate?: boolean): void; /** * Sets collision on all tiles in the given layer, except for the IDs of those in the given array. * The `collides` parameter controls if collision will be enabled (true) or disabled (false). * * @param indexes An array of the tile IDs to not be counted for collision. * @param collides If true it will enable collision. If false it will clear collision. - Default: true * @param layer The layer to operate on. If not given will default to this.currentLayer. * @param recalculate Recalculates the tile faces after the update. - Default: true */ setCollisionByExclusion(indexes: any[], collides?: boolean, layer?: any, recalculate?: boolean): void; /** * Sets collision values on a tile in the set. * You shouldn't usually call this method directly, instead use setCollision, setCollisionBetween or setCollisionByExclusion. * * @param index The index of the tile on the layer. * @param collides If true it will enable collision on the tile. If false it will clear collision values from the tile. - Default: true * @param layer The layer to operate on. If not given will default to this.currentLayer. * @param recalculate Recalculates the tile faces after the update. - Default: true */ setCollisionByIndex(index: number, collides?: boolean, layer?: number, recalculate?: boolean): void; /** * Sets the current layer to the given index. * * @param layer The layer to set as current. */ setLayer(layer: any): void; /** * Turn off/on the recalculation of faces for tile or collision updates. * `setPreventRecalculate(true)` puts recalculation on hold while `setPreventRecalculate(false)` recalculates all the changed layers. * * @param value If true it will put the recalculation on hold. */ setPreventRecalculate(value: boolean): void; /** * 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. * * Return `true` from the callback to continue separating the tile and colliding object, or `false` to cancel the collision for the current tile (see {@link Phaser.Physics.Arcade#separateTile}). * * @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 (via {@link Phaser.Physics.Arcade#collide}). * @param callbackContext The context under which the callback is called. * @param layer The layer to operate on. If not given will default to this.currentLayer. */ setTileIndexCallback(indexes: any, callback: Function, callbackContext?: any, layer?: any): void; /** * Sets a global collision callback for the given map location within the layer. This will affect all tiles on this layer found in the given area. * 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. * * Return `true` from the callback to continue separating the tile and colliding object, or `false` to cancel the collision for the current tile (see {@link Phaser.Physics.Arcade#separateTile}). * * @param x X position of the top left of the area to copy (given in tiles, not pixels) * @param y Y position of the top left of the area to copy (given in tiles, not pixels) * @param width The width of the area to copy (given in tiles, not pixels) * @param height The height of the area to copy (given in tiles, not pixels) * @param callback The callback that will be invoked when the tile is collided with (via {@link Phaser.Physics.Arcade#collide}). * @param callbackContext The context under which the callback is called. * @param layer The layer to operate on. If not given will default to this.currentLayer. */ setTileLocationCallback(x: number, y: number, width: number, height: number, callback: Function, callbackContext?: any, layer?: any): void; /** * Sets the base tile size for the map. * * @param tileWidth The width of the tiles the map uses for calculations. * @param tileHeight The height of the tiles the map uses for calculations. */ setTileSize(tileWidth: number, tileHeight: number): void; /** * Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed! * Only the tile indexes are modified. * * @param x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ shuffle(x: number, y: number, width: number, height: number, layer: any): void; /** * Scans the given area for tiles with an index matching tileA and swaps them with tileB. * Only the tile indexes are modified. * * @param tileA First tile index. * @param tileB Second tile index. * @param x X position of the top left of the area to operate one, given in tiles, not pixels. * @param y Y position of the top left of the area to operate one, given in tiles, not pixels. * @param width The width in tiles of the area to operate on. * @param height The height in tiles of the area to operate on. * @param layer The layer to operate on. */ swap(tileA: number, tileB: number, x: number, y: number, width: number, height: number, layer?: any): void; } /** * A TilemapLayer is a Phaser.Image/Sprite that renders a specific TileLayer of a Tilemap. * * Since a TilemapLayer is a Sprite it can be moved around the display, added to other groups or display objects, etc. * * By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior. */ class TilemapLayer extends Phaser.Sprite { /** * A TilemapLayer is a Phaser.Image/Sprite that renders a specific TileLayer of a Tilemap. * * Since a TilemapLayer is a Sprite it can be moved around the display, added to other groups or display objects, etc. * * By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior. * * @param game Game reference to the currently running game. * @param tilemap The tilemap to which this layer belongs. * @param index The index of the TileLayer to render within the Tilemap. * @param width Width of the renderable area of the layer (in pixels). * @param height Height of the renderable area of the layer (in pixels). */ constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number); /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * The canvas to which this TilemapLayer draws. */ canvas: HTMLCanvasElement; collisionHeight: number; collisionWidth: number; /** * The 2d context of the canvas. */ context: CanvasRenderingContext2D; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * Enable an additional "debug rendering" pass to display collision information. */ debug: boolean; debugAlpha: number; debugCallbackColor: string; debugColor: string; /** * Settings used for debugging and diagnostics. */ debugSettings: { missingImageFill: string; debuggedTileOverfill: string; forceFullRedraw: boolean; debugAlpha: number; facingEdgeStroke: string; collidingTileOverfill: string; }; /** * If true tiles will be force rendered, even if such is not believed to be required. */ dirty: boolean; /** * Controls if the core game loop and physics update this game object or not. */ exists: boolean; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The index of this layer within the Tilemap. */ index: number; /** * The layer object within the Tilemap that this layer represents. */ layer: Phaser.TilemapLayer; /** * The Tilemap to which this layer is bound. */ map: Phaser.Tilemap; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The const physics body type of this object. */ physicsType: number; /** * Settings that control standard (non-diagnostic) rendering. * Default: {"enableScrollDelta":true,"overdrawRatio":0.2,"copyCanvas":null} */ renderSettings: { enableScrollDelta: boolean; overdrawRatio: number; copyCanvas: any; }; /** * Speed at which this layer scrolls horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do). * Default: 1 */ scrollFactorX: number; /** * Speed at which this layer scrolls vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do) * Default: 1 */ scrollFactorY: number; scrollX: number; scrollY: number; /** * The const type of this object. * Default: Phaser.TILEMAPLAYER */ type: number; wrap: boolean; /** * Destroys this TilemapLayer. */ destroy(): void; /** * Gets all tiles that intersect with the given line. * * @param line The line used to determine which tiles to return. * @param stepRate How many steps through the ray will we check? Defaults to `rayStepRate`. - Default: (rayStepRate) * @param collides If true, _only_ return tiles that collide on one or more faces. * @param interestingFace If true, _only_ return tiles that have interesting faces. * @return An array of Phaser.Tiles. */ getRayCastTiles(line: Phaser.Line, stepRate?: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[]; /** * Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles. * * @param x X position of the top left corner (in pixels). * @param y Y position of the top left corner (in pixels). * @param width Width of the area to get (in pixels). * @param height Height of the area to get (in pixels). * @param collides If true, _only_ return tiles that collide on one or more faces. * @param interestingFace If true, _only_ return tiles that have interesting faces. * @return An array of Tiles. */ getTiles(x: number, y: number, width: number, height: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[]; /** * Convert a pixel value to a tile coordinate. * * @param x X position of the point in target tile (in pixels). * @return The X map location of the tile. */ getTileX(x: number): number; /** * Convert a pixel coordinate to a tile coordinate. * * @param x X position of the point in target tile (in pixels). * @param y Y position of the point in target tile (in pixels). * @param point The Point/object to update. * @return A Point/object with its `x` and `y` properties set. */ getTileXY(x: number, y: number, point: Phaser.Point): Phaser.Point; /** * Convert a pixel value to a tile coordinate. * * @param y Y position of the point in target tile (in pixels). * @return The Y map location of the tile. */ getTileY(y: number): number; /** * Automatically called by World.postUpdate. Handles cache updates. */ postUpdate(): void; /** * Renders the tiles to the layer canvas and pushes to the display. */ render(): void; /** * Resizes the internal canvas and texture frame used by this TilemapLayer. * * This is an expensive call, so don't bind it to a window resize event! But instead call it at carefully * selected times. * * Be aware that no validation of the new sizes takes place and the current map scroll coordinates are not * modified either. You will have to handle both of these things from your game code if required. * * @param width The new width of the TilemapLayer * @param height The new height of the TilemapLayer */ resize(width: number, height: number): void; /** * Sets the world size to match the size of this layer. */ resizeWorld(): void; /** * The TilemapLayer caches tileset look-ups. * * Call this method of clear the cache if tilesets have been added or updated after the layer has been rendered. */ resetTilesetCache(): void; /** * This method will set the scale of the tilemap as well as update the underlying block data of this layer. * * @param xScale The scale factor along the X-plane - Default: 1 * @param yScale The scale factor along the Y-plane */ setScale(xScale?: number, yScale?: number): void; updateMax(): void; getTileOffsetX(): number; /** * Get the Y axis position offset of this layer's tiles. */ getTileOffsetY(): number; } class TilemapLayerGL { constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number, tileset?: Phaser.Tileset); collisionHeight: number; collisionWidth: number; data: any; dirty: boolean; exists: boolean; fixedToCamera: boolean; game: Phaser.Game; index: number; layer: Phaser.TilemapLayer; map: Phaser.Tilemap; name: string; physicsType: number; scrollFactorX: number; scrollFactorY: number; scrollX: number; scrollY: number; type: number; wrap: boolean; x: number; y: number; width: number; height: number; destroy(): void; postUpdate(): void; render(): void; resize(width: number, height: number): void; resizeWorld(): void; resetTilesetCache(): void; setScale(xScale?: number, yScale?: number): void; updateMax(): void; } /** * Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap. */ class TilemapParser { /** * When scanning the Tiled map data the TilemapParser can either insert a null value (true) or * a Phaser.Tile instance with an index of -1 (false, the default). Depending on your game type * depends how this should be configured. 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 (perhaps the map dynamically changes * during the game) then leave the default value set. */ static INSERT_NULL: boolean; /** * Returns an empty map data object. * @return Generated map data. */ static getEmptyData(tileWidth?: number, tileHeight?: number, width?: number, height?: number): any; /** * Parse tilemap data from the cache and creates data for a Tilemap object. * * @param game Game reference to the currently running game. * @param key The key of the tilemap in the Cache. * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10 * @return The parsed map object. */ static parse(game: Phaser.Game, key: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): any; /** * Parses a CSV file into valid map data. * * @param key The name you want to give the map data. * @param data The CSV file data. * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32 * @return Generated map data. */ static parseCSV(key: string, data: string, tileWidth?: number, tileHeight?: number): any; static parseJSON(json: any): any; } /** * A Tile set is a combination of an image containing the tiles and collision data per tile. * * Tilesets are normally created automatically when Tiled data is loaded. */ class Tileset { /** * A Tile set is a combination of an image containing the tiles and collision data per tile. * * Tilesets are normally created automatically when Tiled data is loaded. * * @param name The name of the tileset in the map data. * @param firstgid The first tile index this tileset contains. * @param width Width of each tile (in pixels). - Default: 32 * @param height Height of each tile (in pixels). - Default: 32 * @param margin The margin around all tiles in the sheet (in pixels). * @param spacing The spacing between each tile in the sheet (in pixels). * @param properties Custom Tileset properties. - Default: {} */ constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: any); /** * The number of tile columns in the tileset. */ columns: number; /** * The Tiled firstgid value. * This is the starting index of the first tile index this Tileset contains. */ firstgid: number; /** * The cached image that contains the individual tiles. Use {@link Phaser.Tileset.setImage setImage} to set. */ image: any; lastgid: number; /** * The name of the Tileset. */ name: string; /** * Tileset-specific properties that are typically defined in the Tiled editor. */ properties: any; /** * The number of tile rows in the the tileset. */ rows: number; /** * The height of each tile (in pixels). */ tileHeight: number; /** * The margin around the tiles in the sheet (in pixels). * Use `setSpacing` to change. */ tileMargin: number; /** * The spacing between each tile in the sheet (in pixels). * Use `setSpacing` to change. */ tileSpacing: number; /** * The width of each tile (in pixels). */ tileWidth: number; /** * The total number of tiles in the tileset. */ total: number; /** * Returns true if and only if this tileset contains the given tile index. * * @param tileIndex * @return True if this tileset contains the given index. */ containsTileIndex(tileIndex: number): boolean; /** * Draws a tile from this Tileset at the given coordinates on the context. * * @param context The context to draw the tile onto. * @param x The x coordinate to draw to. * @param y The y coordinate to draw to. * @param index The index of the tile within the set to draw. */ draw(context: CanvasRenderingContext2D, x: number, y: number, index: number): void; drawGl(glBatch: any[], x: number, y: number, index: number, alpha: number, flippedVal: number): void; /** * Set the image associated with this Tileset and update the tile data. * * @param image The image that contains the tiles. */ setImage(image: any): void; /** * Sets tile spacing and margins. * * @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?: number, spacing?: number): 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. * * TileSprites have no input handler or physics bodies by default, both need enabling in the same way as for normal Sprites. * * You shouldn't ever create a TileSprite any larger than your actual screen 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 screen 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 texture dimensions: * * When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should ideally be * a power of two in size (i.e. 4, 8, 16, 32, 64, 128, 256, 512, etc pixels width by height). If the texture isn't a power of two * it will be rendered to a blank canvas that is the correct size, which means you may have 'blank' areas appearing to the right and * bottom of your frame. To avoid this ensure your textures are perfect powers of two. * * TileSprites support animations in the same way that Sprites do. You add and play animations using the AnimationManager. However * if your game is running under WebGL please note that each frame of the animation must be a power of two in size, or it will receive * additional padding to enforce it to be so. */ class TileSprite extends PIXI.TilingSprite { /** * 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. * * TileSprites have no input handler or physics bodies by default, both need enabling in the same way as for normal Sprites. * * You shouldn't ever create a TileSprite any larger than your actual screen 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 screen 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 texture dimensions: * * When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should ideally be * a power of two in size (i.e. 4, 8, 16, 32, 64, 128, 256, 512, etc pixels width by height). If the texture isn't a power of two * it will be rendered to a blank canvas that is the correct size, which means you may have 'blank' areas appearing to the right and * bottom of your frame. To avoid this ensure your textures are perfect powers of two. * * TileSprites support animations in the same way that Sprites do. You add and play animations using the AnimationManager. However * if your game is running under WebGL please note that each frame of the animation must be a power of two in size, or it will receive * additional padding to enforce it to be so. * * @param game A reference to the currently running game. * @param x The x coordinate (in world space) to position the TileSprite at. * @param y The y coordinate (in world space) to position the TileSprite at. * @param width The width of the TileSprite. - Default: 256 * @param height The height of the TileSprite. - Default: 256 * @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Phaser Image Cache entry, or an instance of a PIXI.Texture or BitmapData. * @param frame If this TileSprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. */ constructor(game: Phaser.Game, x: number, y: number, width: number, height: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number); /** * A useful flag to control if the Game Object is alive or dead. * * This is set automatically by the Health components `damage` method should the object run out of health. * Or you can toggle it via your game code. * * This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates. * However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling. * Default: true */ alive: boolean; /** * The angle property is the rotation of the Game Object in *degrees* from its original orientation. * * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. * * Values outside this range are added to or subtracted from 360 to obtain a value within the range. * For example, the statement player.angle = 450 is the same as player.angle = 90. * * If you wish to work in radians instead of degrees you can use the property `rotation` instead. * Working in radians is slightly faster as it doesn't have to perform any calculations. */ angle: number; /** * If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance. * Through it you can create, play, pause and stop animations. */ animations: Phaser.AnimationManager; /** * A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame. * If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`. * This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ autoCull: boolean; /** * `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated * properties and methods via it. * * By default Game Objects won't add themselves to any physics system and their `body` property will be `null`. * * To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object * and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`. * * You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group. * * Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5, * so the physics body is centered on the Game Object. * * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. */ body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any; /** * The sum of the y and height properties. * This is the same as `y + height - offsetY`. */ bottom: number; /** * The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true. * * The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list. */ cameraOffset: Phaser.Point; /** * If this is set to `true` the Game Object checks if it is within the World bounds each frame. * * When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event. * * If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event. * * It also optionally kills the Game Object if `outOfBoundsKill` is `true`. * * When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame. * * This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required, * or you have tested performance and find it acceptable. */ checkWorldBounds: boolean; /** * The components this Game Object has installed. */ components: any; /** * Does this texture require a custom render call? (as set by BitmapData, Video, etc) */ customRender: boolean; /** * An empty Object that belongs to this Game Object. * This value isn't ever used internally by Phaser, but may be used by your own code, or * by Phaser Plugins, to store data that needs to be associated with the Game Object, * without polluting the Game Object directly. * Default: {} */ data: any; /** * A debug flag designed for use with `Game.enableStep`. */ debug: boolean; /** * As a Game Object runs through its destroy method this flag is set to true, * and can be checked in any sub-systems or plugins it is being destroyed from. */ destroyPhase: boolean; /** * All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this * Game Object, or any of its components. */ events: Phaser.Events; /** * Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}). * Default: true */ exists: boolean; /** * A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets * are stored in the `cameraOffset` property, which is initialized with the current object coordinates. * * The values are adjusted at the rendering stage, overriding the Game Objects actual world position. * * The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world * the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times * regardless where in the world the camera is. * * Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list. * * Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them. */ fixedToCamera: boolean; /** * Gets or sets the current frame index of the texture being used to render this Game Object. * * To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use, * for example: `player.frame = 4`. * * If the frame index given doesn't exist it will revert to the first frame found in the texture. * * If you are using a texture atlas then you should use the `frameName` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frame: string | number; /** * Gets or sets the current frame name of the texture being used to render this Game Object. * * To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use, * for example: `player.frameName = "idle"`. * * If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning. * * If you are using a sprite sheet then you should use the `frame` property instead. * * If you wish to fully replace the texture being used see `loadTexture`. */ frameName: string; /** * A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update. * This property is mostly used internally by the physics systems, but is exposed for the use of plugins. */ fresh: boolean; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Checks if the Game Objects bounds intersect with the Game Camera bounds. * Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds. */ inCamera: boolean; /** * The Input Handler for this Game Object. * * By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`. * * After you have done this, this property will be a reference to the Phaser InputHandler. */ input: Phaser.InputHandler; /** * By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created * for this Game Object and it will then start to process click / touch events and more. * * You can then access the Input Handler via `this.input`. * * Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`. * * If you set this property to false it will stop the Input Handler from processing any more input events. * * If you want to _temporarily_ disable input for a Game Object, then it's better to set * `input.enabled = false`, as it won't reset any of the Input Handlers internal properties. * You can then toggle this back on as needed. */ inputEnabled: boolean; /** * Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds. */ inWorld: boolean; /** * The key of the image or texture used by this Game Object during rendering. * If it is a string it's the string used to retrieve the texture from the Phaser Image Cache. * It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache. * If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it. */ key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture; /** * The left coordinate of the Game Object. * This is the same as `x - offsetX`. */ left: number; /** * A user defined name given to this Game Object. * This value isn't ever used internally by Phaser, it is meant as a game level property. */ name: string; /** * The amount the Game Object is visually offset from its x coordinate. * This is the same as `width * anchor.x`. * It will only be > 0 if anchor.x is not equal to zero. */ offsetX: number; /** * The amount the Game Object is visually offset from its y coordinate. * This is the same as `height * anchor.y`. * It will only be > 0 if anchor.y is not equal to zero. */ offsetY: number; /** * If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false. */ outOfBoundsKill: boolean; /** * A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update. * You can set it directly to allow you to flag an object to be destroyed on its next update. * * This is extremely useful if you wish to destroy an object from within one of its own callbacks * such as with Buttons or other Input events. */ pendingDestroy: boolean; /** * The const physics body type of this object. */ physicsType: number; /** * The coordinates, in pixels, of this DisplayObject, relative to its parent container. * * The value of this property does not reflect any positioning happening further up the display list. * To obtain that value please see the `worldPosition` property. */ position: Phaser.Point; /** * Enable or disable texture smoothing for this Game Object. * * It only takes effect if the Game Object is using an image based texture. * * Smoothing is enabled by default. */ smoothed: boolean; /** * The position the Game Object was located in the previous frame. */ previousPosition: Phaser.Point; previousRoation: number; /** * The right coordinate of the Game Object. * This is the same as `x + width - offsetX`. */ right: number; /** * The y coordinate of the Game Object. * This is the same as `y - offsetY`. */ top: number; /** * The render order ID is used internally by the renderer and Input Manager and should not be modified. * This property is mostly used internally by the renderers, but is exposed for the use of plugins. */ renderOrderID: number; /** * The const type of this object. */ type: number; /** * The world coordinates of this Game Object in pixels. * Depending on where in the display list this Game Object is placed this value can differ from `position`, * which contains the x/y coordinates relative to the Game Objects parent. */ world: Phaser.Point; /** * The z depth of this Game Object within its parent Group. * No two objects in a Group can have the same z value. * This value is adjusted automatically whenever the Group hierarchy changes. * If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop. */ z: number; /** * Aligns this Game Object within another Game Object, or Rectangle, known as the * 'container', to one of 9 possible positions. * * The container must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the container. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, * `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, * `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * container, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place. * So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive * one expands it. * * @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Aligns this Game Object to the side of another Game Object, or Rectangle, known as the * 'parent', in one of 11 possible positions. * * The parent must be a Game Object, or Phaser.Rectangle object. This can include properties * such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world * and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText, * TileSprites or Buttons. * * Please note that aligning a Sprite to another Game Object does **not** make it a child of * the parent. It simply modifies its position coordinates so it aligns with it. * * The position constants you can use are: * * `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, * `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, * `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` * and `Phaser.BOTTOM_RIGHT`. * * The Game Objects are placed in such a way that their _bounds_ align with the * parent, taking into consideration rotation, scale and the anchor property. * This allows you to neatly align Game Objects, irrespective of their position value. * * The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final * aligned position of the Game Object. For example: * * `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)` * * Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner. * Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place. * So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive * one expands it. * * @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`. * @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`. * @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it. * @return This Game Object. */ alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any; /** * Sets this TileSprite to automatically scroll in the given direction until stopped via TileSprite.stopScroll(). * The scroll speed is specified in pixels per second. * A negative x value will scroll to the left. A positive x value will scroll to the right. * A negative y value will scroll up. A positive y value will scroll down. * * @param x Horizontal scroll speed in pixels per second. * @param y Vertical scroll speed in pixels per second. * @return This instance. */ autoScroll(x: number, y: number): void; /** * Destroys the TileSprite. This removes it from its parent group, destroys the event and animation handlers if present * and nulls its reference to game, freeing it up for garbage collection. * * @param destroyChildren Should every child of this object have its destroy method called? - Default: true */ destroy(destroyChildren?: boolean): void; /** * Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache. * * If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead. * * You should only use `loadTexture` if you want to replace the base texture entirely. * * Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU. * * You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite. * Doing this then sets the key to be the `frame` argument (the frame is set to zero). * * This allows you to create sprites using `load.image` during development, and then change them * to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS' * and swapping it to be the key of the atlas data. * * Note: You cannot use a RenderTexture as a texture for a TileSprite. * * @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture. * @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. * @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true */ loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void; /** * Plays an Animation. * * The animation should have previously been created via `animations.add`. * * If the animation is already playing calling this again won't do anything. * If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`. * * @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'. * @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. * @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return A reference to playing Animation. */ play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation; /** * Internal method called by the World postUpdate cycle. */ postUpdate(): void; /** * Automatically called by World.preUpdate. */ preUpdate(): void; /** * Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object, * which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result. * * This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result. * * Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency. * It should be fine for low-volume testing where physics isn't required. * * @param displayObject The display object to check against. * @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object. */ overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean; /** * Resets the TileSprite. This places the TileSprite at the given x/y world coordinates, resets the tilePosition and then * sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state. * If the TileSprite has a physics body that too is reset. * * @param x The x coordinate (in world space) to position the Sprite at. * @param y The y coordinate (in world space) to position the Sprite at. * @return This instance. */ reset(x: number, y: number, health?: number): Phaser.TileSprite; /** * Resizes the Frame dimensions that the Game Object uses for rendering. * * You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData * it can be useful to adjust the dimensions directly in this way. * * @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object. * @param width The new width of the texture. * @param height The new height of the texture. */ resizeFrame(parent: any, width: number, height: number): void; /** * Resets the texture frame dimensions that the Game Object uses for rendering. */ resetFrame(): void; /** * Sets the texture frame the Game Object uses for rendering. * * This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes. * * @param frame The Frame to be used by the texture. */ setFrame(frame: Phaser.Frame): void; /** * Stops an automatically scrolling TileSprite. * @return This instance. */ stopScroll(): void; /** * Override this method in your own custom objects to handle any update requirements. * It is called immediately after `preUpdate` and before `postUpdate`. * Remember if this Game Object has any children you should call update on those too. */ update(): void; } /** * This is the core internal game clock. * * It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens, * and also handles the standard Timer pool. * * To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time#events events}. * * There are different types of time in Phaser. * * Animations, lifespan, particles, physics, timers, and tweens use game time, represented by {@link Phaser.Time#delta} and {@link Phaser.Time#deltaTotal}. * Game time is scaled by {@link Phaser.Time#slowMotion} and does not advance when paused. * * Input, sounds, and the Scale Manager use clock time, represented by {@link Phaser.Time#time}. */ class Time { /** * This is the core internal game clock. * * It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens, * and also handles the standard Timer pool. * * To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time#events events}. * * There are different types of time in Phaser. * * Animations, lifespan, particles, physics, timers, and tweens use game time, represented by {@link Phaser.Time#delta} and {@link Phaser.Time#deltaTotal}. * Game time is scaled by {@link Phaser.Time#slowMotion} and does not advance when paused. * * Input, sounds, and the Scale Manager use clock time, represented by {@link Phaser.Time#time}. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * If true then advanced profiling, including the fps rate, fps min/max, suggestedFps and msMin/msMax are updated. This isn't expensive, but displaying it with {@link Phaser.Utils.Debug#text} can be, especially in WebGL mode. */ advancedTiming: boolean; /** * The current game step interval in milliseconds. */ delta: number; /** * The maximum acceptable step interval in milliseconds, based on `desiredMinFps`. */ deltaMax: number; /** * The total of all step intervals in milliseconds. */ deltaTotal: number; /** * The number of logic updates per second. * * This is used is used to calculate the physic / logic multiplier and how to apply catch-up logic updates. * * The render rate is unaffected unless you also turn off {@link Phaser.Game#forceSingleRender}. * Default: 60 */ desiredFps: number; /** * The desired step interval in seconds, based on `desiredFps`. */ desiredFpsMult: number; /** * The smallest acceptable logic update rate. * * This is used is used to calculate {@link Phaser.Time#deltaMax}. * * It should be substantially smaller than {@link Phaser.Time#desiredFps}. * Default: 5 */ desiredMinFps: number; /** * Elapsed time since the last time update, in milliseconds, based on `now`. * * This value _may_ include time that the game is paused/inactive. * * While the game is active, this will be similar to (1000 / {@link Phaser.Time#fps fps}). * * This is updated only once per animation frame, even if multiple logic update steps are done. * * Don't use this for game timing. Use {@link Phaser.Time#delta delta} instead. */ elapsed: number; /** * A {@link Phaser.Timer} object bound to the master clock (this Time object) which events can be added to. */ events: Phaser.Timer; /** * The time in ms since the last time update, in milliseconds, based on `time`. * * This value is corrected for game pauses and will be "about zero" after a game is resumed. * * This is updated at each logic update, possibly more than once per game loop. * If multiple consecutive logic update steps are done, `elapsedMS` will be close to zero after the first. * * Don't use this for game timing. Use {@link Phaser.Time#deltaTime deltaTime} instead. */ elapsedMS: number; /** * Advanced timing result: Frames per second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ fps: number; /** * Advanced timing result: The highest rate the fps has reached (usually no higher than 60fps). * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. * This value can be manually reset. */ fpsMax: number; /** * Advanced timing result: The lowest rate the fps has dropped to. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. * This value can be manually reset. */ fpsMin: number; /** * Advanced timing result: The number of animation frames received from the browser in the last second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ frames: number; /** * Local reference to game. */ game: Phaser.Game; lastTime: number; /** * Advanced timing result: The maximum amount of time the game has taken between consecutive frames. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. * This value can be manually reset. */ msMax: number; /** * Advanced timing result: The minimum amount of time the game has taken between consecutive frames. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. * This value can be manually reset. * Default: 1000 */ msMin: number; /** * An increasing value representing cumulative milliseconds since an undisclosed epoch. * * While this value is in milliseconds and can be used to compute time deltas, * it must must _not_ be used with `Date.now()` as it may not use the same epoch / starting reference. * * The source may either be from a high-res source (eg. if RAF is available) or the standard Date.now; * the value can only be relied upon within a particular game instance. * * This is updated only once per animation frame, even if multiple logic update steps are done. */ now: number; pausedTime: number; /** * Records how long the game was last paused, in milliseconds. * (This is not updated until the game is resumed.) */ pauseDuration: number; /** * Advanced timing result: The number of {@link Phaser.Game#updateRender renders} made in the last second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ renders: number; /** * Advanced timing result: Renders per second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ rps: number; /** * Scaling factor to make the game move smoothly in slow motion (or fast motion) * * - 1.0 = normal speed * - 2.0 = half speed * - 0.5 = double speed * Default: 1 */ slowMotion: number; /** * The suggested frame rate for your game, based on an averaged real frame rate. * This value is only populated if `Time.advancedTiming` is enabled. * * _Note:_ This is not available until after a few frames have passed; until then * it's set to the same value as desiredFps. */ suggestedFps: number; /** * The `Date.now()` value when the time was last updated. */ time: number; /** * The time when the next call is expected when using setTimer to control the update loop */ timeExpected: number; /** * The value that setTimeout needs to work out when to next update */ timeToCall: number; /** * Advanced timing result: The number of {@link Phaser.Game#updateLogic logic updates} made in the last second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ updates: number; /** * Advanced timing result: Logic updates per second. * * Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled. */ ups: number; /** * Adds an existing Phaser.Timer object to the Timer pool. * * @param timer An existing Phaser.Timer object. * @return The given Phaser.Timer object. */ add(timer: Phaser.Timer): Phaser.Timer; /** * Called automatically by Phaser.Game after boot. Should not be called directly. */ boot(): void; /** * Creates a new stand-alone Phaser.Timer object. * * @param autoDestroy A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events). - Default: true * @return The Timer object that was created. */ create(autoDestroy?: boolean): Phaser.Timer; /** * How long has passed since the given time (in seconds). * * @param since The time you want to measure (in seconds). * @return Duration between given time and now (in seconds). */ elapsedSecondsSince(since: number): number; /** * How long has passed since the given time. * * @param since The time you want to measure against. * @return The difference between the given time and now. */ elapsedSince(since: number): number; /** * Remove all Timer objects, regardless of their state and clears all Timers from the {@link Phaser.Time#events events} timer. */ removeAll(): void; /** * Resets the private _started value to now and removes all currently running Timers. */ reset(): void; /** * The number of seconds that have elapsed since the game was started. * @return The number of seconds that have elapsed since the game was started. */ totalElapsedSeconds(): number; /** * Updates the game clock and advanced timing data (if enabled) from the given timestamp. * * This is called automatically by Phaser.Game once per animation frame (RAF or setTimeout). * * @param time The current relative timestamp; see {@link Phaser.Time#now now}. */ update(time: number): void; } /** * A Timer is a way to create and manage {@link Phaser.TimerEvent timer events} that wait for a specific duration and then run a callback. * Many different timer events, with individual delays, can be added to the same Timer. * * All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second. * * Timers are based on game time. They are scaled by {@link Phaser.Time#slowMotion} and do not advance when the game is paused. */ class Timer { /** * A Timer is a way to create and manage {@link Phaser.TimerEvent timer events} that wait for a specific duration and then run a callback. * Many different timer events, with individual delays, can be added to the same Timer. * * All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second. * * Timers are based on game time. They are scaled by {@link Phaser.Time#slowMotion} and do not advance when the game is paused. * * @param game A reference to the currently running game. * @param autoDestroy If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events). - Default: true */ constructor(game: Phaser.Game, autoDestroy?: boolean); /** * Number of milliseconds in half a second. */ static HALF: number; /** * Number of milliseconds in a minute. */ static MINUTE: number; /** * Number of milliseconds in a quarter of a second. */ static QUARTER: number; /** * Number of milliseconds in a second. */ static SECOND: number; /** * If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events). */ autoDestroy: boolean; /** * The duration in ms remaining until the next event will occur. */ duration: number; /** * An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it. */ events: Phaser.TimerEvent[]; /** * An expired Timer is one in which all of its events have been dispatched and none are pending. */ expired: boolean; /** * Local reference to game. */ game: Phaser.Game; /** * The number of pending events in the queue. */ length: number; /** * The duration in milliseconds that this Timer has been running for. */ ms: number; /** * The time at which the next event will occur. */ next: number; /** * The time the next tick will occur. */ nextTick: number; /** * This signal will be dispatched when this Timer has completed which means that there are no more events in the queue. * * The signal is supplied with one argument, `timer`, which is this Timer object. */ onComplete: Phaser.Signal; /** * True if the Timer is actively running. * * Do not modify this boolean - use {@link Phaser.Timer#pause pause} (and {@link Phaser.Timer#resume resume}) to pause the timer. */ running: boolean; /** * The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing. */ paused: boolean; /** * The duration in seconds that this Timer has been running for. */ seconds: number; /** * Adds a new Event to this Timer. * * The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running. * The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time. * * Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer. * * @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs. * @param callback The callback that will be called when the timer event occurs. * @param callbackContext The context in which the callback will be called. * @param args Additional arguments that will be supplied to the callback. * @return The Phaser.TimerEvent object that was created. */ add(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent; /** * Clears any events from the Timer which have pendingDelete set to true and then resets the private _len and _i values. */ clearPendingEvents(): void; /** * Destroys this Timer. Any pending Events are not dispatched. * The onComplete callbacks won't be called. */ destroy(): void; /** * Adds a new looped Event to this Timer that will repeat forever or until the Timer is stopped. * * The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running. * The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time. * * Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer. * * @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs. * @param callback The callback that will be called when the timer event occurs. * @param callbackContext The context in which the callback will be called. * @param args Additional arguments that will be supplied to the callback. * @return The Phaser.TimerEvent object that was created. */ loop(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent; /** * Orders the events on this Timer so they are in tick order. * This is called automatically when new events are created. */ order(): void; /** * Pauses the Timer and all events in the queue. */ pause(): void; /** * Removes a pending TimerEvent from the queue. * * @param event The event to remove from the queue. */ remove(event: Phaser.TimerEvent): boolean; /** * Removes all Events from this Timer and all callbacks linked to onComplete, but leaves the Timer running. * The onComplete callbacks won't be called. */ removeAll(): void; /** * Adds a new TimerEvent that will always play through once and then repeat for the given number of iterations. * * The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running. * The delay is in relation to when the Timer starts, not the time it was added. * If the Timer is already running the delay will be calculated based on the timers current time. * * Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer. * * @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs. * @param repeatCount The number of times the event will repeat once is has finished playback. A repeatCount of 1 means it will repeat itself once, playing the event twice in total. * @param callback The callback that will be called when the timer event occurs. * @param callbackContext The context in which the callback will be called. * @param args Additional arguments that will be supplied to the callback. * @return The Phaser.TimerEvent object that was created. */ repeat(delay: number, repeatCount: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent; /** * Resumes the Timer and updates all pending events. */ resume(): void; /** * Sort handler used by Phaser.Timer.order. */ sortHandler(a: any, b: any): number; /** * Starts this Timer running. * * @param delay The number of milliseconds, in {@link Phaser.Time game time}, that should elapse before the Timer will start. */ start(startDelay?: number): void; /** * Stops this Timer from running. Does not cause it to be destroyed if autoDestroy is set to true. * * @param clearEvents If true all the events in Timer will be cleared, otherwise they will remain. - Default: true */ stop(clearEvents?: boolean): void; /** * The main Timer update event, called automatically by Phaser.Time.update. * * @param time The time from the core game clock. * @return True if there are still events waiting to be dispatched, otherwise false if this Timer can be destroyed. */ update(time: number): boolean; } /** * A TimerEvent is a single event that is processed by a Phaser.Timer. * * It consists of a delay, which is a value in milliseconds after which the event will fire. * When the event fires it calls a specific callback with the specified arguments. * * TimerEvents are removed by their parent timer once finished firing or repeating. * * Use {@link Phaser.Timer#add}, {@link Phaser.Timer#repeat}, or {@link Phaser.Timer#loop} methods to create a new event. */ class TimerEvent { /** * A TimerEvent is a single event that is processed by a Phaser.Timer. * * It consists of a delay, which is a value in milliseconds after which the event will fire. * When the event fires it calls a specific callback with the specified arguments. * * TimerEvents are removed by their parent timer once finished firing or repeating. * * Use {@link Phaser.Timer#add}, {@link Phaser.Timer#repeat}, or {@link Phaser.Timer#loop} methods to create a new event. * * @param timer The Timer object that this TimerEvent belongs to. * @param delay The delay in ms at which this TimerEvent fires. * @param tick The tick is the next game clock time that this event will fire at. * @param repeatCount If this TimerEvent repeats it will do so this many times. * @param loop True if this TimerEvent loops, otherwise false. * @param callback The callback that will be called when the TimerEvent occurs. * @param callbackContext The context in which the callback will be called. * @param arguments Additional arguments to be passed to the callback. */ constructor(timer: Phaser.Timer, delay: number, tick: number, repeatCount: number, loop: boolean, callback: Function, callbackContext?: any, ...args: any[]); /** * Additional arguments to be passed to the callback. */ args: any[]; /** * The callback that will be called when the TimerEvent occurs. */ callback: Function; /** * The context in which the callback will be called. */ callbackContext: any; /** * The delay in ms at which this TimerEvent fires. */ delay: number; /** * True if this TimerEvent loops, otherwise false. */ loop: boolean; /** * A flag that controls if the TimerEvent is pending deletion. */ pendingDelete: boolean; /** * If this TimerEvent repeats it will do so this many times. */ repeatCount: number; /** * The tick is the next game clock time that this event will fire at. */ tick: number; /** * The Timer object that this TimerEvent belongs to. */ timer: Phaser.Timer; } /** * Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch. * * You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you. */ class Touch { /** * Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch. * * You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * The context under which callbacks are called. */ callbackContext: any; /** * Whether the input handler is active. */ active: boolean; /** * Touch events will only be processed if enabled. * Default: true */ enabled: boolean; /** * The browser touch DOM event. Will be set to null if no touch event has ever been received. */ event: any; /** * A reference to the currently running game. */ game: Phaser.Game; /** * If true the TouchEvent will have prevent.default called on it. * Default: true */ preventDefault: boolean; /** * A callback that can be fired on a touchCancel event. */ touchCancelCallback: Function; /** * A callback that can be fired on a touchEnd event. */ touchEndCallback: Function; /** * A callback that can be fired on a touchEnter event. */ touchEnterCallback: Function; /** * A callback that can be fired on a touchLeave event. */ touchLeaveCallback: Function; /** * A callback that can be fired on a touchMove event. */ touchMoveCallback: Function; /** * A callback that can be fired on a touchStart event. */ touchStartCallback: Function; touchLockCallbacks: Function[]; addTouchLockCallback(callback: Function, context?: any, onEnd?: boolean): void; removeTouchLockCallback(callback: Function, context?: any): boolean; /** * Consumes all touchmove events on the document (only enable this if you know you need it!). */ consumeTouchMove(): void; /** * Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome). * Occurs for example on iOS when you put down 4 fingers and the app selector UI appears. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchCancel(event: any): void; /** * The handler for the touchend events. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchEnd(event: any): void; /** * For touch enter and leave its a list of the touch points that have entered or left the target. * Doesn't appear to be supported by most browsers on a canvas element yet. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchEnter(event: any): void; /** * For touch enter and leave its a list of the touch points that have entered or left the target. * Doesn't appear to be supported by most browsers on a canvas element yet. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchLeave(event: any): void; /** * The handler for the touchmove events. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchMove(event: any): void; /** * The internal method that handles the touchstart event from the browser. * * @param event The native event from the browser. This gets stored in Touch.event. */ onTouchStart(event: any): void; /** * Starts the event listeners running. */ start(): boolean; /** * Stop the event listeners. */ stop(): void; } /** * A Tween allows you to alter one or more properties of a target object over a defined period of time. * This can be used for things such as alpha fading Sprites, scaling them or motion. * Use `Tween.to` or `Tween.from` to set-up the tween values. You can create multiple tweens on the same object * by calling Tween.to multiple times on the same Tween. Additional tweens specified in this way become "child" tweens and * are played through in sequence. You can use Tween.timeScale and Tween.reverse to control the playback of this Tween and all of its children. */ class Tween { /** * A helper for tweening {@link Phaser.Color.createColor color objects}. * * It can be passed to {@link Phaser.Tween#onUpdateCallback onUpdateCallback}. * * ```javascript * var color = Phaser.Color.createColor(255, 0, 0); // red * * var tween = game.add.tween(color).to({ * r: 0, g: 0, b: 255 // blue * }); * * tween.onUpdateCallback(Phaser.Tween.updateColor); * * tween.start(); * ``` * * @param tween A Tween with a {@link #target} that is a {@link Phaser.Color.createColor color object}. */ static updateColor(tween: Tween): void; /** * A Tween allows you to alter one or more properties of a target object over a defined period of time. * This can be used for things such as alpha fading Sprites, scaling them or motion. * Use `Tween.to` or `Tween.from` to set-up the tween values. You can create multiple tweens on the same object * by calling Tween.to multiple times on the same Tween. Additional tweens specified in this way become "child" tweens and * are played through in sequence. You can use Tween.timeScale and Tween.reverse to control the playback of this Tween and all of its children. * * @param target The target object, such as a Phaser.Sprite or Phaser.Sprite.scale. * @param game Current game instance. * @param manager The TweenManager responsible for looking after this Tween. */ constructor(target: any, game: Phaser.Game, manager: Phaser.TweenManager); /** * If this Tween is chained to another this holds a reference to it. */ chainedTween: Phaser.Tween; /** * The current Tween child being run. */ current: number; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state or waiting to start are considered as being running. */ isRunning: boolean; /** * Is this Tween paused or not? */ isPaused: boolean; /** * Reference to the TweenManager responsible for updating this Tween. */ manager: Phaser.TweenManager; /** * The onChildComplete event is fired when the Tween or any of its children completes. * Fires every time a child completes unless a child is set to repeat forever. * It will be sent 2 parameters: the target object and this tween. */ onChildComplete: Phaser.Signal; /** * The onComplete event is fired when the Tween and all of its children completes. Does not fire if the Tween is set to loop or repeatAll(-1). * It will be sent 2 parameters: the target object and this tween. */ onComplete: Phaser.Signal; /** * The onLoop event is fired if the Tween, or any child tweens loop. * It will be sent 2 parameters: the target object and this tween. */ onLoop: Phaser.Signal; /** * The onRepeat event is fired if the Tween and all of its children repeats. If this tween has no children this will never be fired. * It will be sent 2 parameters: the target object and this tween. */ onRepeat: Phaser.Signal; /** * The onStart event is fired when the Tween begins. If there is a delay before the tween starts then onStart fires after the delay is finished. * It will be sent 2 parameters: the target object and this tween. */ onStart: Phaser.Signal; /** * True if this Tween is ready to be deleted by the TweenManager. */ pendingDelete: boolean; /** * Target property cache used when building the child data values. */ properties: any; /** * If the Tween and any child tweens are set to repeat this contains the current repeat count. */ repeatCounter: number; /** * If set to `true` the current tween will play in reverse. * If the tween hasn't yet started this has no effect. * If there are child tweens then all child tweens will play in reverse from the current point. */ reverse: boolean; /** * The target object, such as a Phaser.Sprite or property like Phaser.Sprite.scale. */ target: any; /** * An Array of TweenData objects that comprise the different parts of this Tween. */ timeline: Phaser.TweenData[]; /** * The speed at which the tweens will run. A value of 1 means it will match the game frame rate. 0.5 will run at half the frame rate. 2 at double the frame rate, etc. * If a tweens duration is 1 second but timeScale is 0.5 then it will take 2 seconds to complete. * Default: 1 */ timeScale: number; /** * Gets the total duration of this Tween, including all child tweens, in milliseconds. */ totalDuration: number; /** * This method allows you to chain tweens together. Any tween chained to this tween will have its `Tween.start` method called * as soon as this tween completes. If this tween never completes (i.e. repeatAll or loop is set) then the chain will never progress. * Note that `Tween.onComplete` will fire when *this* tween completes, not when the whole chain completes. * For that you should listen to `onComplete` on the final tween in your chain. * * If you pass multiple tweens to this method they will be joined into a single long chain. * For example if this is Tween A and you pass in B, C and D then B will be chained to A, C will be chained to B and D will be chained to C. * Any previously chained tweens that may have been set will be overwritten. * * @param tweens One or more tweens that will be chained to this one. * @return This tween. Useful for method chaining. */ chain(...args: any[]): Phaser.Tween; /** * Sets the delay in milliseconds before this tween will start. If there are child tweens it sets the delay before the first child starts. * The delay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween. * If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to delay. * If you have child tweens and pass -1 as the index value it sets the delay across all of them. * * @param duration The amount of time in ms that the Tween should wait until it begins once started is called. Set to zero to remove any active delay. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children. * @return This tween. Useful for method chaining. */ delay(duration: number, index?: number): Phaser.Tween; /** * Set easing function this tween will use, i.e. Phaser.Easing.Linear.None. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * If you have child tweens and pass -1 as the index value it sets the easing function defined here across all of them. * * @param ease The easing function this tween will use, i.e. Phaser.Easing.Linear.None. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the easing function on all children. * @return This tween. Useful for method chaining. */ easing(ease: Function, index?: number): Phaser.Tween; /** * Set easing function this tween will use, i.e. Phaser.Easing.Linear.None. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * If you have child tweens and pass -1 as the index value it sets the easing function defined here across all of them. * * @param ease The easing function this tween will use, i.e. Phaser.Easing.Linear.None. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the easing function on all children. * @return This tween. Useful for method chaining. */ easing(ease: string, index?: number): Phaser.Tween; /** * Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value. * For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * * @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. * @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). * @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ from(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween; /** * Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value. * For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * * @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. * @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). * @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ from(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween; /** * This will generate an array populated with the tweened object values from start to end. * It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from. * It ignores delay and repeat counts and any chained tweens, but does include child tweens. * Just one play through of the tween data is returned, including yoyo if set. * * @param frameRate The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates. - Default: 60 * @param data If given the generated data will be appended to this array, otherwise a new array will be returned. * @return An array of tweened values. */ generateData(frameRate?: number, data?: any): any[]; /** * Sets the interpolation function the tween will use. By default it uses Phaser.Math.linearInterpolation. * Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation. * The interpolation function is only used if the target properties is an array. * If you have child tweens and pass -1 as the index value and it will set the interpolation function across all of them. * * @param interpolation The interpolation function to use (Phaser.Math.linearInterpolation by default) * @param context The context under which the interpolation function will be run. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the interpolation function on all children. * @return This tween. Useful for method chaining. */ interpolation(interpolation: Function, context?: any, index?: number): Phaser.Tween; /** * Enables the looping of this tween. The tween will loop forever, and onComplete will never fire. * * If `value` is `true` then this is the same as setting `Tween.repeatAll(-1)`. * If `value` is `false` it is the same as setting `Tween.repeatAll(0)` and will reset the `repeatCounter` to zero. * * Usage: * game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true) * .to({ y: 300 }, 1000, Phaser.Easing.Linear.None) * .to({ x: 0 }, 1000, Phaser.Easing.Linear.None) * .to({ y: 0 }, 1000, Phaser.Easing.Linear.None) * .loop(); * * @param value If `true` this tween will loop once it reaches the end. Set to `false` to remove an active loop. - Default: true * @return This tween. Useful for method chaining. */ loop(value?: boolean): Phaser.Tween; /** * Sets a callback to be fired each time this tween updates. * * The callback receives the current Tween, the {@link Phaser.TweenData#value 'value' of the current TweenData}, and the current {@link Phaser.TweenData TweenData}. The second parameter is most useful. * * ```javascript * tween.onUpdateCallback(function (tween, value, tweenData) { * console.log('Tween running -- percent: %.2f value: %.2f', tweenData.percent, value); * }); * ``` * * @param callback The callback to invoke each time this tween is updated. Set to `null` to remove an already active callback. * @param callbackContext The context in which to call the onUpdate callback. * @return This tween. Useful for method chaining. */ onUpdateCallback(callback: Function, callbackContext?: any): Phaser.Tween; /** * Pauses the tween. Resume playback with Tween.resume. */ pause(): void; /** * Sets the number of times this tween will repeat. * If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to repeat. * If you have child tweens and pass -1 as the index value it sets the number of times they'll repeat across all of them. * If you wish to define how many times this Tween and all children will repeat see Tween.repeatAll. * * @param total How many times a tween should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever. * @param repeat This is the amount of time to pause (in ms) before the repeat will start. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeat value on all the children. * @return This tween. Useful for method chaining. */ repeat(total: number, repeatDelay?: number, index?: number): Phaser.Tween; /** * Sets the delay in milliseconds before this tween will repeat itself. * The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween. * If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on. * If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them. * * @param duration The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active repeatDelay. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeatDelay on all the children. * @return This tween. Useful for method chaining. */ repeatDelay(duration: number, index?: number): Phaser.Tween; /** * Set how many times this tween and all of its children will repeat. * A tween (A) with 3 children (B,C,D) with a `repeatAll` value of 2 would play as: ABCDABCD before completing. * * @param total How many times this tween and all children should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever. * @return This tween. Useful for method chaining. */ repeatAll(total?: number): Phaser.Tween; /** * Resumes a paused tween. */ resume(): void; /** * Starts the tween running. Can also be called by the `autoStart` parameter of {@link Phaser.Tween#to to} or {@link Phaser.Tween#from from}. * This sets the {@link Phaser.Tween#isRunning isRunning} property to `true` and dispatches the {@link Phaser.Tween#onStart onStart} signal. * If the tween has a delay set then nothing will start tweening until the delay has expired. * If the tween is already running, is flagged for deletion (such as after {@link Phaser.Tween#stop stop}), * or has an empty timeline, calling start has no effect and the `onStart` signal is not dispatched. * * @param index If this Tween contains child tweens you can specify which one to start from. The default is zero, i.e. the first tween created. * @return This tween. Useful for method chaining. */ start(index?: number): Phaser.Tween; /** * Stops the tween if running and flags it for deletion from the TweenManager. The tween can't be {@link #start restarted} after this. * The {@link Phaser.Tween#onComplete onComplete} signal is not dispatched and no chained tweens are started unless the `complete` parameter is set to `true`. * If you just wish to pause a tween then use {@link Phaser.Tween#pause pause} instead. * If the tween is not running, it is **not** flagged for deletion and can be started again. * * @param complete Set to `true` to dispatch the Tween.onComplete signal. * @return This tween. Useful for method chaining. */ stop(complete?: boolean): Phaser.Tween; /** * Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given. * For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * * @param properties An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. * @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). * @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ to(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween; /** * Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given. * For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`. * The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ". * ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types. * * @param properties An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. * @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). * @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this individual tween, not any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ to(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween; /** * Core tween update function called by the TweenManager. Does not need to be invoked directly. * * @param time A timestamp passed in by the TweenManager. * @return false if the tween and all child tweens have completed and should be deleted from the manager, otherwise true (still active). */ update(time: number): boolean; /** * Updates either a single TweenData or all TweenData objects properties to the given value. * Used internally by methods like Tween.delay, Tween.yoyo, etc. but can also be called directly if you know which property you want to tweak. * The property is not checked, so if you pass an invalid one you'll generate a run-time error. * * @param property The property to update. * @param value The value to set the property to. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children. * @return This tween. Useful for method chaining. */ updateTweenData(property: string, value: number | Function, index?: number): Phaser.Tween; /** * A Tween that has yoyo set to true will run through from its starting values to its end values and then play back in reverse from end to start. * Used in combination with repeat you can create endless loops. * If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to yoyo. * If you have child tweens and pass -1 as the index value it sets the yoyo property across all of them. * If you wish to yoyo this Tween and all of its children then see Tween.yoyoAll. * * @param enable Set to true to yoyo this tween, or false to disable an already active yoyo. * @param yoyoDelay This is the amount of time to pause (in ms) before the yoyo will start. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set yoyo on all the children. * @return This tween. Useful for method chaining. */ yoyo(enable: boolean, yoyoDelay?: number, index?: number): Phaser.Tween; /** * Sets the delay in milliseconds before this tween will run a yoyo (only applies if yoyo is enabled). * The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween. * If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on. * If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them. * * @param duration The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active yoyoDelay. * @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the yoyoDelay on all the children. * @return This tween. Useful for method chaining. */ yoyoDelay(duration: number, index?: number): Phaser.Tween; } /** * A Phaser.Tween contains at least one TweenData object. It contains all of the tween data values, such as the * starting and ending values, the ease function, interpolation and duration. The Tween acts as a timeline manager for * TweenData objects and can contain multiple TweenData objects. */ class TweenData { /** * A Phaser.Tween contains at least one TweenData object. It contains all of the tween data values, such as the * starting and ending values, the ease function, interpolation and duration. The Tween acts as a timeline manager for * TweenData objects and can contain multiple TweenData objects. * * @param parent The Tween that owns this TweenData object. */ constructor(parent: Phaser.Tween); static COMPLETE: number; static LOOPED: number; static PENDING: number; static RUNNING: number; /** * The amount to delay by until the Tween starts (in ms). Only applies to the start, use repeatDelay to handle repeats. */ delay: number; /** * Current time value. */ dt: number; /** * The duration of the tween in ms. * Default: 1000 */ duration: number; /** * The easing function used for the Tween. * Default: Phaser.Easing.Default */ easingFunction: Function; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * When a Tween is yoyoing this value holds if it's currently playing forwards (false) or in reverse (true). */ inReverse: boolean; /** * True if the Tween will use interpolation (i.e. is an Array to Array tween) */ interpolate: boolean; interpolateFunctionContext: Phaser.Math; /** * The interpolation function context used for the Tween. * Default: Phaser.Math */ interpolationContext: Phaser.Math; /** * The interpolation function used for Array-based Tween. * Default: Phaser.Math.linearInterpolation */ interpolationFunction: Function; /** * If the tween is running this is set to `true`. Unless Phaser.Tween a TweenData that is waiting for a delay to expire is *not* considered as running. */ isRunning: boolean; /** * Is this a from tween or a to tween? */ isFrom: boolean; /** * The Tween which owns this TweenData. */ parent: Phaser.Tween; /** * A value between 0 and 1 that represents how far through the duration this tween is. */ percent: number; /** * If the Tween is set to repeat this is the number of repeats remaining (and `repeatTotal - repeatCounter` is the number of repeats completed). */ repeatCounter: number; /** * The time the Tween started or null if it hasn't yet started. */ startTime: number; /** * The output of the easing function for the current {@link Phaser.TweenData#percent percent}. Depending on the easing function, this will be within [0, 1] or a slightly larger range (e.g., Bounce). When easing is Linear, this will be identical to {@link Phaser.TweenData#percent percent}. */ value: number; /** * True if the Tween is set to yoyo, otherwise false. */ yoyo: boolean; /** * The amount of time in ms between yoyos of this tween. */ yoyoDelay: number; /** * Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value. * For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`. * * @param properties The properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden at will. * @param delay Delay before this tween will start, defaults to 0 (no delay). Value given is in ms. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This ignores any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ from(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData; /** * This will generate an array populated with the tweened object values from start to end. * It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from. * Just one play through of the tween data is returned, including yoyo if set. * * @param frameRate The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates. - Default: 60 * @return An array of tweened values. */ generateData(frameRate?: number): any[]; /** * Checks if this Tween is meant to repeat or yoyo and handles doing so. * @return Either Phaser.TweenData.LOOPED or Phaser.TweenData.COMPLETE. */ repeat(): number; /** * Starts the Tween running. * @return This Tween object. */ start(): Phaser.TweenData; /** * Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given. * For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`. * * @param properties The properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object. * @param duration Duration of this tween in ms. - Default: 1000 * @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden at will. * @param delay Delay before this tween will start, defaults to 0 (no delay). Value given is in ms. * @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This ignores any chained tweens. * @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead. * @return This Tween object. */ to(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData; /** * Updates this Tween. This is called automatically by Phaser.Tween. * * @param time A timestamp passed in by the Tween parent. * @return The current status of this Tween. One of the Phaser.TweenData constants: PENDING, RUNNING, LOOPED or COMPLETE. */ update(time: number): number; } /** * Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated. * Tweens are hooked into the game clock and pause system, adjusting based on the game state. * * TweenManager is based heavily on tween.js by http://soledadpenades.com. * The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object. * It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors. * Please see https://github.com/sole/tween.js for a full list of contributors. */ class TweenManager { /** * Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated. * Tweens are hooked into the game clock and pause system, adjusting based on the game state. * * TweenManager is based heavily on tween.js by http://soledadpenades.com. * The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object. * It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors. * Please see https://github.com/sole/tween.js for a full list of contributors. * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * Local reference to game. */ game: Phaser.Game; /** * Add a new tween into the TweenManager. * * @param tween The tween object you want to add. * @return The tween object you added to the manager. */ add(tween: Phaser.Tween): Phaser.Tween; /** * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite. * * @param object Object the tween will be run on. * @return The newly created tween object. */ create(object: any): Phaser.Tween; /** * Get all the tween objects in an array. * @return Array with all tween objects. */ getAll(): Phaser.Tween[]; /** * Checks to see if a particular Sprite is currently being tweened. * * The `checkIsRunning` parameter will exclude tweens that have **just** completed or been stopped but haven't yet been removed from the manager. * * @param object The object to check for tweens against. * @param checkIsRunning Also check that the tween is running and is not marked for deletion. * @return Returns true if the object is currently being tweened, false if not. */ isTweening(object: any, checkIsRunning?: boolean): boolean; /** * Remove a tween from this manager. * * @param tween The tween object you want to remove. */ remove(tween: Phaser.Tween): Phaser.Tween; /** * Remove all tweens running and in the queue. Doesn't call any of the tween onComplete events. */ removeAll(): void; /** * Remove all tweens from a specific object, array of objects or Group. * * @param obj The object you want to remove the tweens from. * @param children If passing a group, setting this to true will remove the tweens from all of its children instead of the group itself. - Default: true */ removeFrom(obj: any, children?: boolean): void; /** * Resumes all currently paused tweens. */ resumeAll(): void; /** * Update all the tween objects you added to this manager. * @return Return false if there's no tween to update, otherwise return true. */ update(): boolean; /** * Pauses all currently running tweens. */ pauseAll(): void; } class Utils { /** * Gets an object's property by string. * * @param obj The object to traverse. * @param name The property name, or a series of names separated by `.` (for nested properties). * @return - The value of the property or `undefined` if the property isn't found. */ static getProperty(obj: any, prop: string): any; /** * Sets an object's property by name and value. * * ```javascript * Phaser.Utils.setProperty(sprite, 'body.velocity.x', 60); * ``` * * @param obj The object to modify. * @param name The property name, or a series of names separated by `.` (for nested properties). * @param value The value. * @return The modified object. */ static setProperty(obj: any, prop: string, value: any): any; /** * Sets an object's properties from a map of property names and values. * * ```javascript * Phaser.Utils.setProperties(sprite, { * 'animations.paused': true, * 'body.enable': false, * 'input.draggable': true, * }); * ``` * * @param obj The object to modify. * @param props The property names and values to set on the object (see {@link #setProperty}). * @return The modified object. */ static setProperties(obj: any, props: any): any; /** * Generate a random bool result based on the chance value. * * Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. * * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%). * @return True if the roll passed, or false otherwise. */ static chanceRoll(chance: number): boolean; /** * Choose between one of two values randomly. * * @param choice1 * @param choice2 * @return The randomly selected choice */ static randomChoice(choice1: string | number, choice2: any): any; /** * Takes the given string and reverses it, returning the reversed string. * For example if given the string `Atari 520ST` it would return `TS025 iratA`. * * @param string The string to be reversed. * @return The reversed string. */ static reverseString(string: string): string; /** * Get a unit dimension from a string. * * @param size The size to parse. * @param dimension The window dimension to check. * @return The parsed dimension. */ static parseDimension(size: any, dimension: number): number; /** * Takes the given string and pads it out, to the length required, using the character * specified. For example if you need a string to be 6 characters long, you can call: * * `pad('bob', 6, '-', 2)` * * This would return: `bob---` as it has padded it out to 6 characters, using the `-` on the right. * * You can also use it to pad numbers (they are always returned as strings): * * `pad(512, 6, '0', 1)` * * Would return: `000512` with the string padded to the left. * * If you don't specify a direction it'll pad to both sides: * * `pad('c64', 7, '*')` * * Would return: `**c64**` * * @param str The target string. `toString()` will be called on the string, which means you can also pass in common data types like numbers. * @param len The number of characters to be added. * @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 * @return The padded string. */ static pad(str: string, len?: number, pad?: string, dir?: number): string; /** * This is a slightly modified version of jQuery.isPlainObject. * A plain object is an object whose internal class property is [object Object]. * * @param obj The object to inspect. * @return - true if the object is plain, otherwise false. */ static isPlainObject(object: any): boolean; /** * This is a slightly modified version of http://api.jquery.com/jQuery.extend/ * * @param deep Perform a deep copy? * @param target The target object to copy to. * @return The extended object. */ static extend(deep: boolean, target: any, ...args: any[]): any; /** * Mixes in an existing mixin object with the target. * * Values in the mixin that have either `get` or `set` functions are created as properties via `defineProperty` * _except_ if they also define a `clone` method - if a clone method is defined that is called instead and * the result is assigned directly. * * @param target The target object to receive the new functions. * @param mixin The object to copy the functions from. * @param replace If the target object already has a matching function should it be overwritten or not? */ static mixinPrototype(target: any, mixin: any, replace?: boolean): void; /** * Mixes the source object into the destination object, returning the newly modified destination object. * Based on original code by @mudcube * * @param from The object to copy (the source object). * @param to The object to copy to (the destination object). * @return The modified destination object. */ static mixin(from: T, to: any): T; } module Utils { /** * A collection of methods for displaying debug information about game objects. * * If your game is running in Canvas mode, then you should invoke all of the Debug methods from * your game's `render` function. This is because they are drawn directly onto the game canvas * itself, so if you call any debug methods outside of `render` they are likely to be overwritten * by the game itself. * * If your game is running in WebGL then Debug will create a Sprite that is placed at the top of the Stage display list and bind a canvas texture * to it, which must be uploaded every frame. Be advised: this is very expensive, especially in browsers like Firefox. So please only enable Debug * in WebGL mode if you really need it (or your desktop can cope with it well) and disable it for production! */ class Debug { static GEOM_AUTO: number; static GEOM_RECTANGLE: number; static GEOM_CIRCLE: number; static GEOM_POINT: number; static GEOM_ELLIPSE: number; /** * A collection of methods for displaying debug information about game objects. * * If your game is running in Canvas mode, then you should invoke all of the Debug methods from * your game's `render` function. This is because they are drawn directly onto the game canvas * itself, so if you call any debug methods outside of `render` they are likely to be overwritten * by the game itself. * * If your game is running in WebGL then Debug will create a Sprite that is placed at the top of the Stage display list and bind a canvas texture * to it, which must be uploaded every frame. Be advised: this is very expensive, especially in browsers like Firefox. So please only enable Debug * in WebGL mode if you really need it (or your desktop can cope with it well) and disable it for production! * * @param game A reference to the currently running game. */ constructor(game: Phaser.Game); /** * In WebGL mode this BitmapData contains a copy of the debug canvas. */ bmd: Phaser.BitmapData; /** * The canvas to which Debug calls draws. */ canvas: HTMLCanvasElement; /** * The spacing between columns. * Default: 100 */ columnWidth: number; /** * The 2d context of the canvas. */ context: CanvasRenderingContext2D; /** * The alpha of the Debug context, set before all debug information is rendered to it. * Default: 1 */ currentAlpha: number; /** * The current X position the debug information will be rendered at. */ currentX: number; /** * The current Y position the debug information will be rendered at. */ currentY: number; /** * Does the canvas need re-rendering? */ dirty: boolean; /** * The font that the debug information is rendered in. * Default: 14px monospace */ font: string; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * The line height between the debug text. * Default: 16 */ lineHeight: number; /** * The width of the stroke on lines and shapes. A positive number. * Default: 1 */ lineWidth: number; /** * Should the text be rendered with a slight shadow? Makes it easier to read on different types of background. * Default: true */ renderShadow: boolean; /** * If debugging in WebGL mode, this is the Image displaying the debug {@link #bmd BitmapData}. */ sprite: Phaser.Image; AStar(astar: Phaser.Plugin.AStar, x: number, y: number, showVisited: boolean): void; /** * Internal method that boots the debug displayer. */ boot(): void; /** * Render a Sprites Physics body if it has one set. The body is rendered as a filled or stroked rectangle. * This only works for Arcade Physics, Ninja Physics (AABB and Circle only) and Box2D Physics bodies. * To display a P2 Physics body you should enable debug mode on the body when creating it. * * @param sprite The Sprite who's body will be rendered. * @param color Color of the debug rectangle to be rendered. The format is a CSS color string such as '#ff0000' or 'rgba(255,0,0,0.5)'. - Default: 'rgba(0,255,0,0.4)' * @param filled Render the body as a filled rectangle (true) or a stroked rectangle (false) - Default: true */ body(sprite: Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.Sprite | Phaser.Text | Phaser.TileSprite, color?: string, filled?: boolean): void; /** * Render a Sprites Physic Body information. * * @param sprite The sprite to be rendered. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ bodyInfo(sprite: Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.Sprite | Phaser.Text | Phaser.TileSprite, x: number, y: Number, color?: string): void; /** * Renders 'debug draw' data for the given Box2D body. * This uses the standard debug drawing feature of Box2D, so colors will be decided by the Box2D engine. * * @param body The body to be rendered. * @param color Color of the rendering (format is css color string). - Default: 'rgb(0,255,0)' */ box2dBody(body: any /* Phaser.Physics.Box2D.Body */, color?: string): void; /** * Renders 'debug draw' data for the Box2D world if it exists. * This uses the standard debug drawing feature of Box2D, so colors will be decided by * the Box2D engine. */ box2dWorld(): void; /** * Marks the follow {@link Phaser.Utils.Debug#target target} and {@link Phaser.Utils.Debug#deadzone deadzone}. * * @param camera The Phaser.Camera to show the debug information for. * @param color Color of the debug shapes to be rendered (format is css color string). * @param filled Render the shapes filled (default, true) or stroked (false). - Default: true */ camera(camera: Phaser.Camera, color?: string, filled?: boolean): void; /** * Render camera information including dimensions and location. * * @param camera The Phaser.Camera to show the debug information for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ cameraInfo(camera: Phaser.Camera, x: number, y: number, color?: string): void; /** * Shows device capabilities: Pointer Events, Touch Events, Web Audio, WebGL. * * @param x * @param y * @param color */ device(x: number, y: number, color?: string): void; /** * Destroy this object. */ destroy(): void; /** * Renders a Phaser geometry object including Rectangle, Circle, Ellipse, Point or Line. * * @param object The geometry object to render. * @param color Color of the debug info to be rendered (format is css color string). * @param filled Render the objected as a filled (default, true) or a stroked (false) - Default: true * @param forceType Force rendering of a specific type: (0) GEOM_AUTO, 1 GEOM_RECTANGLE, (2) GEOM_CIRCLE, (3) GEOM_POINT, (4) GEOM_LINE, (5) GEOM_ELLIPSE. - Default: Phaser.Utils.Debug.GEOM_AUTO */ geom(object: any, color?: string, fiiled?: boolean, forceType?: number): void; /** * Render debug information about the Input object. * * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' * @param showDetails Also describe input sources and pointers. - Default: true */ inputInfo(x: number, y: number, color?: string, showDetails?: boolean): void; /** * Renders Line information in the given color. * * @param line The Line to display the data for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ lineInfo(line: Phaser.Line, x: number, y: number, color?: string): void; /** * Renders Phaser.Key object information. * * @param key The Key to render the information for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ key(key: Phaser.Key, x?: number, y?: number, color?: string): void; /** * Internal method that outputs a single line of text split over as many columns as needed, one per parameter. */ line(...args: string[]): void; /** * Prints the progress of a {@link Phaser.Loader}. * * Typically you would call this within a {@link State#loadRender} callback and pass `game.load` ({@link Phaser.Game#load}). * * You can enable {@link Phaser.Loader#resetLocked} to temporarily hold the loader in its 'complete' state. * Just remember to disable it before restarting the loader (such as when changing states). * * @param loader The loader. Usually `game.load` ({@link Phaser.Game#load}). * @param x The X value the debug info will start from. * @param y The Y value the debug info will start from. * @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)' */ loader(loader: Phaser.Loader, x: number, y: number, color?: string): void; /** * Prints Phaser {@link Phaser.VERSION version}, {@link Phaser.Game.#renderType rendering mode}, and {@link Phaser.Device#webAudio device audio support}. * * @param x The X value the debug info will start from. * @param y The Y value the debug info will start from. * @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)' */ phaser(x: number, y: number, color?: string): void; /** * Internal method that clears the canvas (if a Sprite) ready for a new debug session. */ preUpdate(): void; /** * Render each physics {@link Phaser.Utils.Debug#body body} in a group. * * @param group A group containing physics-enabled sprites. * @param color Color of the debug rectangle to be rendered. The format is a CSS color string such as '#ff0000' or 'rgba(255,0,0,0.5)'. - Default: 'rgba(0,255,0,0.4)' * @param filled Render the body as a filled rectangle (true) or a stroked rectangle (false). - Default: true * @param checkExists Render only children with `exists=true`. */ physicsGroup(group: Phaser.Group, color?: string, filled?: boolean, checkExists?: boolean): void; /** * Renders a single pixel at the given size. * * @param x X position of the pixel to be rendered. * @param y Y position of the pixel to be rendered. * @param color Color of the pixel (format is css color string). * @param size The width and height of the rendered pixel. - Default: 2 */ pixel(x: number, y: number, color?: string, size?: number): void; /** * Renders the Pointer.circle object onto the stage in green if down or yellow if up along with debug text. * * @param pointer The Pointer you wish to display. * @param hideIfUp Doesn't render the circle if the pointer is up. * @param downColor The color the circle is rendered in if the Pointer is down. - Default: 'rgba(0,255,0,0.5)' * @param upColor The color the circle is rendered in if the Pointer is up (and hideIfUp is false). - Default: 'rgba(255,255,0,0.5)' * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' * @param inactiveColor The color the circle is rendered in if the Pointer is inactive. - Default: 'rgb(255,0,0,0.5)' */ pointer(pointer: Phaser.Pointer, hideIfUp?: boolean, downColor?: string, upColor?: string, color?: string, inactiveColor?: string): void; /** * Visually renders a QuadTree to the display. * * @param quadtree The quadtree to render. * @param color The color of the lines in the quadtree. */ quadTree(quadtree: Phaser.QuadTree, color?: string): void; /** * Renders a Rectangle. * * @param object The rectangle to render. * @param color Color of the debug info to be rendered (format is css color string). * @param filled Render the rectangle as filled (default, true) or a stroked (false) - Default: true */ rectangle(object: Phaser.Rectangle, color?: string, filled?: boolean): void; /** * Prints a description of the {@link Phaser.Game#renderer renderer} and render session. * * @param x The X value the debug info will start from. * @param y The Y value the debug info will start from. * @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)' */ renderer(x?: number, y?: number, color?: string): void; /** * Clears the Debug canvas. */ reset(): void; /** * Renders the Rope's segments. Note: This is really expensive as it has to calculate new segments every time you call it * * @param rope The rope to display the segments of. * @param color Color of the debug info to be rendered (format is css color string). * @param filled Render the rectangle as a fillRect (default, true) or a strokeRect (false) - Default: true */ ropeSegments(rope: Phaser.Rope, color?: number, filled?: boolean): void; /** * Render Sound Manager information, including volume, mute, audio mode, and locked status. * * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ sound(x: number, y: number, color?: string): void; /** * Prints game/canvas dimensions and {@link Phaser.ScaleManager game scale} settings. * * @param x The X value the debug info will start from. * @param y The Y value the debug info will start from. * @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)' */ scale(x: number, y: number, color?: string): void; /** * Render Sound information, including decoded state, duration, volume and more. * * @param sound The sound object to debug. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ soundInfo(sound: Phaser.Sound, x: number, y: number, color?: string): void; /** * Renders the Sprites bounds. Note: This is really expensive as it has to calculate the bounds every time you call it! * * @param sprite The sprite to display the bounds of. * @param color Color of the debug info to be rendered (format is css color string). * @param filled Render the rectangle as a fillRect (default, true) or a strokeRect (false) - Default: true */ spriteBounds(sprite: any, color?: string, filled?: boolean): void; /** * Renders the sprite coordinates in local, positional and world space. * * @param sprite The sprite to display the coordinates for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ spriteCoords(sprite: any, x: number, y: number, color?: string): void; /** * Render debug infos (including name, bounds info, position and some other properties) about the Sprite. * * @param sprite The Sprite to display the information of. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ spriteInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void; /** * Render Sprite Input Debug information. * * @param sprite The sprite to display the input data for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ spriteInputInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void; /** * Internal method that resets and starts the debug output values. * * @param x The X value the debug info will start from. * @param y The Y value the debug info will start from. * @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)' * @param columnWidth The spacing between columns. */ start(x?: number, y?: number, color?: string, columnWidth?: number): void; /** * Internal method that stops the debug output. */ stop(): void; /** * Render a string of text. * * @param text The line of text to draw. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color Color of the debug info to be rendered (format is css color string). * @param font The font of text to draw. */ text(text: string, x: number, y: number, color?: string, font?: string): void; /** * Render Timer information. * * @param timer The Phaser.Timer to show the debug information for. * @param x X position of the debug info to be rendered. * @param y Y position of the debug info to be rendered. * @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)' */ timer(timer: Phaser.Timer, x: number, y: number, color?: string): void; } } /** * The Weapon Plugin provides the ability to easily create a bullet pool and manager. * * Weapons fire {@link Phaser.Bullet} objects, which are essentially Sprites with a few extra properties. * The Bullets are enabled for {@link Phaser.Physics.Arcade Arcade Physics}. They do not currently work with P2 Physics. * * The Bullets are created inside of {@link #bullets weapon.bullets}, which is a {@link Phaser.Group} instance. Anything you * can usually do with a Group, such as move it around the display list, iterate it, etc can be done * to the bullets Group too. * * Bullets can have textures and even animations. You can control the speed at which they are fired, * the firing rate, the firing angle, and even set things like gravity for them. * * A small example, using {@link Phaser.GameObjectFactory#weapon add.weapon}, assumed to be running from within a {@link Phaser.State#create} method: * * ```javascript * var weapon = this.add.weapon(10, 'bullet'); * weapon.fireFrom.set(300, 300); * this.input.onDown.add(weapon.fire, this); * ``` * * If you want to (re)create the bullet pool separately, you can use: * * ```javascript * var weapon = this.game.plugins.add(Phaser.Weapon); * // … * weapon.createBullets(10, 'bullet'); * ``` */ class Weapon extends Phaser.Plugin { /** * The Weapon Plugin provides the ability to easily create a bullet pool and manager. * * Weapons fire {@link Phaser.Bullet} objects, which are essentially Sprites with a few extra properties. * The Bullets are enabled for {@link Phaser.Physics.Arcade Arcade Physics}. They do not currently work with P2 Physics. * * The Bullets are created inside of {@link #bullets weapon.bullets}, which is a {@link Phaser.Group} instance. Anything you * can usually do with a Group, such as move it around the display list, iterate it, etc can be done * to the bullets Group too. * * Bullets can have textures and even animations. You can control the speed at which they are fired, * the firing rate, the firing angle, and even set things like gravity for them. * * A small example, using {@link Phaser.GameObjectFactory#weapon add.weapon}, assumed to be running from within a {@link Phaser.State#create} method: * * ```javascript * var weapon = this.add.weapon(10, 'bullet'); * weapon.fireFrom.set(300, 300); * this.input.onDown.add(weapon.fire, this); * ``` * * If you want to (re)create the bullet pool separately, you can use: * * ```javascript * var weapon = this.game.plugins.add(Phaser.Weapon); * // … * weapon.createBullets(10, 'bullet'); * ``` * * @param game A reference to the current Phaser.Game instance. * @param parent The Phaser Plugin Manager which looks after this plugin. */ constructor(game: Phaser.Game, parent: Phaser.PluginManager); /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that stops the bullets from ever being destroyed automatically. */ static KILL_NEVER: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets when their {@link Phaser.Weapon#bulletLifespan bulletLifespan} expires. */ static KILL_LIFESPAN: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets after they * exceed the {@link Phaser.Weapon#bulletKillDistance bulletKillDistance} from their original firing position. */ static KILL_DISTANCE: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets when they leave the {@link Phaser.Weapon#bounds bounds} rectangle. */ static KILL_WEAPON_BOUNDS: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets when they leave the {@link Phaser.Camera#bounds} rectangle. */ static KILL_CAMERA_BOUNDS: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets when they leave the {@link Phaser.World#bounds} rectangle. */ static KILL_WORLD_BOUNDS: number; /** * A {@link Phaser.Weapon#bulletKillType bulletKillType} constant that automatically kills the bullets when they leave the {@link Phaser.Weapon#bounds bounds} rectangle. */ static KILL_STATIC_BOUNDS: number; /** * Should the bullet pool run out of bullets (i.e. they are all in flight) then this * boolean controls if the Group will create a brand new bullet object or not. */ autoExpandBulletsGroup: boolean; /** * Will this weapon auto fire? If set to true then a new bullet will be fired * based on the {@link Phaser.Weapon#fireRate fireRate} value. */ autofire: boolean; /** * This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not. * It's used in combination with {@link Phaser.Weapon#bulletKillType bulletKillType} when that is set to either `Phaser.Weapon.KILL_WEAPON_BOUNDS` * or `Phaser.Weapon.KILL_STATIC_BOUNDS`. If you are not using either of these kill types then the bounds are ignored. * If you are tracking a Sprite or Point then the bounds are centered on that object every frame. */ bounds: Phaser.Rectangle; /** * An optional angle offset applied to the Bullets when they are launched. * This is useful if for example your bullet sprites have been drawn facing up, instead of * to the right, and you want to fire them at an angle. In which case you can set the * angle offset to be 90 and they'll be properly rotated when fired. */ bulletAngleOffset: number; /** * This is a variance added to the angle of Bullets when they are fired. * If you fire from an angle of 90 and have a `bulletAngleVariance` of 20 then the actual * angle of the Bullets will be between 70 and 110 degrees. This is a quick way to add a * great 'spread' effect to a Weapon. */ bulletAngleVariance: number; /** * The string based name of the animation that the Bullet will be given on launch. * This is set via {@link Phaser.Weapon#addBulletAnimation addBulletAnimation}. */ bulletAnimation: string; /** * The Class of the bullets that are launched by this Weapon. Defaults to {@link Phaser.Bullet}, but can be * overridden before calling `createBullets` and set to your own class type. * * It should be a constructor function accepting `(game, x, y, key, frame)`. */ bulletClass: any; /** * Should bullets collide with the World bounds or not? */ bulletCollideWorldBounds: boolean; /** * The Texture Frame that the Bullets use when rendering. * Changing this has no effect on bullets in-flight, only on newly spawned bullets. */ bulletFrame: string; /** * If you've added a set of frames via {@link Phaser.Weapon#setBulletFrames setBulletFrames} then you can optionally * chose for each Bullet fired to use the next frame in the set. The frame index is then * advanced one frame until it reaches the end of the set, then it starts from the start * again. Cycling frames like this allows you to create varied bullet effects via * sprite sheets. */ bulletFrameCycle: boolean; /** * If you've added a set of frames via {@link Phaser.Weapon#setBulletFrames setBulletFrames} then you can optionally * chose for each Bullet fired to pick a random frame from the set. */ bulletFrameRandom: boolean; /** * This array stores the frames added via @link #setBulletFrames. */ bulletFrames: any[]; /** * This is the amount of {@link Phaser.Physics.Arcade.Body#gravity} added to the Bullets physics body when fired. * Gravity is expressed in pixels / second / second. */ bulletGravity: Phaser.Point; /** * When a Bullet is fired it can optionally inherit the velocity of the `trackedSprite` if set. */ bulletInheritSpriteSpeed: boolean; /** * The Texture Key that the Bullets use when rendering. * Changing this has no effect on bullets in-flight, only on newly spawned bullets. */ bulletKey: string; /** * If you've set {@link Phaser.Weapon#bulletKillType bulletKillType} to `Phaser.Weapon.KILL_DISTANCE` this controls the distance * the Bullet can travel before it is automatically killed. The distance is given in pixels. */ bulletKillDistance: number; /** * This controls how the bullets will be killed. The default is `Phaser.Weapon.KILL_WORLD_BOUNDS`. * * There are 7 different "kill types" available: * * * `Phaser.Weapon.KILL_NEVER` * The bullets are never destroyed by the Weapon. It's up to you to destroy them via your own code. * * * `Phaser.Weapon.KILL_LIFESPAN` * The bullets are automatically killed when their {@link Phaser.Weapon#bulletLifespan bulletLifespan} amount expires. * * * `Phaser.Weapon.KILL_DISTANCE` * The bullets are automatically killed when they exceed {@link Phaser.Weapon#bulletKillDistance bulletKillDistance} pixels away from their original launch position. * * * `Phaser.Weapon.KILL_WEAPON_BOUNDS` * The bullets are automatically killed when they no longer intersect with the {@link Phaser.Weapon#bounds bounds} rectangle. * * * `Phaser.Weapon.KILL_CAMERA_BOUNDS` * The bullets are automatically killed when they no longer intersect with the {@link Phaser.Camera#bounds} rectangle. * * * `Phaser.Weapon.KILL_WORLD_BOUNDS` * The bullets are automatically killed when they no longer intersect with the {@link Phaser.World#bounds} rectangle. * * * `Phaser.Weapon.KILL_STATIC_BOUNDS` * The bullets are automatically killed when they no longer intersect with the {@link Phaser.Weapon#bounds bounds} rectangle. * The difference between static bounds and weapon bounds, is that a static bounds will never be adjusted to * match the position of a tracked sprite or pointer. */ bulletKillType: number; /** * If you've set {@link Phaser.Weapon#bulletKillType bulletKillType} to `Phaser.Weapon.KILL_LIFESPAN` this controls the amount * of lifespan the Bullets have set on launch. The value is given in milliseconds. * When a Bullet hits its lifespan limit it will be automatically killed. */ bulletLifespan: number; /** * Bullets can optionally adjust their rotation in-flight to match their velocity. * This can create the effect of a bullet 'pointing' to the path it is following, for example * an arrow being fired from a bow, and works especially well when added to {@link Phaser.Weapon#bulletGravity bulletGravity}. */ bulletRotateToVelocity: boolean; /** * This is the Phaser.Group that contains all of the bullets managed by this plugin. */ bullets: Phaser.Group; /** * The initial velocity of fired bullets, in pixels per second. * Default: 200 */ bulletSpeed: number; /** * This is a variance added to the speed of Bullets when they are fired. * If bullets have a {@link Phaser.Weapon#bulletSpeed bulletSpeed} value of 200, and a `bulletSpeedVariance` of 50 * then the actual speed of the Bullets will be between 150 and 250 pixels per second. */ bulletSpeedVariance: number; /** * Should the Bullets wrap around the world bounds? This automatically calls * `World.wrap` on the Bullet each frame. See the docs for that method for details. */ bulletWorldWrap: boolean; /** * If `bulletWorldWrap` is true then you can provide an optional padding value with this * property. It's added to the calculations determining when the Bullet should wrap around * the world or not. The value is given in pixels. */ bulletWorldWrapPadding: number; /** * The angle at which the bullets are fired. This can be a const such as Phaser.ANGLE_UP * or it can be any number from 0 to 360 inclusive, where 0 degrees is to the right. */ fireAngle: number; /** * This is a Rectangle from within which the bullets are fired. By default it's a 1x1 * rectangle, the equivalent of a Point. But you can change the width and height, and if * larger than 1x1 it'll pick a random point within the rectangle to launch the bullet from. */ fireFrom: Phaser.Rectangle; /** * The maximum number of shots that this Weapon is allowed to fire before it stops. * When the limit is his the {@link Phaser.Weapon#onFireLimit onFireLimit} Signal is dispatched. * You can reset the shot counter via {@link Phaser.Weapon#resetShots resetShots}. */ fireLimit: number; /** * The minimum interval between shots, in milliseconds. * Default: 100 */ fireRate: number; /** * This is a modifier that is added to the {@link Phaser.Weapon#fireRate fireRate} each update to add variety * to the firing rate of the Weapon. The value is given in milliseconds. * If you've a `fireRate` of 200 and a `fireRateVariance` of 50 then the actual * firing rate of the Weapon will be between 150 and 250. */ fireRateVariance: number; /** * If you want this Weapon to be able to fire more than 1 bullet in a single * update, then set this property to `true`. When `true` the Weapon plugin won't * set the shot / firing timers until the `postRender` phase of the game loop. * This means you can call `fire` (and similar methods) as often as you like in one * single game update. */ multiFire: boolean; /** * The onFire Signal is dispatched each time {@link Phaser.Weapon#fire fire} is called, and a Bullet is * _successfully_ launched. The callback is set two arguments: a reference to the bullet sprite itself, * and a reference to the Weapon that fired the bullet. */ onFire: Phaser.Signal; /** * The onFireLimit Signal is dispatched if {@link Phaser.Weapon#fireLimit fireLimit} is > 0, and a bullet launch takes the number * of shots fired to equal the fire limit. * The callback is sent two arguments: A reference to this Weapon, and the value of * {@link Phaser.Weapon#fireLimit fireLimit}. */ onFireLimit: Phaser.Signal; /** * The onKill Signal is dispatched each time a Bullet that is in-flight is killed. This can be the result * of leaving the Weapon bounds, an expiring lifespan, or exceeding a specified distance. * The callback is sent one argument: A reference to the bullet sprite itself. */ onKill: Phaser.Signal; /** * The total number of bullets this Weapon has fired so far. * You can limit the number of shots allowed (via {@link Phaser.Weapon#fireLimit fireLimit}), and reset * this total via {@link Phaser.Weapon#resetShots resetShots}. */ shots: number; /** * The Pointer currently being tracked by the Weapon, if any. * This is set via the {@link Phaser.Weapon#trackPointer trackPointer} method. */ trackedPointer: Phaser.Pointer; /** * The Sprite currently being tracked by the Weapon, if any. * This is set via the {@link Phaser.Weapon#trackSprite trackSprite} method. */ trackedSprite: any; /** * The Track Offset is a Point object that allows you to specify a pixel offset that bullets use * when launching from a tracked Sprite or Pointer. For example if you've got a bullet that is 2x2 pixels * in size, but you're tracking a Sprite that is 32x32, then you can set `trackOffset.x = 16` to have * the bullet launched from the center of the Sprite. */ trackOffset: Phaser.Point; /** * If the Weapon is tracking a Sprite, should it also track the Sprites rotation? * This is useful for a game such as Asteroids, where you want the weapon to fire based * on the sprites rotation. */ trackRotation: boolean; /** * The x coordinate from which bullets are fired. This is the same as `Weapon.fireFrom.x`, and * can be overridden by the {@link Phaser.Weapon#fire fire} arguments. */ x: number; /** * The y coordinate from which bullets are fired. This is the same as `Weapon.fireFrom.y`, and * can be overridden by the {@link Phaser.Weapon#fire fire} arguments. */ y: number; /** * Adds a new animation under the given key. Optionally set the frames, frame rate and loop. * The arguments are all the same as for `Animation.add`, and work in the same way. * * {@link Phaser.Weapon#bulletAnimation bulletAnimation} will be set to this animation after it's created. From that point on, all * bullets fired will play using this animation. You can swap between animations by calling this method * several times, and then just changing the {@link Phaser.Weapon#bulletAnimation bulletAnimation} property to the name of the animation * you wish to play for the next launched bullet. * * If you wish to stop using animations at all, set {@link Phaser.Weapon#bulletAnimation bulletAnimation} to '' (an empty string). * * @param name The unique (within the Weapon instance) name for the animation, i.e. "fire", "blast". * @param frames An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used. * @param frameRate The speed at which the animation should play. The speed is given in frames per second. - Default: 60 * @param loop Whether or not the animation is looped or just plays once. * @param useNumericIndex Are the given frames using numeric indexes (default) or strings? - Default: true * @return The Weapon Plugin. */ addBulletAnimation(name: string, frames?: number[] | string[], frameRate?: number, loop?: boolean, useNumericIndex?: boolean): Phaser.Weapon; /** * This method performs two actions: First it will check to see if the {@link Phaser.Weapon#bullets bullets} Group exists or not, * and if not it creates it, adding it the `group` given as the 4th argument. * * Then it will seed the bullet pool with the `quantity` number of Bullets, using the texture key and frame * provided (if any). * * If for example you set the quantity to be 10, then this Weapon will only ever be able to have 10 bullets * in-flight simultaneously. If you try to fire an 11th bullet then nothing will happen until one, or more, of * the in-flight bullets have been killed, freeing them up for use by the Weapon again. * * If you do not wish to have a limit set, then pass in -1 as the quantity. In this instance the Weapon will * keep increasing the size of the bullet pool as needed. It will never reduce the size of the pool however, * so be careful it doesn't grow too large. * * You can either set the texture key and frame here, or via the {@link Phaser.Weapon#bulletKey bulletKey} and {@link Phaser.Weapon#bulletFrame bulletFrame} * properties. You can also animate bullets, or set them to use random frames. All Bullets belonging to a * single Weapon instance must share the same texture key however. * * @param quantity The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand. - Default: 1 * @param key The Game.cache key of the image that this Sprite will use. * @param frame If the Sprite image contains multiple frames you can specify which one to use here. * @param group Optional Group to add the object to. If not specified it will be added to the World group. * @return This Weapon instance. */ createBullets(quantity?: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Weapon; /** * Uses `Game.Debug` to draw some useful information about this Weapon, including the number of bullets * both in-flight, and available. And optionally the physics debug bodies of the bullets. * * @param x The coordinate, in screen space, at which to draw the Weapon debug data. - Default: 16 * @param y The coordinate, in screen space, at which to draw the Weapon debug data. - Default: 32 * @param debugBodies Optionally draw the physics body of every bullet in-flight. */ debug(x?: number, y?: number, debugBodies?: boolean): void; /** * Destroys this Weapon. It removes itself from the PluginManager, destroys * the {@link Phaser.Weapon#bullets bullets} Group, and nulls internal references. */ destroy(): void; /** * Attempts to fire a single Bullet. If there are no more bullets available in the pool, and the pool cannot be extended, * then this method returns `null`. It will also return `null` if not enough time has expired since the last time * the Weapon was fired, as defined in the {@link Phaser.Weapon#fireRate fireRate} property. * * Otherwise the first available bullet is selected, launched, and returned. * * The arguments are all optional, but allow you to control both where the bullet is launched from, and aimed at. * * If you don't provide any of the arguments then it uses those set via properties such as {@link Phaser.Weapon#trackedSprite trackedSprite}, * {@link Phaser.Weapon#bulletAngle bulletAngle} and so on. * * When the bullet is launched it has its texture and frame updated, as required. The velocity of the bullet is * calculated based on Weapon properties like `bulletSpeed`. * * If you wish to fire multiple bullets in a single game update, then set `Weapon.multiFire = true` * and you can call `fire` as many times as you like, per loop. Multiple fires in a single update * only counts once towards the `shots` total, but you will still receive a Signal for each bullet. * * @param from Optionally fires the bullet **from** the `x` and `y` properties of this object. If set this overrides {@link #trackedSprite} or `trackedPointer`. Pass `null` to ignore it. * @param x The x coordinate, in world space, to fire the bullet **towards**. If left as `undefined`, or `null`, the bullet direction is based on its angle. * @param y The y coordinate, in world space, to fire the bullet **towards**. If left as `undefined`, or `null`, the bullet direction is based on its angle. * @param offsetX If the bullet is fired from a tracked Sprite or Pointer, or the `from` argument is set, this applies a horizontal offset from the launch position. * @param offsetY If the bullet is fired from a tracked Sprite or Pointer, or the `from` argument is set, this applies a vertical offset from the launch position. * @return The fired bullet, if a launch was successful, otherwise `null`. */ fire(from?: any, x?: number, y?: number, offsetX?: number, offsetY?: number): Phaser.Bullet; /** * Fires a bullet **at** the given Pointer. The bullet will be launched from the {@link Phaser.Weapon#fireFrom fireFrom} position, * or from a Tracked Sprite or Pointer, if you have one set. * * @param pointer The Pointer to fire the bullet towards. * @return The fired bullet if successful, null otherwise. */ fireAtPointer(pointer: Phaser.Pointer): Phaser.Bullet; /** * Fires a bullet **at** the given Sprite. The bullet will be launched from the {@link Phaser.Weapon#fireFrom fireFrom} position, * or from a Tracked Sprite or Pointer, if you have one set. * * @param sprite The Sprite to fire the bullet towards. * @return The fired bullet if successful, null otherwise. */ fireAtSprite(sprite: Phaser.Sprite): Phaser.Bullet; /** * Fires a bullet **at** the given coordinates. The bullet will be launched from the {@link Phaser.Weapon#fireFrom fireFrom} position, * or from a Tracked Sprite or Pointer, if you have one set. * * @param x The x coordinate, in world space, to fire the bullet towards. * @param y The y coordinate, in world space, to fire the bullet towards. * @return The fired bullet if successful, null otherwise. */ fireAtXY(x: number, y: number): Phaser.Bullet; /** * Attempts to fire multiple bullets from the positions defined in the given array. * * If you provide a `from` argument, or if there is a tracked Sprite or Pointer, then * the positions are treated as __offsets__ from the given objects position. * * If `from` is undefined, and there is no tracked object, then the bullets are fired * from the given positions, as they exist in the world. * * Calling this method sets {@link Phaser.Weapon#multiFire multiFire} to `true`. * * If there are not enough bullets available in the pool, and the pool cannot be extended, * then this method may not fire from all of the given positions. * * When the bullets are launched they have their texture and frame updated, as required. * The velocity of the bullets are calculated based on Weapon properties like {@link Phaser.Weapon#bulletSpeed bulletSpeed}. * * @param positions An array of positions. Each position can be any Object, as long as it has public `x` and `y` properties, such as Phaser.Point, { x: 0, y: 0 }, Phaser.Sprite, etc. * @param from Optionally fires the bullets **from** the `x` and `y` properties of this object, _instead_ of any {@link #trackedSprite} or `trackedPointer` that is set. * @return An array containing all of the fired Phaser.Bullet objects, if a launch was successful, otherwise an empty array. */ fireMany(positions: any[], from?: any): Phaser.Bullet[]; /** * Attempts to fire a single Bullet from a tracked Sprite or Pointer, but applies an offset * to the position first. This is the same as calling {@link Phaser.Weapon#fire fire} and passing in the offset arguments. * * If there are no more bullets available in the pool, and the pool cannot be extended, * then this method returns `null`. It will also return `null` if not enough time has expired since the last time * the Weapon was fired, as defined in the {@link Phaser.Weapon#fireRate fireRate} property. * * Otherwise the first available bullet is selected, launched, and returned. * * When the bullet is launched it has its texture and frame updated, as required. The velocity of the bullet is * calculated based on Weapon properties like {@link Phaser.Weapon#bulletSpeed bulletSpeed}. * * If you wish to fire multiple bullets in a single game update, then set {@link Phaser.Weapon#multiFire multiFire} to `true` * and you can call this method as many times as you like, per loop. See also {@link Phaser.Weapon#fireMany fireMany}. * * @param offsetX The horizontal offset from the position of the tracked Sprite or Pointer, as set with {@link #trackSprite}. * @param offsetY The vertical offset from the position of the tracked Sprite or Pointer, as set with {@link #trackSprite}. * @return The fired bullet, if a launch was successful, otherwise `null`. */ fireOffset(offsetX?: number, offsetY?: number): Phaser.Bullet; /** * Call a function on each in-flight bullet in this Weapon. * * See {@link Phaser.Group#forEachExists forEachExists} for more details. * * @param callback The function that will be called for each applicable child. The child will be passed as the first argument. * @param callbackContext The context in which the function should be called (usually 'this'). * @param args Additional arguments to pass to the callback function, after the child item. - Default: (none) * @return This Weapon instance. */ forEach(callback: any, callbackContext?: any): Phaser.Weapon; /** * Calls {@link Phaser.Bullet#kill} on every in-flight bullet in this Weapon. * Also re-enables their physics bodies, should they have been disabled via {@link Phaser.Weapon#pauseAll pauseAll}. * @return This Weapon instance. */ killAll(): Phaser.Weapon; /** * Sets {@link Phaser.Physics.Arcade.Body#enable} to `false` on each bullet in this Weapon. * This has the effect of stopping them in-flight should they be moving. * It also stops them being able to be checked for collision. * @return This Weapon instance. */ pauseAll(): Phaser.Weapon; /** * Resets the {@link Phaser.Weapon#shots shots} counter back to zero. This is used when you've set * {@link Phaser.Weapon#fireLimit fireLimit} and have hit (or just wish to reset) your limit. * * @param newLimit Optionally set a new {@link #fireLimit}. * @return This Weapon instance. */ resetShots(newLimit?: number): Phaser.Weapon; /** * Sets {@link Phaser.Physics.Arcade.Body#enable} to `true` on each bullet in this Weapon. * This has the effect of resuming their motion should they be in-flight. * It also enables them for collision checks again. * @return This Weapon instance. */ resumeAll(): Phaser.Weapon; /** * You can modify the size of the physics Body the Bullets use to be any dimension you need. * This allows you to make it smaller, or larger, than the parent Sprite. * You can also control the x and y offset of the Body. This is the position of the * Body relative to the top-left of the Sprite _texture_. * * For example: If you have a Sprite with a texture that is 80x100 in size, * and you want the physics body to be 32x32 pixels in the middle of the texture, you would do: * * `setSize(32 / Math.abs(this.scale.x), 32 / Math.abs(this.scale.y), 24, 34)` * * Where the first two parameters are the new Body size (32x32 pixels) relative to the Sprite's scale. * 24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34 * is the vertical offset. * * @param width The width of the Body. * @param height The height of the Body. * @param offsetX The X offset of the Body from the top-left of the Sprites texture. * @param offsetY The Y offset of the Body from the top-left of the Sprites texture. * @return The Weapon Plugin. */ setBulletBodyOffset(width: number, height: number, offsetX?: number, offsetY?: number): Phaser.Weapon; /** * Sets the texture frames that the bullets can use when being launched. * * This is intended for use when you've got numeric based frames, such as those loaded via a Sprite Sheet. * * It works by calling `Phaser.ArrayUtils.numberArray` internally, using the min and max values * provided. Then it sets the frame index to be zero. * * You can optionally set the cycle and random booleans, to allow bullets to cycle through the frames * when they're fired, or pick one at random. * * @param min The minimum value the frame can be. Usually zero. * @param max The maximum value the frame can be. * @param cycle Should the bullet frames cycle as they are fired? - Default: true * @param random Should the bullet frames be picked at random as they are fired? * @return The Weapon Plugin. */ setBulletFrames(min: number, max: number, cycle?: boolean, random?: boolean): Phaser.Weapon; /** * Sets this Weapon to track the given Pointer. * When a Weapon tracks a Pointer it will automatically update its {@link Phaser.Weapon#fireFrom fireFrom} value to match the Pointer's * position within the Game World, adjusting the coordinates based on the offset arguments. * * This allows you to lock a Weapon to a Pointer, so that bullets are always launched from its location. * * Calling `trackPointer` will reset {@link Phaser.Weapon#trackedSprite trackedSprite} to null, should it have been set, as you can * only track _either_ a Pointer, or a Sprite, at once, but not both. * * @param pointer The Pointer to track the position of. Defaults to `Input.activePointer` if not specified. * @param offsetX The horizontal offset from the Pointers position to be applied to the Weapon. * @param offsetY The vertical offset from the Pointers position to be applied to the Weapon. * @return This Weapon instance. */ trackPointer(pointer: Phaser.Pointer, offsetX?: number, offsetY?: number): Phaser.Weapon; /** * Sets this Weapon to track the given Sprite, or any Object with a public {@link Phaser.Component.Core#world world} Point object. * When a Weapon tracks a Sprite it will automatically update its {@link Phaser.Weapon#fireFrom fireFrom} value to match the Sprite's * position within the Game World, adjusting the coordinates based on the offset arguments. * * This allows you to lock a Weapon to a Sprite, so that bullets are always launched from its location. * * Calling `trackSprite` will reset {@link Phaser.Weapon#trackedPointer trackedPointer} to null, should it have been set, as you can * only track _either_ a Sprite, or a Pointer, at once, but not both. * * @param sprite The Sprite to track the position of. * @param offsetX The horizontal offset from the Sprites position to be applied to the Weapon. * @param offsetY The vertical offset from the Sprites position to be applied to the Weapon. * @param trackRotation Should the Weapon also track the Sprites rotation? * @return This Weapon instance. */ trackSprite(sprite: Phaser.Sprite, offsetX?: number, offsetY?: number, trackRotation?: boolean): Phaser.Weapon; } /** * "This world is but a canvas to our imagination." - Henry David Thoreau * * A game has only one world. The world is an abstract place in which all game objects live. It is not bound * by stage limits and can be any size. You look into the world via cameras. All game objects live within * the world at world-based coordinates. By default a world is created the same size as your Stage. */ class World extends Phaser.Group { /** * "This world is but a canvas to our imagination." - Henry David Thoreau * * A game has only one world. The world is an abstract place in which all game objects live. It is not bound * by stage limits and can be any size. You look into the world via cameras. All game objects live within * the world at world-based coordinates. By default a world is created the same size as your Stage. * * @param game Reference to the current game instance. */ constructor(game: Phaser.Game); /** * The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects. * By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display. * However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0. * So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0. Bound of this world that objects can not escape from. */ bounds: Phaser.Rectangle; /** * Camera instance. */ camera: Phaser.Camera; /** * Gets the X position corresponding to the center point of the world. */ centerX: number; /** * Gets the Y position corresponding to the center point of the world. */ centerY: number; /** * A reference to the currently running Game. */ game: Phaser.Game; /** * Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions. */ height: number; isPaused: boolean; /** * Gets a random integer which is lesser than or equal to the current width of the game world. */ randomX: number; /** * Gets a random integer which is lesser than or equal to the current height of the game world. */ randomY: number; stats: { skipped: number; ignored: number; checked: number; }; /** * Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions. */ width: number; /** * Initialises the game world. */ boot(): void; getObjectsUnderPointer(pointer: Phaser.Pointer, group: Phaser.Group, callback?: Function, callbackContext?: any): Phaser.Sprite; /** * Updates this world's width and height (but not smaller than any previous {@link #setBounds defined size}). * * Phaser uses this to adapt to {@link Phaser.ScaleManager#updateDimensions layout changes}. * You probably want to use {@link Phaser.World#setBounds setBounds} instead. * * @param width New width of the game world in pixels. * @param height New height of the game world in pixels. */ resize(width: number, height: number): void; /** * Updates the size of this world and sets World.x/y to the given values * The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds. * * @param x Top left most corner of the world. * @param y Top left most corner of the world. * @param width New width of the game world in pixels. * @param height New height of the game world in pixels. */ setBounds(x: number, y: number, width: number, height: number): void; sortLeftRight(a: Phaser.Sprite, b: Phaser.Sprite): number; sortRightLeft(a: Phaser.Sprite, b: Phaser.Sprite): number; sortTopBottom(a: Phaser.Sprite, b: Phaser.Sprite): number; sortBottomTop(a: Phaser.Sprite, b: Phaser.Sprite): number; /** * Sort the children in the group according to a particular key and ordering. * * Call this function to sort the group according to a particular key value and order. * * For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`. * * Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including * alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details. * * @param key The name of the property to sort on. Defaults to the objects z-depth value. - Default: 'z' * @param order Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}). - Default: Phaser.Group.SORT_ASCENDING */ sort(group: Phaser.Group, sortDirection?: number): void; /** * Sort the children in the group according to a particular key and ordering. * * Call this function to sort the group according to a particular key value and order. * * For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`. * * Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including * alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details. * * @param key The name of the property to sort on. Defaults to the objects z-depth value. - Default: 'z' * @param order Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}). - Default: Phaser.Group.SORT_ASCENDING */ sort(key?: string, order?: number): void; /** * Destroyer of worlds. */ shutdown(): void; /** * This will take the given game object and check if its x/y coordinates fall outside of the world bounds. * If they do it will reposition the object to the opposite side of the world, creating a wrap-around effect. * If sprite has a P2 body then the body (sprite.body) should be passed as first parameter to the function. * * Please understand there are limitations to this method. For example if you have scaled the World * then objects won't always be re-positioned correctly, and you'll need to employ your own wrapping function. * * @param sprite The object you wish to wrap around the world bounds. * @param padding Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true. * @param useBounds If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive. * @param horizontal If horizontal is false, wrap will not wrap the object.x coordinates horizontally. - Default: true * @param vertical If vertical is false, wrap will not wrap the object.y coordinates vertically. - Default: true */ wrap(sprite: any, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void; /** * * * @param group A group of sprites. * @param checkExists Wrap only sprites having `exists=true`. * @param padding Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true. * @param useBounds If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive. * @param horizontal If horizontal is false, wrap will not wrap the object.x coordinates horizontally. - Default: true * @param vertical If vertical is false, wrap will not wrap the object.y coordinates vertically. - Default: true */ wrapAll(group: Phaser.Group, checkExists?: boolean, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void; } }