phaser-ce
Version:
Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
1,328 lines (1,109 loc) • 1.59 MB
TypeScript
/// <reference path="pixi.comments.d.ts" />
/// <reference path="p2.d.ts" />
// Type definitions for Phaser CE
// Project: https://github.com/photonstorm/phaser-ce
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;
}
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 prefix 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<T>(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<T>(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<T>(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<T>(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<T>(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;
/**
* 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 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;
op: string;
/**
* An Uint32Array view into BitmapData.buffer.
*/
pixels: Uint32Array;
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.