phaser/typescript/phaser.comments.d.ts

32081 lines
1.4 MiB
TypeScript
Raw Normal View History

2016-08-26 00:18:47 +00:00
/// <reference path="pixi.comments.d.ts" />
/// <reference path="p2.d.ts" />
// Type definitions for Phaser 2.6.2 - 26th August 2016
// Project: https://github.com/photonstorm/phaser
declare module "phaser" {
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 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 {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Animation {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, parent: Phaser.Sprite, name: string, frameData: Phaser.FrameData, frames: number[] | string[], frameRate?: number, loop?: boolean);
2016-06-17 11:46:47 +00:00
/**
* The currently displayed frame of the Animation.
*/
2016-08-26 00:18:47 +00:00
currentFrame: Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* The delay in ms between each frame of the Animation, based on the given frameRate.
*/
2016-08-26 00:18:47 +00:00
delay: number;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets if this animation will dispatch the onUpdate events upon changing frame.
*/
2016-08-26 00:18:47 +00:00
enableUpdate: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the current frame index and updates the Texture Cache for display.
*/
2016-08-26 00:18:47 +00:00
frame: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
*/
2016-08-26 00:18:47 +00:00
frameTotal: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The finished state of the Animation. Set to true once playback completes, false during playback.
*/
2016-08-26 00:18:47 +00:00
isFinished: boolean;
2016-06-17 11:46:47 +00:00
/**
* The paused state of the Animation.
*/
2016-08-26 00:18:47 +00:00
isPaused: boolean;
2016-06-17 11:46:47 +00:00
/**
* The playing state of the Animation. Set to false once playback completes, true during playback.
*/
2016-08-26 00:18:47 +00:00
isPlaying: boolean;
2016-06-17 11:46:47 +00:00
/**
* Should the parent of this Animation be killed when the animation completes?
*/
2016-08-26 00:18:47 +00:00
killOnComplete: boolean;
2016-06-17 11:46:47 +00:00
/**
* The loop state of the Animation.
*/
2016-08-26 00:18:47 +00:00
loop: boolean;
2016-06-17 11:46:47 +00:00
/**
* The number of times the animation has looped since it was last started.
*/
2016-08-26 00:18:47 +00:00
loopCount: number;
2016-06-17 11:46:47 +00:00
/**
* The user defined name given to this Animation.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when this Animation completes playback. If the animation is set to loop this is never fired, listen for onLoop instead.
*/
2016-08-26 00:18:47 +00:00
onComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when this Animation loops.
*/
2016-08-26 00:18:47 +00:00
onLoop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when this Animation starts playback.
*/
2016-08-26 00:18:47 +00:00
onStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onUpdate: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* Gets and sets the paused state of this Animation.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets and sets the isReversed state of this Animation.
*/
2016-08-26 00:18:47 +00:00
reversed: boolean;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
speed: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
complete(): void;
2016-06-17 11:46:47 +00:00
/**
* Cleans up this animation ready for deletion. Nulls all values and references.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static generateFrameNames(prefix: string, start: number, stop: number, suffix?: string, zeroPad?: number): string[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
next(quantity?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Called when the Game enters a paused state.
*/
2016-08-26 00:18:47 +00:00
onPause(): void;
2016-06-17 11:46:47 +00:00
/**
* Called when the Game resumes from a paused state.
*/
2016-08-26 00:18:47 +00:00
onResume(): void;
2016-06-17 11:46:47 +00:00
/**
* Plays this animation.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
play(frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
previous(quantity?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Sets this animation back to the first frame and restarts the animation.
*/
2016-08-26 00:18:47 +00:00
restart(): void;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* Reverses the animation direction.
2016-06-17 11:46:47 +00:00
* @return The animation instance.
*/
2016-08-26 00:18:47 +00:00
reverse(): Animation;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reverseOnce(): Animation;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrame(frameId?: string | number, useLocalFrameIndex?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
stop(resetFrame?: boolean, dispatchComplete?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Updates this animation. Called automatically by the AnimationManager.
*/
2016-08-26 00:18:47 +00:00
update(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateCurrentFrame(signalUpdate: boolean, fromPlay?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Changes the FrameData object this Animation is using.
*
* @param frameData The FrameData object that contains all frames used by this Animation.
*/
2016-08-26 00:18:47 +00:00
updateFrameData(frameData: FrameData): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class AnimationManager {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(sprite: Phaser.Sprite);
2016-06-17 11:46:47 +00:00
/**
* The currently displayed animation, if any.
*/
2016-08-26 00:18:47 +00:00
currentAnim: Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
currentFrame: Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the current frame index and updates the Texture Cache for display.
*/
2016-08-26 00:18:47 +00:00
frame: number;
2016-06-17 11:46:47 +00:00
/**
* The current animations FrameData.
*/
2016-08-26 00:18:47 +00:00
frameData: Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the current frame name and updates the Texture Cache for display.
*/
2016-08-26 00:18:47 +00:00
frameName: string;
2016-06-17 11:46:47 +00:00
/**
* The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
*/
2016-08-26 00:18:47 +00:00
frameTotal: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Set to true once animation data has been loaded.
*/
2016-08-26 00:18:47 +00:00
isLoaded: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets the current animation name, if set.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* Gets and sets the paused state of the current animation.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the parent Sprite that owns this AnimationManager.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Should the animation data continue to update even if the Sprite.visible is set to false.
* Default: true
*/
2016-08-26 00:18:47 +00:00
updateIfVisible: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(name: string, frames?: number[] | string[], frameRate?: number, loop?: boolean, useNumericIndex?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* 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`
*/
2016-08-26 00:18:47 +00:00
copyFrameData(frameData: Phaser.FrameData, frame: string | number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Destroys all references this AnimationManager contains.
* Iterates through the list of animations stored in this manager and calls destroy on each of them.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getAnimation(name: string): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
next(quantity?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
previous(quantity?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
stop(name?: string, resetFrame?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
validateFrames(frames: Phaser.Frame[], useNumericIndex?: boolean): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
*/
2016-08-26 00:18:47 +00:00
class AnimationParser {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static JSONData(game: Phaser.Game, json: any): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static JSONDataHash(game: Phaser.Game, json: any): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static JSONDataPyxel(game: Phaser.Game, json: any): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return A FrameData object containing the parsed frames.
*/
2016-08-26 00:18:47 +00:00
static spriteSheet(game: Phaser.Game, key: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static XMLData(game: Phaser.Game, xml: any): Phaser.FrameData;
}
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
class AudioSprite {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, key: string);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Asset key for the Audio Sprite.
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* JSON audio atlas object.
*/
2016-08-26 00:18:47 +00:00
config: any;
2016-06-17 11:46:47 +00:00
/**
* If a sound is set to auto play, this holds the marker key of it.
*/
2016-08-26 00:18:47 +00:00
autoplayKey: string;
2016-06-17 11:46:47 +00:00
/**
* Is a sound set to autoplay or not?
*/
2016-08-26 00:18:47 +00:00
autoplay: boolean;
2016-06-17 11:46:47 +00:00
/**
* An object containing the Phaser.Sound objects for the Audio Sprite.
*/
2016-08-26 00:18:47 +00:00
sounds: any;
2016-06-17 11:46:47 +00:00
/**
* Get a sound with the given name.
*
* @param marker The name of sound to get.
* @return The sound instance.
*/
2016-08-26 00:18:47 +00:00
get(marker: string): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(marker: string, volume?: number): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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: ''
*/
2016-08-26 00:18:47 +00:00
stop(marker: string): Phaser.Sound;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class ArraySet {
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
constructor(list: any[]);
2016-06-17 11:46:47 +00:00
/**
* Current cursor position as established by `first` and `next`.
*/
2016-08-26 00:18:47 +00:00
position: number;
2016-06-17 11:46:47 +00:00
/**
* The backing array.
*/
2016-08-26 00:18:47 +00:00
list: any[];
2016-06-17 11:46:47 +00:00
/**
* Number of items in the ArraySet. Same as `list.length`.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* Returns the first item and resets the cursor to the start.
*/
2016-08-26 00:18:47 +00:00
first: any;
2016-06-17 11:46:47 +00:00
/**
* Returns the the next item (based on the cursor) and advances the cursor.
*/
2016-08-26 00:18:47 +00:00
next: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(item: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getByKey(property: string, value: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getIndex(item: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
exists(item: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* Removes all the items.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
remove(item: any): any;
2016-06-17 11:46:47 +00:00
/**
* Removes every member from this ArraySet and optionally destroys it.
*
* @param destroy Call `destroy` on each member as it's removed from this set.
*/
2016-08-26 00:18:47 +00:00
removeAll(destoy?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setAll(key: any, value: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
callAll(key: string, ...parameter: any[]): void;
}
2016-06-17 11:46:47 +00:00
/**
* Utility functions for dealing with Arrays.
*/
2016-08-26 00:18:47 +00:00
class ArrayUtils {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getRandomItem<T>(objects: T[], startIndex?: number, length?: number): T;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static removeRandomItem<T>(objects: T[], startIndex?: number, length?: number): T;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static shuffle<T>(array: T[]): T[];
2016-06-17 11:46:47 +00:00
/**
* Transposes the elements of the given matrix (array of arrays).
*
* @param array The matrix to transpose.
* @return A new transposed matrix
*/
2016-08-26 00:18:47 +00:00
static transposeMatrix<T>(array: T[]): T;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static rotateMatrix(matrix: any, direction: number | string): any;
2016-06-17 11:46:47 +00:00
/**
* Snaps a value to the nearest value in an 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.
*/
2016-08-26 00:18:47 +00:00
static findClosest(value: number, arr: number[]): number;
2016-06-17 11:46:47 +00:00
/**
* Moves the element from the start of the array to the end, shifting all items in the process.
* The "rotation" happens to the left.
2016-07-08 14:46:26 +00:00
*
* Before: `[ A, B, C, D, E, F ]`
* After: `[ B, C, D, E, F, A ]`
*
* See also Phaser.ArrayUtils.rotateRight
2016-07-01 15:57:13 +00:00
*
* @param array The array to rotate. The array is modified.
* @return The rotated value.
*/
2016-08-26 00:18:47 +00:00
static rotate(array: any[]): any;
2016-07-01 15:57:13 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static rotateLeft(array: any[]): any;
2016-07-08 14:46:26 +00:00
2016-07-01 15:57:13 +00:00
/**
* Moves the element from the end of the array to the start, shifting all items in the process.
* The "rotation" happens to the right.
2016-06-17 11:46:47 +00:00
*
2016-07-08 14:46:26 +00:00
* 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.
2016-06-17 11:46:47 +00:00
* @return The shifted value.
*/
2016-08-26 00:18:47 +00:00
static rotateRight(array: any[]): any;
2016-06-17 11:46:47 +00:00
/**
* Create an array representing the inclusive range of numbers (usually integers) in `[start, end]`.
* This is equivalent to `numberArrayStep(start, end, 1)`.
*
* @param start The minimum value the array starts with.
* @param end The maximum value the array contains.
* @return The array of number values.
*/
2016-08-26 00:18:47 +00:00
static numberArray(start: number, end: number): number[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class BitmapData {
2016-06-17 11:46:47 +00:00
/**
* 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
2016-07-08 14:46:26 +00:00
* @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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, key: string, width?: number, height?: number, skipPool?: boolean);
2016-06-17 11:46:47 +00:00
/**
* The PIXI.BaseTexture.
*/
2016-08-26 00:18:47 +00:00
baseTexture: PIXI.BaseTexture;
buffer: ArrayBuffer;
2016-06-17 11:46:47 +00:00
/**
* The canvas to which this BitmapData draws.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* The 2d context of the canvas.
*/
2016-08-26 00:18:47 +00:00
context: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* A reference to BitmapData.context.
*/
2016-08-26 00:18:47 +00:00
ctx: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* A Uint8ClampedArray view into BitmapData.buffer.
* Note that this is unavailable in some browsers (such as Epic Browser due to its security restrictions)
*/
2016-08-26 00:18:47 +00:00
data: Uint8Array;
2016-06-17 11:46:47 +00:00
/**
* If dirty this BitmapData will be re-rendered.
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* If disableTextureUpload is true this BitmapData will never send its image data to the GPU when its dirty flag is true.
*/
2016-08-26 00:18:47 +00:00
disableTextureUpload: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The height of the BitmapData in pixels.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
imageData: ImageData;
2016-06-17 11:46:47 +00:00
/**
* The key of the BitmapData in the Cache, if stored there.
*/
2016-08-26 00:18:47 +00:00
key: string;
op: string;
2016-06-17 11:46:47 +00:00
/**
* An Uint32Array view into BitmapData.buffer.
*/
2016-08-26 00:18:47 +00:00
pixels: Uint32Array;
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The context property needed for smoothing this Canvas.
*/
2016-08-26 00:18:47 +00:00
smoothProperty: string;
2016-06-17 11:46:47 +00:00
/**
* The PIXI.Texture.
*/
2016-08-26 00:18:47 +00:00
texture: PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* The Frame this BitmapData uses for rendering.
*/
2016-08-26 00:18:47 +00:00
textureFrame: Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the BitmapData in pixels.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getTransform(translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(object: any): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addToWorld(x?: number, y?: number, anchorX?: number, anchorY?: number, scaleX?: number, scaleY?: number): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
alphaMask(source: any, mask?: any, sourceRect?: Phaser.Rectangle, maskRect?: Phaser.Rectangle): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'lighter'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendAdd(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'color'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendColor(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'color-burn'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendColorBurn(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'color-dodge'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendColorDodge(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'darken'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDarken(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'destination-atop'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDestinationAtop(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'destination-in'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDestinationIn(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'destination-out'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDestinationOut(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'destination-over'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDestinationOver(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'difference'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendDifference(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'exclusion'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendExclusion(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'hard-light'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendHardLight(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'hue'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendHue(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'lighten'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendLighten(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'luminosity'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendLuminosity(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'multiply'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendMultiply(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'overlay'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendOverlay(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Resets the blend mode (effectively sets it to 'source-over')
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendReset(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'saturation'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSaturation(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'screen'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendScreen(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'soft-light'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSoftLight(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'source-atop'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSourceAtop(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'source-in'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSourceIn(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'source-out'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSourceOut(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'source-over'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendSourceOver(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Sets the blend mode to 'xor'
* @return This BitmapData object for method chaining.
*/
2016-08-26 00:18:47 +00:00
blendXor(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
circle(x: number, y: number, radius: number, fillStyle?: string): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clear(x?: number, y?: number, width?: number, height?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Clears the BitmapData context using a clearRect.
*/
2016-08-26 00:18:47 +00:00
cls(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyRect(source: any, area: Phaser.Rectangle, x?: number, y?: number, alpha?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyTransform(source: any, blendMode?: string, roundPx?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Destroys this BitmapData and puts the canvas it was using back into the canvas pool for re-use.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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`.
2016-06-17 11:46:47 +00:00
*
* @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.
*/
2016-08-26 00:18:47 +00:00
draw(source: any, x?: number, y?: number, width?: number, height?: number, blendMode?: string, roundPx?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
drawFull(parent: any, blendMode?: string, roundPx?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
* You can trigger an update yourself by calling `stage.updateTransform()` before calling `drawGroup`.
2016-06-17 11:46:47 +00:00
*
* @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.
*/
2016-08-26 00:18:47 +00:00
drawGroup(group: Phaser.Group, blendMode?: string, roundPx?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
extract(destination: Phaser.BitmapData, r: number, g: number, b: number, a?: number, resize?: boolean, r2?: number, g2?: number, b2?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fill(r: number, g: number, b: number, a?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Creates a new Image element by converting this BitmapDatas canvas into a dataURL.
*
* The image is then stored in the image Cache using the key given.
*
* Finally a 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:
*
* `var texture = bitmapdata.generateTexture('ball');`
*
* Then you can either apply the texture to a sprite:
*
* `game.add.sprite(0, 0, texture);`
*
* or by using the string based key:
*
* `game.add.sprite(0, 0, 'ball');`
*
* @param key The key which will be used to store the image in the Cache.
* @return The newly generated texture.
*/
2016-08-26 00:18:47 +00:00
generateTexture(key: string): PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBounds(rect?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFirstPixel(direction: number): { r: number; g: number; b: number; x: number; y: number; };
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData.
* @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.
*/
2016-08-26 00:18:47 +00:00
getPixel(x: number, y: number, out?: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData.
* @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.
*/
2016-08-26 00:18:47 +00:00
getPixelRGB(x: number, y: number, out?: any, hsl?: boolean, hsv?: boolean): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData.
* @return A native color value integer (format: 0xAARRGGBB)
*/
2016-08-26 00:18:47 +00:00
getPixel32(x: number, y: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPixels(rect: Phaser.Rectangle): ImageData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTransform(translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
line(x1: number, y1: number, x2: number, y2: number, color?: string, width?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
load(source: any): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
move(x: number, y: number, wrap?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveH(distance: number, wrap?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveV(distance: number, wrap?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
processPixel(callback: (color: number, x: number, y: number) => void, callbackContext: any, x?: number, y?: Number, width?: number, height?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
processPixelRGB(callback: (color: ColorComponents, x: number, y: number) => void, callbackContext: any, x?: number, y?: Number, width?: number, height?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rect(x: number, y: number, width: number, height: number, fillStyle?: string): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
render(): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
replaceRGB(r1: number, g1: number, b1: number, a1: number, r2: number, g2: number, b2: number, a2: number, region?: Phaser.Rectangle): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resize(width: number, height: number): Phaser.BitmapData;
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setHSL(h?: number, s?: number, l?: number, region?: Phaser.Rectangle): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData.
* @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.
*/
2016-08-26 00:18:47 +00:00
setPixel(x: number, y: number, red: number, green: number, blue: number, immediate?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param y The y coordinate of the pixel to be set. Must lay within the dimensions of this BitmapData.
* @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.
*/
2016-08-26 00:18:47 +00:00
setPixel32(x: number, y: number, red: number, green: number, blue: number, alpha: number, immediate?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
shadow(color: string, blur?: number, x?: number, y?: number): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @param s The amount to shift the saturation by.
* @param l The amount to shift the lightness by.
* @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.
*/
2016-08-26 00:18:47 +00:00
shiftHSL(h?: number, s?: number, l?: number, region?: Phaser.Rectangle): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text(text: string, x?: number, y?: number, font?: string, color?: string, shadow?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
textureLine(line: Phaser.Line, key: string, repeat?: string): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(x?: number, y?: number, width?: number, height?: number): Phaser.BitmapData;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class BitmapText extends PIXI.DisplayObjectContainer {
2016-06-17 11:46:47 +00:00
/**
* 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'
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, font: string, text?: string, size?: number, align?: string);
2016-06-17 11:46:47 +00:00
/**
* Alignment for multi-line text ('left', 'center' or 'right'), does not affect single lines of text.
*/
2016-08-26 00:18:47 +00:00
align: string;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* The anchor value of this BitmapText.
*/
2016-08-26 00:18:47 +00:00
anchor: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* `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.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* The dirty state of this object.
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
*/
2016-08-26 00:18:47 +00:00
font: string;
2016-06-17 11:46:47 +00:00
/**
* The size of the font in pixels.
*/
2016-08-26 00:18:47 +00:00
fontSize: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
2016-08-26 00:18:47 +00:00
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* 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 the millisecond equivalent of `game.time.physicsElapsed` each frame.
* When it reaches zero it will call the `kill` method.
*
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
maxWidth: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
2016-08-26 00:18:47 +00:00
outOfBoundsKill: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* The text to be displayed by this BitmapText object.
*/
2016-08-26 00:18:47 +00:00
text: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The width in pixels of the overall text area, taking into consideration multi-line text.
*/
2016-08-26 00:18:47 +00:00
textWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The height in pixels of the overall text area, taking into consideration multi-line text.
*/
2016-08-26 00:18:47 +00:00
textHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The tint applied to the BitmapText. This is a hex value. Set to white to disable (0xFFFFFF)
*/
2016-08-26 00:18:47 +00:00
tint: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the x axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the y axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present
* and nulls its reference to `game`, freeing it up for garbage collection.
*
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
*
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
* @param destroyChildren Should every child of this object have its destroy method called as well? - Default: true
* @param destroyTexture Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
kill(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
* @return True if the BitmapText was rendered, otherwise false.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
purgeGlyphs(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.BitmapText;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
revive(health?: number): Phaser.BitmapText;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scanLine(data: any, scale: number, text: string): { width: number; text: string; end: boolean; chars: string[] };
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setText(text: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* Renders text and updates it when needed.
*/
2016-08-26 00:18:47 +00:00
updateText(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the transform of this object.
*/
2016-08-26 00:18:47 +00:00
updateTransform(): void;
}
class Bullet extends Phaser.Sprite {
constructor(game: Phaser.Game, x: number, y: number, key?: any, frame?: any);
kill(): Phaser.Bullet;
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Button extends Phaser.Image {
2016-06-17 11:46:47 +00:00
/**
* 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.
* @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.
*/
2016-08-26 00:18:47 +00:00
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);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
forceOut: boolean;
2016-06-17 11:46:47 +00:00
/**
* When true the the texture frame will not be automatically switched on up/down/over/out events.
*/
2016-08-26 00:18:47 +00:00
freezeFrames: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Sound to be played when this Buttons Down state is activated.
*/
2016-08-26 00:18:47 +00:00
onDownSound: Phaser.Sound | Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* The Sound Marker used in conjunction with the onDownSound.
*/
2016-08-26 00:18:47 +00:00
onDownSoundMarker: string;
2016-06-17 11:46:47 +00:00
/**
* The Signal (or event) dispatched when this Button is in an Down state.
*/
2016-08-26 00:18:47 +00:00
onInputDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The Signal (or event) dispatched when this Button is in an Out state.
*/
2016-08-26 00:18:47 +00:00
onInputOut: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The Signal (or event) dispatched when this Button is in an Over state.
*/
2016-08-26 00:18:47 +00:00
onInputOver: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The Signal (or event) dispatched when this Button is in an Up state.
*/
2016-08-26 00:18:47 +00:00
onInputUp: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The Sound to be played when this Buttons Out state is activated.
*/
2016-08-26 00:18:47 +00:00
onOutSound: Phaser.Sound | Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* The Sound Marker used in conjunction with the onOutSound.
*/
2016-08-26 00:18:47 +00:00
onOutSoundMarker: string;
2016-06-17 11:46:47 +00:00
/**
* The Sound to be played when this Buttons Over state is activated.
*/
2016-08-26 00:18:47 +00:00
onOverSound: Phaser.Sound | Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* The Sound Marker used in conjunction with the onOverSound.
*/
2016-08-26 00:18:47 +00:00
onOverSoundMarker: string;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
onOverMouseOnly: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Sound to be played when this Buttons Up state is activated.
*/
2016-08-26 00:18:47 +00:00
onUpSound: Phaser.Sound | Phaser.AudioSprite;
onUpSoundMaker: string;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
2016-06-17 11:46:47 +00:00
/**
* The Phaser Object Type.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* Clears all of the frames set on this Button.
*/
2016-08-26 00:18:47 +00:00
clearFrames(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setDownSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrames(overFrame?: string | number, outFrame?: string | number, downFrame?: string | number, upFrame?: string | number): void;
2016-06-17 11:46:47 +00:00
/**
* Internal function that handles input events.
*
* @param sprite The Button that the event occurred on.
* @param pointer The Pointer that activated the Button.
*/
2016-08-26 00:18:47 +00:00
onInputOverHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
* Internal function that handles input events.
*
* @param sprite The Button that the event occurred on.
* @param pointer The Pointer that activated the Button.
*/
2016-08-26 00:18:47 +00:00
onInputOutHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
* Internal function that handles input events.
*
* @param sprite The Button that the event occurred on.
* @param pointer The Pointer that activated the Button.
*/
2016-08-26 00:18:47 +00:00
onInputDownHandler(sprite: Phaser.Button, pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
* Internal function that handles input events.
*
* @param sprite The Button that the event occurred on.
* @param pointer The Pointer that activated the Button.
*/
2016-08-26 00:18:47 +00:00
onInputUpHandler(sprite: Phaser.Button, pointer: Phaser.Pointer, isOver: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Called when this Button is removed from the World.
*/
2016-08-26 00:18:47 +00:00
removedFromWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setOutSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setOverSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setUpSound(sound: Phaser.Sound | Phaser.AudioSprite, marker?: string): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class PointerMode {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static CURSOR: number;
2016-06-17 11:46:47 +00:00
/**
* A 'CONTACT' pointer has an *active cursor* that only tracks movement when actived; notably this is a touch-style input.
*/
2016-08-26 00:18:47 +00:00
static CONTACT: number;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Cache {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
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;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The default image used for a texture when no other is specified.
*/
2016-08-26 00:18:47 +00:00
static DEFAULT: PIXI.Texture;
2016-07-08 14:46:26 +00:00
/**
* The default image used for a texture when the source image is missing.
*/
2016-08-26 00:18:47 +00:00
static MISSING: PIXI.Texture;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* Automatically resolve resource URLs to absolute paths for use with the Cache.getURL method.
*/
2016-08-26 00:18:47 +00:00
autoResolveURL: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when the sound system is unlocked via a touch event on cellular devices.
*/
2016-08-26 00:18:47 +00:00
onSoundUnlock: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addBinary(key: string, binaryData: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addBitmapData(key: string, bitmapData: Phaser.BitmapData, frameData?: Phaser.FrameData): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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 Texture atlas frames data.
* @param atlasType The format of the texture atlas ( '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.
*/
2016-08-26 00:18:47 +00:00
addBitmapFont(key: string, texture: Phaser.RetroFont): void;
2016-06-17 11:46:47 +00:00
/**
* 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 Texture atlas frames data.
* @param atlasType The format of the texture atlas ( '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.
*/
2016-08-26 00:18:47 +00:00
addBitmapFont(key: string, url: string, data: any, atlasData: any, atlasType: string, xSpacing?: number, ySpacing?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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')`.
*/
2016-08-26 00:18:47 +00:00
addCanvas(key: string, canvas: HTMLCanvasElement, context?: CanvasRenderingContext2D): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addDefaultImage(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
addImage(key: string, url: string, data: any): HTMLImageElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addJSON(key: string, urL: string, data: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addMissingImage(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addPhysicsData(key: string, url: string, JSONData: any, format: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addRenderTexture(key: string, texture: RenderTexture): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addShader(key: string, url: string, data: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addSound(key: string, url: string, data: any, webAudio: boolean, audioTag: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addSpriteSheet(key: string, url: string, data: any, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addText(key: string, url: string, data: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addTextureAtlas(key: string, url: string, data: any, atlasData: any, format: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addTilemap(key: string, url: string, mapData: any, format: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addVideo(key: string, url: string, data: any, isBlob?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addXML(key: string, url: string, data: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkBinaryKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkBitmapDataKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkBitmapFontKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkCanvasKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkImageKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkJSONKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkKey(cache: number, key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkPhysicsKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkRenderTextureKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkShaderKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkSoundKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkTextKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkTextureKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkTilemapKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkURL(url: string): any;
checkUrl(url: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkXMLKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkVideoKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clearGLTextures(): void;
2016-06-17 11:46:47 +00:00
/**
* Add a new decoded sound.
*
* @param key The key of the asset within the cache.
* @param data Extra sound data.
*/
2016-08-26 00:18:47 +00:00
decodedSound(key: string, data: any): void;
2016-06-17 11:46:47 +00:00
/**
* Clears the cache. Removes every local cache object reference.
* If an object in the cache has a `destroy` method it will also be called.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBaseTexture(key: string, cache?: number): PIXI.BaseTexture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBinary(key: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBitmapData(key: string): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBitmapFont(key: string): Phaser.BitmapFont;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getCanvas(key: string): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrame(key: string, cache?: number): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameByIndex(key: string, index: number, cache?: number): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameByName(key: string, name: string, cache?: number): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameCount(key: string, cache?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameData(key: string, cache?: number): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getImage(key: string, full?: boolean): HTMLImageElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getItem(key: string, cache: number, method?: string, property?: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getJSON(key: string, clone?: boolean): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getKeys(cache: number): string[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPhysicsData(key: string, object?: string, fixtureKey?: string): any[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getRenderTexture(key: string): Phaser.CachedRenderTexture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getShader(key: string): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getSound(key: string): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getSoundData(key: string): any;
getSpriteSheetKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getText(key: string): string;
getTextKeys(): string[];
getTexture(key: string): Phaser.RenderTexture;
getTextureAtlasKey(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTextureFrame(key: string): Phaser.Frame;
getTilemap(key: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTilemapData(key: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getURL(url: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getXML(key: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getVideo(key: string): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hasFrameData(key: string, cache?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isSoundDecoded(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isSoundReady(key: string): boolean;
isSpriteSheet(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* Reload a Sound file from the server.
*
* @param key The key of the asset within the cache.
*/
2016-08-26 00:18:47 +00:00
reloadSound(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* Fires the onSoundUnlock event when the sound has completed reloading.
*
* @param key The key of the asset within the cache.
*/
2016-08-26 00:18:47 +00:00
reloadSoundComplete(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBinary(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBitmapData(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBitmapFont(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeCanvas(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* Removes an image from the cache.
*
* You can optionally elect to destroy it as well. This calls BaseTexture.destroy on it.
*
2016-07-08 14:46:26 +00:00
* Note that this only removes it from the Phaser Cache. If you still have references to the data elsewhere
2016-06-17 11:46:47 +00:00
* then it will persist in memory.
*
* @param key Key of the asset you want to remove.
2016-07-08 14:46:26 +00:00
* @param destroyBaseTexture Should the BaseTexture behind this image also be destroyed? - Default: true
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
removeImage(key: string, removeFromPixi?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeJSON(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removePhysics(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeRenderTexture(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeShader(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeSound(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeSpriteSheet(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeText(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeTextureAtlas(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeTilemap(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeXML(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeVideo(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
updateFrameData(key: string, frameData: any, cache?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the sound object in the cache.
*
* @param key The key of the asset within the cache.
*/
2016-08-26 00:18:47 +00:00
updateSound(key: string, property: string, value: Phaser.Sound): void;
}
interface CachedRenderTexture {
frame: Phaser.Frame;
texture: Phaser.RenderTexture;
}
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
class Camera {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, id: number, x: number, y: number, width: number, height: number);
static FOLLOW_LOCKON: number;
static FOLLOW_PLATFORMER: number;
static FOLLOW_TOPDOWN: number;
static FOLLOW_TOPDOWN_TIGHT: number;
static SHAKE_BOTH: number;
static SHAKE_HORIZONTAL: number;
static SHAKE_VERTICAL: number;
static ENABLE_FX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
atLimit: { x: boolean; y: boolean; };
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Moving inside this Rectangle will not cause the camera to move.
*/
2016-08-26 00:18:47 +00:00
deadzone: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* The display object to which all game objects are added. Set by World.boot.
*/
2016-08-26 00:18:47 +00:00
displayObject: PIXI.DisplayObject;
2016-06-17 11:46:47 +00:00
/**
* Reserved for future multiple camera set-ups.
*/
2016-08-26 00:18:47 +00:00
id: number;
2016-06-17 11:46:47 +00:00
/**
* The Graphics object used to handle camera fx such as fade and flash.
*/
2016-08-26 00:18:47 +00:00
fx: Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
lerp: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
roundPx: boolean;
2016-06-17 11:46:47 +00:00
/**
* The scale of the display object to which all game objects are added. Set by World.boot.
*/
2016-08-26 00:18:47 +00:00
scale: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The Cameras shake intensity. Gets or sets the cameras shake intensity.
*/
2016-08-26 00:18:47 +00:00
shakeIntensity: number;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched when the camera fade effect completes.
* When the fade effect completes you will be left with the screen black (or whatever
* color you faded to). In order to reset this call `Camera.resetFX`. This is called
* automatically when you change State.
*/
2016-08-26 00:18:47 +00:00
onFadeComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched when the camera flash effect completes.
*/
2016-08-26 00:18:47 +00:00
onFlashComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched when the camera shake effect completes.
*/
2016-08-26 00:18:47 +00:00
onShakeComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* If the camera is tracking a Sprite, this is a reference to it, otherwise null.
*/
2016-08-26 00:18:47 +00:00
target: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* The total number of Sprites with `autoCull` set to `true` that are visible by this Camera.
*/
2016-08-26 00:18:47 +00:00
totalInView: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
view: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Whether this camera is visible or not.
* Default: true
*/
2016-08-26 00:18:47 +00:00
visible: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game world.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.World;
2016-06-17 11:46:47 +00:00
/**
* The Cameras x coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras x position.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The Cameras y coordinate. This value is automatically clamped if it falls outside of the World bounds. Gets or sets the cameras y position.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Method called to ensure the camera doesn't venture outside of the game world.
* Called automatically by Camera.update.
*/
2016-08-26 00:18:47 +00:00
checkBounds(): void;
2016-06-17 11:46:47 +00:00
/**
* This creates a camera fade 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.
* @return True if the effect was started, otherwise false.
*/
2016-08-26 00:18:47 +00:00
fade(color?: number, duration?: number, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return True if the effect was started, otherwise false.
*/
2016-08-26 00:18:47 +00:00
flash(color?: number, duration?: number, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
focusOn(displayObject: PIXI.DisplayObject): void;
2016-06-17 11:46:47 +00:00
/**
* Move the camera focus on a location instantly.
*
* @param x X position.
* @param y Y position.
*/
2016-08-26 00:18:47 +00:00
focusOnXY(x: number, y: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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 "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
*/
2016-08-26 00:18:47 +00:00
follow(target: Phaser.Sprite, style?: number, lerpX?: number, lerpY?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resetFX(): void;
2016-06-17 11:46:47 +00:00
/**
* Update the Camera bounds to match the game world.
*/
2016-08-26 00:18:47 +00:00
setBoundsToWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setPosition(x: number, y: number): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the size of the view rectangle given the width and height in parameters.
*
* @param width The desired width.
* @param height The desired height.
*/
2016-08-26 00:18:47 +00:00
setSize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
shake(intensity?: number, duration?: number, force?: boolean, direction?: number, shakeBounds?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Sets the Camera follow target to null, stopping it from following an object if it's doing so.
*/
2016-08-26 00:18:47 +00:00
unfollow(): void;
2016-06-17 11:46:47 +00:00
/**
* The camera update loop. This is called automatically by the core game loop.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* The Canvas class handles everything related to creating the `canvas` DOM tag that Phaser will use,
* including styles, offset and aspect ratio.
*/
2016-08-26 00:18:47 +00:00
class Canvas {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static addToDOM(canvas: HTMLCanvasElement, parent: HTMLElement, overflowHidden?: boolean): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static create(parent: HTMLDivElement, width?: number, height?: number, id?: string, skipPool?: boolean): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getSmoothingEnabled(context: CanvasRenderingContext2D): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getSmoothingPrefix(context: CanvasRenderingContext2D): string;
2016-06-17 11:46:47 +00:00
/**
* Removes the given canvas element from the DOM.
*
* @param canvas The canvas to be removed from the DOM.
*/
2016-08-26 00:18:47 +00:00
static removeFromDOM(canvas: HTMLCanvasElement): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setBackgroundColor(canvas: HTMLCanvasElement, color: string): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setImageRenderingBicubic(canvas: HTMLCanvasElement): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* Sets the CSS image-rendering property on the given canvas to be 'crisp' (aka 'optimize contrast' on webkit).
* 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.
*/
2016-08-26 00:18:47 +00:00
static setImageRenderingCrisp(canvas: HTMLCanvasElement): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setSmoothingEnabled(context: CanvasRenderingContext2D, value: boolean): CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setTouchAction(canvas: HTMLCanvasElement, value: string): HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setTransform(context: CanvasRenderingContext2D, translateX: number, translateY: number, scaleX: number, scaleY: number, skewX: number, skewY: number): CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static setUserSelect(canvas: HTMLCanvasElement, value?: string): HTMLCanvasElement;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Circle {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(x?: number, y?: number, diameter?: number);
2016-06-17 11:46:47 +00:00
/**
* The area of this Circle.
*/
2016-08-26 00:18:47 +00:00
area: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* The largest distance between any two points on the circle. The same as the radius * 2. Gets or sets the diameter of the circle.
*/
2016-08-26 00:18:47 +00:00
diameter: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
empty: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
radius: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The x coordinate of the center of the circle.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the center of the circle.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static circumferencePoint(a: Phaser.Circle, angle: number, asDegrees: boolean, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static contains(a: Phaser.Circle, x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static equals(a: Phaser.Circle, b: Phaser.Circle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersects(a: Phaser.Circle, b: Phaser.Circle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersectsRectangle(c: Phaser.Circle, r: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* The circumference of the circle.
* @return The circumference of the circle.
*/
2016-08-26 00:18:47 +00:00
circumference(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
circumferencePoint(angle: number, asDegrees?: boolean, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output: Phaser.Circle): Phaser.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
contains(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyFrom(source: any): Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyTo(dest: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
distance(dest: any, round?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* Returns the framing rectangle of the circle as a Phaser.Rectangle object.
* @return The bounds of the Circle.
*/
2016-08-26 00:18:47 +00:00
getBounds(): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offset(dx: number, dy: number): Phaser.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetPoint(point: Phaser.Point): Phaser.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
random(out?: Phaser.Point): Phaser.Point;
scale(x: number, y?: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTo(x: number, y: number, diameter: number): Circle;
2016-06-17 11:46:47 +00:00
/**
* Returns a string representation of this object.
* @return a string representation of the instance.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
}
2016-06-17 11:46:47 +00:00
/**
* The Phaser.Color class is a set of static methods that assist in color manipulation and conversion.
*/
2016-08-26 00:18:47 +00:00
class Color {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static componentToHex(color: number): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static createColor(r?: number, g?: number, b?: number, a?: number, h?: number, s?: number, l?: number, v?: number): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static fromRGBA(rgba: number, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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)).
*/
2016-08-26 00:18:47 +00:00
static getAlpha(color: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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)).
*/
2016-08-26 00:18:47 +00:00
static getAlphaFloat(color: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static getBlue(color: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static getColor(red: number, green: number, blue: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static getColor32(alpha: number, red: number, green: number, blue: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static getGreen(color: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getRandomColor(min?: number, max?: number, alpha?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static getRed(color: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getRGB(color: number): RGBColor;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
static getWebRGB(color: number | RGBColor): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static hexToRGB(h: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static hexToColor(hex: string, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static HSLtoRGB(h: number, s: number, l: number, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static HSLColorWheel(s?: number, l?: number): ColorComponents[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static HSVtoRGB(h: number, s: number, v: number, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static HSVColorWheel(s?: number, v?: number): ColorComponents[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static hueToColor(p: number, q: number, t: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return The interpolated color value.
*/
2016-08-26 00:18:47 +00:00
static interpolateColor(color1: number, color2: number, steps: number, currentStep: number, alpha?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static interpolateColorWithRGB(color: number, r: number, g: number, b: number, steps: number, currentStep: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static interpolateRGB(r1: number, g1: number, b1: number, r2: number, g2: number, b2: number, steps: number, currentStep: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static packPixel(r: number, g: number, b: number, a: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static RGBtoHSL(r: number, g: number, b: number, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static RGBtoHSV(r: number, g: number, b: number, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
static RGBtoString(r: number, g: number, b: number, a?: number, prefix?: string): string;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static toRGBA(r: number, g: number, b: number, a: number): number;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static toABGR(r: number, g: number, b: number, a: number): number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static unpackPixel(rgba: number, out?: ColorComponents, hsl?: boolean, hsv?: boolean): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
static updateColor(out: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static valueToColor(value: string, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static webToColor(web: string, out?: ColorComponents): ColorComponents;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendNormal(a: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendLighten(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendDarken(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendMultiply(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendAverage(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendAdd(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendSubtract(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendDifference(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendNegation(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendScreen(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendExclusion(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendOverlay(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendSoftLight(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendHardLight(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendColorDodge(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendColorBurn(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendLinearDodge(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendLinearBurn(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendLinearLight(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendVividLight(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendPinLight(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendHardMix(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendReflect(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendGlow(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static blendPhoenix(a: number, b: number): number;
}
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;
}
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
class Create {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* A 16 color palette by [Arne](http://androidarts.com/palette/16pal.htm)
*/
2016-08-26 00:18:47 +00:00
static PALETTE_ARNE: number;
2016-06-17 11:46:47 +00:00
/**
* A 16 color JMP inspired palette.
*/
2016-08-26 00:18:47 +00:00
static PALETTE_JMP: number;
2016-06-17 11:46:47 +00:00
/**
* A 16 color CGA inspired palette.
*/
2016-08-26 00:18:47 +00:00
static PALETTE_CGA: number;
2016-06-17 11:46:47 +00:00
/**
* A 16 color C64 inspired palette.
*/
2016-08-26 00:18:47 +00:00
static PALETTE_C64: number;
2016-06-17 11:46:47 +00:00
/**
* A 16 color palette inspired by Japanese computers like the MSX.
*/
2016-08-26 00:18:47 +00:00
static PALETTE_JAPANESE_MACHINE: number;
2016-06-17 11:46:47 +00:00
/**
* The internal BitmapData Create uses to generate textures from.
*/
2016-08-26 00:18:47 +00:00
bmd: Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* The canvas the BitmapData uses.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* The 2d context of the canvas.
*/
2016-08-26 00:18:47 +00:00
ctx: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A range of 16 color palettes for use with sprite generation.
*/
2016-08-26 00:18:47 +00:00
palettes: any;
2016-06-17 11:46:47 +00:00
/**
* Creates a grid texture based on the given dimensions.
*
* @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)`.
* @return The newly generated texture.
*/
2016-08-26 00:18:47 +00:00
grid(key: string, width: number, height: number, cellWidth: number, cellHeight: number, color: string): PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* 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');`
*
* @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.
* @return The newly generated texture.
*/
2016-08-26 00:18:47 +00:00
texture(key: string, data: any, pixelWidth?: number, pixelHeight?: number, palette?: number): PIXI.Texture;
}
interface CursorKeys {
up: Phaser.Key;
down: Phaser.Key;
left: Phaser.Key;
right: Phaser.Key;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* 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
*/
2016-08-26 00:18:47 +00:00
class Device {
2016-06-17 11:46:47 +00:00
/**
* Same value as `littleEndian`.
*/
2016-08-26 00:18:47 +00:00
static LITTLE_ENDIAN: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static onInitialized: Phaser.Signal;
static checkFullScreenSupport(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static canPlayAudio(type: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static canPlayVideo(type: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* Check whether the console is open.
* Note that this only works in Firefox with Firebug and earlier versions of Chrome.
* It used to work in Chrome, but then they removed the ability: {@link http://src.chromium.org/viewvc/blink?view=revision&revision=151136}
*/
2016-08-26 00:18:47 +00:00
static isConsoleOpen(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static isAndroidStockBrowser(): string;
static whenReady: (callback: Function, context?: any) => void;
2016-06-17 11:46:47 +00:00
/**
* Is running on android?
*/
2016-08-26 00:18:47 +00:00
android: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Arora.
*/
2016-08-26 00:18:47 +00:00
arora: boolean;
2016-06-17 11:46:47 +00:00
/**
* Are Audio tags available?
*/
2016-08-26 00:18:47 +00:00
audioData: boolean;
cancelFullScreen: string;
2016-06-17 11:46:47 +00:00
/**
* Is canvas available?
*/
2016-08-26 00:18:47 +00:00
canvas: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Chrome.
*/
2016-08-26 00:18:47 +00:00
chrome: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on chromeOS?
*/
2016-08-26 00:18:47 +00:00
chromeOS: boolean;
2016-06-17 11:46:47 +00:00
/**
* If running in Chrome this will contain the major version number.
*/
2016-08-26 00:18:47 +00:00
chromeVersion: number;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under CocoonJS?
*/
2016-08-26 00:18:47 +00:00
cocoonJS: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is this game running with CocoonJS.App?
*/
2016-08-26 00:18:47 +00:00
cocoonJSApp: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under Apache Cordova?
*/
2016-08-26 00:18:47 +00:00
cordova: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under the Intel Crosswalk XDK?
*/
2016-08-26 00:18:47 +00:00
crosswalk: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is css3D available?
*/
2016-08-26 00:18:47 +00:00
css3D: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on a desktop?
*/
2016-08-26 00:18:47 +00:00
desktop: boolean;
2016-06-17 11:46:47 +00:00
/**
* The time the device became ready.
*/
2016-08-26 00:18:47 +00:00
deviceReadyAt: number;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under GitHub Electron?
*/
2016-08-26 00:18:47 +00:00
electron: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under Ejecta?
*/
2016-08-26 00:18:47 +00:00
ejecta: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Epiphany.
*/
2016-08-26 00:18:47 +00:00
epiphany: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is file available?
*/
2016-08-26 00:18:47 +00:00
file: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is fileSystem available?
*/
2016-08-26 00:18:47 +00:00
fileSystem: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Firefox.
*/
2016-08-26 00:18:47 +00:00
firefox: boolean;
2016-06-17 11:46:47 +00:00
/**
* If running in Firefox this will contain the major version number.
*/
2016-08-26 00:18:47 +00:00
firefoxVersion: number;
fullScreen: boolean;
fullScreenKeyboard: boolean;
2016-06-17 11:46:47 +00:00
/**
* Does the device support the getUserMedia API?
* Default: true
*/
2016-08-26 00:18:47 +00:00
getUserMedia: boolean;
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Can this device play h264 mp4 video files?
*/
2016-08-26 00:18:47 +00:00
h264Video: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play hls video files?
*/
2016-08-26 00:18:47 +00:00
hlsVideo: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Internet Explorer.
*/
2016-08-26 00:18:47 +00:00
ie: boolean;
2016-06-17 11:46:47 +00:00
/**
* If running in Internet Explorer this will contain the major version number. Beyond IE10 you should use Device.trident and Device.tridentVersion.
*/
2016-08-26 00:18:47 +00:00
ieVersion: number;
2016-06-17 11:46:47 +00:00
/**
* Is running on iOS?
*/
2016-08-26 00:18:47 +00:00
iOS: boolean;
2016-06-17 11:46:47 +00:00
/**
* If running in iOS this will contain the major version number.
*/
2016-08-26 00:18:47 +00:00
iOSVersion: number;
2016-06-17 11:46:47 +00:00
/**
* The time as which initialization has completed.
*/
2016-08-26 00:18:47 +00:00
initialized: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on iPad?
*/
2016-08-26 00:18:47 +00:00
iPad: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on iPhone?
*/
2016-08-26 00:18:47 +00:00
iPhone: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on iPhone4?
*/
2016-08-26 00:18:47 +00:00
iPhone4: boolean;
kindle: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on linux?
*/
2016-08-26 00:18:47 +00:00
linux: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the device big or little endian? (only detected if the browser supports TypedArrays)
*/
2016-08-26 00:18:47 +00:00
littleEndian: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is localStorage available?
*/
2016-08-26 00:18:47 +00:00
localStorage: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play m4a files? True if this device can play m4a files.
*/
2016-08-26 00:18:47 +00:00
m4a: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on macOS?
*/
2016-08-26 00:18:47 +00:00
macOS: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Midori.
*/
2016-08-26 00:18:47 +00:00
midori: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Mobile Safari.
*/
2016-08-26 00:18:47 +00:00
mobileSafari: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play mp3 files?
*/
2016-08-26 00:18:47 +00:00
mp3: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play h264 mp4 video files?
*/
2016-08-26 00:18:47 +00:00
mp4Video: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is mspointer available?
*/
2016-08-26 00:18:47 +00:00
mspointer: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under Node.js?
*/
2016-08-26 00:18:47 +00:00
node: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the game running under Node-Webkit?
*/
2016-08-26 00:18:47 +00:00
nodeWebkit: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play ogg files?
*/
2016-08-26 00:18:47 +00:00
ogg: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play ogg video files?
*/
2016-08-26 00:18:47 +00:00
oggVideo: number;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Opera.
*/
2016-08-26 00:18:47 +00:00
opera: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play opus files?
*/
2016-08-26 00:18:47 +00:00
opus: boolean;
2016-06-17 11:46:47 +00:00
/**
* PixelRatio of the host device?
*/
2016-08-26 00:18:47 +00:00
pixelRatio: number;
2016-06-17 11:46:47 +00:00
/**
* Is Pointer Lock available?
*/
2016-08-26 00:18:47 +00:00
pointerLock: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the browser running in strict mode (false) or quirks mode? (true)
*/
2016-08-26 00:18:47 +00:00
quirksMode: boolean;
requestFullScreen: string;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in Safari.
*/
2016-08-26 00:18:47 +00:00
safari: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running in the Silk browser (as used on the Amazon Kindle)
*/
2016-08-26 00:18:47 +00:00
silk: boolean;
2016-06-17 11:46:47 +00:00
/**
* Does the device context support 32bit pixel manipulation using array buffer views?
*/
2016-08-26 00:18:47 +00:00
support32bit: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is touch available?
*/
2016-08-26 00:18:47 +00:00
touch: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running a Trident version of Internet Explorer (IE11+)
*/
2016-08-26 00:18:47 +00:00
trident: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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}
*/
2016-08-26 00:18:47 +00:00
tridentVersion: number;
2016-06-17 11:46:47 +00:00
/**
* Does the browser support TypedArrays?
*/
2016-08-26 00:18:47 +00:00
typedArray: boolean;
2016-06-17 11:46:47 +00:00
/**
* Does the device support the Vibration API?
*/
2016-08-26 00:18:47 +00:00
vibration: boolean;
vita: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play wav files?
*/
2016-08-26 00:18:47 +00:00
wav: boolean;
2016-06-17 11:46:47 +00:00
/**
* Set to true if running as a WebApp, i.e. within a WebView
*/
2016-08-26 00:18:47 +00:00
webApp: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the WebAudio API available?
*/
2016-08-26 00:18:47 +00:00
webAudio: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is webGL available?
*/
2016-08-26 00:18:47 +00:00
webGL: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play webm files?
*/
2016-08-26 00:18:47 +00:00
webm: boolean;
2016-06-17 11:46:47 +00:00
/**
* Can this device play webm video files?
*/
2016-08-26 00:18:47 +00:00
webmVideo: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on windows?
*/
2016-08-26 00:18:47 +00:00
windows: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is running on a Windows Phone?
*/
2016-08-26 00:18:47 +00:00
windowsPhone: boolean;
2016-06-17 11:46:47 +00:00
/**
* The newest type of Wheel/Scroll event supported: 'wheel', 'mousewheel', 'DOMMouseScroll'
*/
2016-08-26 00:18:47 +00:00
wheelEvent: string;
2016-06-17 11:46:47 +00:00
/**
* Is worker available?
*/
2016-08-26 00:18:47 +00:00
worker: boolean;
wp9Video: boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class DeviceButton {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(parent: Phaser.Pointer | Phaser.SinglePad, butonCode: number);
2016-06-17 11:46:47 +00:00
/**
* The buttoncode of this button if a Gamepad, or the DOM button event value if a Pointer.
*/
2016-08-26 00:18:47 +00:00
buttonCode: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The "down" state of the button.
*/
2016-08-26 00:18:47 +00:00
isDown: boolean;
2016-06-17 11:46:47 +00:00
/**
* The "up" state of the button.
* Default: true
*/
2016-08-26 00:18:47 +00:00
isUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onFloat: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onUp: Phaser.Signal;
pad: Phaser.Gamepad;
2016-06-17 11:46:47 +00:00
/**
* Gamepad only.
* If a button is held down this holds down the number of times the button has 'repeated'.
*/
2016-08-26 00:18:47 +00:00
repeats: number;
2016-06-17 11:46:47 +00:00
/**
* The timestamp when the button was last pressed down.
*/
2016-08-26 00:18:47 +00:00
timeDown: number;
2016-06-17 11:46:47 +00:00
/**
* The timestamp when the button was last released.
*/
2016-08-26 00:18:47 +00:00
timeUp: number;
2016-06-17 11:46:47 +00:00
/**
* Button value. Mainly useful for checking analog buttons (like shoulder triggers) on Gamepads.
*/
2016-08-26 00:18:47 +00:00
value: number;
2016-06-17 11:46:47 +00:00
/**
* Destroys this DeviceButton, this disposes of the onDown, onUp and onFloat signals
* and clears the parent and game references.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justPressed(duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justReleased(duration?: number): boolean;
processButtonDown(value: number): void;
processButtonFloat(value: number): void;
processButtonUp(value: number): void;
2016-06-17 11:46:47 +00:00
/**
* Resets this DeviceButton, changing it to an isUp state and resetting the duration and repeats counters.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
}
module Easing {
var Default: Function;
var Power0: Function;
var Power1: Function;
var power2: Function;
var power3: Function;
var power4: Function;
2016-06-17 11:46:47 +00:00
/**
* Back easing.
*/
2016-08-26 00:18:47 +00:00
class Back {
2016-06-17 11:46:47 +00:00
/**
* Back ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Back ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Back ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Bounce easing.
*/
2016-08-26 00:18:47 +00:00
class Bounce {
2016-06-17 11:46:47 +00:00
/**
* Bounce ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Bounce ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Bounce ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Circular easing.
*/
2016-08-26 00:18:47 +00:00
class Circular {
2016-06-17 11:46:47 +00:00
/**
* Circular ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Circular ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Circular ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Cubic easing.
*/
2016-08-26 00:18:47 +00:00
class Cubic {
2016-06-17 11:46:47 +00:00
/**
* Cubic ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Cubic ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Cubic ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Elastic easing.
*/
2016-08-26 00:18:47 +00:00
class Elastic {
2016-06-17 11:46:47 +00:00
/**
* Elastic ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Elastic ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Elastic ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Exponential easing.
*/
2016-08-26 00:18:47 +00:00
class Exponential {
2016-06-17 11:46:47 +00:00
/**
* Exponential ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Exponential ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Exponential ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Linear easing.
*/
2016-08-26 00:18:47 +00:00
class Linear {
2016-06-17 11:46:47 +00:00
/**
* Linear Easing (no variation).
*
* @param k The value to be tweened.
* @return k.
*/
2016-08-26 00:18:47 +00:00
static None(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Quadratic easing.
*/
2016-08-26 00:18:47 +00:00
class Quadratic {
2016-06-17 11:46:47 +00:00
/**
* Ease-in.
*
* @param k The value to be tweened.
* @return k^2.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Ease-out.
*
* @param k The value to be tweened.
* @return k* (2-k).
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Quartic easing.
*/
2016-08-26 00:18:47 +00:00
class Quartic {
2016-06-17 11:46:47 +00:00
/**
* Quartic ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Quartic ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Quartic ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Quintic easing.
*/
2016-08-26 00:18:47 +00:00
class Quintic {
2016-06-17 11:46:47 +00:00
/**
* Quintic ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Quintic ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Quintic ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* Sinusoidal easing.
*/
2016-08-26 00:18:47 +00:00
class Sinusoidal {
2016-06-17 11:46:47 +00:00
/**
* Sinusoidal ease-in.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static In(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Sinusoidal ease-out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static Out(k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Sinusoidal ease-in/out.
*
* @param k The value to be tweened.
* @return The tweened value.
*/
2016-08-26 00:18:47 +00:00
static InOut(k: number): number;
}
}
2016-06-17 11:46:47 +00:00
/**
* Creates a Ellipse object. A curve on a plane surrounding two focal points.
*/
2016-08-26 00:18:47 +00:00
class Ellipse {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(x?: number, y?: number, width?: number, height?: number);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
empty: boolean;
2016-06-17 11:46:47 +00:00
/**
* The overall height of this ellipse.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Ellipse. The same as the X coordinate.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* The top of the Ellipse. The same as its y property. Gets or sets the top of the ellipse.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The overall width of this ellipse.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The X coordinate of the upper-left corner of the framing rectangle of this ellipse.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The Y coordinate of the upper-left corner of the framing rectangle of this ellipse.
*/
2016-08-26 00:18:47 +00:00
y: number;
static constains(a: Phaser.Ellipse, x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output: Phaser.Ellipse): Phaser.Ellipse;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
contains(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyFrom(source: any): Phaser.Ellipse;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyTo(dest: any): any;
2016-06-17 11:46:47 +00:00
/**
* Returns the framing rectangle of the ellipse as a Phaser.Rectangle object.
* @return The bounds of the Ellipse.
*/
2016-08-26 00:18:47 +00:00
getBounds(): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
random(out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTo(x: number, y: number, width: number, height: number): Phaser.Ellipse;
2016-06-17 11:46:47 +00:00
/**
* Returns a string representation of this object.
* @return A string representation of the instance.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
}
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* The Events component is a collection of events fired by the parent Game Object.
2016-06-17 11:46:47 +00:00
*
* 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 `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 Phaser.Signal class.
*
* The Input-related events will only be dispatched if the Sprite has had `inputEnabled` set to `true`
* and the Animation-related events only apply to game objects with animations like {@link Phaser.Sprite}.
*/
2016-08-26 00:18:47 +00:00
class Events {
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* The Events component is a collection of events fired by the parent Game Object.
2016-06-17 11:46:47 +00:00
*
* 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 `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 Phaser.Signal class.
*
* The Input-related events will only be dispatched if the Sprite has had `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.
*/
2016-08-26 00:18:47 +00:00
constructor(sprite: Phaser.Sprite);
2016-06-17 11:46:47 +00:00
/**
* The Sprite that owns these events.
*/
2016-08-26 00:18:47 +00:00
parent: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when this Game Object is added to a new Group.
* It is sent two arguments:
* {any} The Game Object that was added to the Group.
* {Phaser.Group} The Group it was added to.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onAddedToGroup: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object is removed from a Group.
* It is sent two arguments:
* {any} The Game Object that was removed from the Group.
* {Phaser.Group} The Group it was removed from.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onRemovedFromGroup: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This Signal is never used internally by Phaser and is now deprecated.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onRemovedFromWorld: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object is killed.
* This happens when `Sprite.kill()` is called.
* Please understand the difference between `kill` and `destroy` by looking at their respective methods.
* It is sent one argument:
* {any} The Game Object that was killed.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onKilled: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object is revived from a previously killed state.
* This happens when `Sprite.revive()` is called.
* It is sent one argument:
* {any} The Game Object that was revived.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onRevived: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object leaves the Phaser.World bounds.
* This signal is only if `Sprite.checkWorldBounds` is set to `true`.
* It is sent one argument:
* {any} The Game Object that left the World bounds.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onOutOfBounds: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object returns within the Phaser.World bounds, having previously been outside of them.
* This signal is only if `Sprite.checkWorldBounds` is set to `true`.
* It is sent one argument:
* {any} The Game Object that entered the World bounds.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onEnterBounds: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
* and receives an over event from a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onInputOver: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
* and receives an out event from a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onInputOut: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
* and receives a down event from a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onInputDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has `inputEnabled` set to `true`,
* and receives an up event from a 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?
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onInputUp: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched when the Game Object is destroyed.
* This happens when `Sprite.destroy()` is called, or `Group.destroy()` with `destroyChildren` set to true.
* It is sent one argument:
* {any} The Game Object that was destroyed.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onDestroy: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
* It is sent when a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onDragStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
* It is sent when a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onDragStop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has been `inputEnabled` and `enableDrag` has been set.
* It is sent when a 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onDragUpdate: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has the AnimationManager component,
* and an Animation has been played.
* You can also listen to `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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onAnimationStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has the AnimationManager component,
* and an Animation has been stopped (via `animation.stop()` and the `dispatchComplete` argument has been set.
* You can also listen to `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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onAnimationComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* This signal is dispatched if the Game Object has the AnimationManager component,
* and an Animation has looped playback.
* You can also listen to `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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
onAnimationLoop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* Removes all events.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
}
2016-06-17 11:46:47 +00:00
/**
* This is a base Filter class to use for any Phaser filter development.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
class Filter extends PIXI.AbstractFilter {
2016-06-17 11:46:47 +00:00
/**
* This is a base Filter class to use for any Phaser filter development.
*
* 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
* @param fragmentSrc The fragment shader code. Either an array, one element per line of code, or a string.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, uniforms: any, fragmentSrc: string | string[]);
2016-06-17 11:46:47 +00:00
/**
* Internal PIXI var.
* Default: true
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The height (resolution uniform)
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The fragment shader code.
*/
2016-08-26 00:18:47 +00:00
fragmentSrc: string | string[];
2016-06-17 11:46:47 +00:00
/**
* Internal PIXI var.
*/
2016-08-26 00:18:47 +00:00
padding: number;
2016-06-17 11:46:47 +00:00
/**
* The previous position of the pointer (we don't update the uniform if the same)
*/
2016-08-26 00:18:47 +00:00
prevPoint: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object, either Phaser.WEBGL_FILTER or Phaser.CANVAS_FILTER.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* Default uniform mappings. Compatible with ShaderToy and GLSLSandbox.
*/
2016-08-26 00:18:47 +00:00
uniforms: any;
2016-06-17 11:46:47 +00:00
/**
* The width (resolution uniform)
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addToWorld(x?: number, y?: number, width?: number, height?: number, anchorX?: number, anchorY?: number): Phaser.Image;
apply(frameBuffer: WebGLFramebuffer): void;
2016-06-17 11:46:47 +00:00
/**
* Clear down this Filter and null out references
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Should be over-ridden.
*/
2016-08-26 00:18:47 +00:00
init(...args: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* Set the resolution uniforms on the filter.
*
* @param width The width of the display.
* @param height The height of the display.
*/
2016-08-26 00:18:47 +00:00
setResolution(width: number, height: number): void;
syncUniforms(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the filter.
*
* @param pointer A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
*/
2016-08-26 00:18:47 +00:00
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;
}
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class FlexGrid {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(manager: Phaser.ScaleManager, width: number, height: number);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the ScaleManager.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* -
*/
2016-08-26 00:18:47 +00:00
positionCustom: Phaser.Point;
positionFluid: Phaser.Point;
positionFull: Phaser.Point;
positionNone: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The scale factor based on the game dimensions vs. the scaled dimensions.
*/
2016-08-26 00:18:47 +00:00
scaleCustom: Phaser.Point;
scaleFluid: Phaser.Point;
scaleFluidInversed: Phaser.Point;
scaleFull: Phaser.Point;
scaleNone: Phaser.Point;
ratioH: number;
ratioV: number;
multiplier: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createCustomLayer(width: number, height: number, children?: PIXI.DisplayObject[], addToWorld?: boolean): Phaser.FlexLayer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createFluidLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createFullLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createFixedLayer(children: PIXI.DisplayObject[]): Phaser.FlexLayer;
2016-06-17 11:46:47 +00:00
/**
* Call in the render function to output the bounds rects.
*/
2016-08-26 00:18:47 +00:00
debug(): void;
2016-06-17 11:46:47 +00:00
/**
* Fits a sprites width to the bounds.
*
* @param sprite The Sprite to fit.
*/
2016-08-26 00:18:47 +00:00
fitSprite(sprite: Phaser.Sprite): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onResize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates all internal vars such as the bounds and scale values.
*/
2016-08-26 00:18:47 +00:00
refresh(): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the layer children references
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the core game size. This resets the w/h parameters and bounds.
*
* @param width The new dimensions.
* @param height The new dimensions.
*/
2016-08-26 00:18:47 +00:00
setSize(width: number, height: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class FlexLayer extends Phaser.Group {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(manager: Phaser.ScaleManager, position: Phaser.Point, bounds: Phaser.Rectangle, scale: Phaser.Point);
2016-06-17 11:46:47 +00:00
/**
* A reference to the FlexGrid that owns this layer.
*/
2016-08-26 00:18:47 +00:00
grid: Phaser.FlexGrid;
2016-06-17 11:46:47 +00:00
/**
* A reference to the ScaleManager.
*/
2016-08-26 00:18:47 +00:00
manager: Phaser.ScaleManager;
bottomLeft: Phaser.Point;
bottomMiddle: Phaser.Point;
bottomRight: Phaser.Point;
bounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Should the FlexLayer remain through a State swap?
*/
2016-08-26 00:18:47 +00:00
persist: boolean;
position: Phaser.Point;
scale: Phaser.Point;
topLeft: Phaser.Point;
topMiddle: Phaser.Point;
topRight: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Debug.
*/
2016-08-26 00:18:47 +00:00
debug(): void;
2016-06-17 11:46:47 +00:00
/**
* Resize.
*/
2016-08-26 00:18:47 +00:00
resize(): void;
}
2016-06-17 11:46:47 +00:00
/**
* A Frame is a single frame of an animation and is part of a FrameData collection.
*/
2016-08-26 00:18:47 +00:00
class Frame {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(index: number, x: number, y: number, width: number, height: number, name: string);
2016-06-17 11:46:47 +00:00
/**
* The bottom of the frame (y + height).
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* Center X position within the image to cut from.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* Center Y position within the image to cut from.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* The distance from the top left to the bottom-right of this Frame.
*/
2016-08-26 00:18:47 +00:00
distance: number;
2016-06-17 11:46:47 +00:00
/**
* Height of the frame.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The index of this Frame within the FrameData set it is being added to.
*/
2016-08-26 00:18:47 +00:00
index: number;
2016-06-17 11:46:47 +00:00
/**
* Useful for Texture Atlas files (is set to the filename value).
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* The right of the Frame (x + width).
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* Rotated? (not yet implemented)
*/
2016-08-26 00:18:47 +00:00
rotated: boolean;
2016-06-17 11:46:47 +00:00
/**
* Either 'cw' or 'ccw', rotation is always 90 degrees.
* Default: 'cw'
*/
2016-08-26 00:18:47 +00:00
rotationDirection: string;
2016-06-17 11:46:47 +00:00
/**
* Height of the original sprite before it was trimmed.
*/
2016-08-26 00:18:47 +00:00
sourceSizeH: number;
2016-06-17 11:46:47 +00:00
/**
* Width of the original sprite before it was trimmed.
*/
2016-08-26 00:18:47 +00:00
sourceSizeW: number;
2016-06-17 11:46:47 +00:00
/**
* Height of the trimmed sprite.
*/
2016-08-26 00:18:47 +00:00
spriteSourceSizeH: number;
2016-06-17 11:46:47 +00:00
/**
* Width of the trimmed sprite.
*/
2016-08-26 00:18:47 +00:00
spriteSourceSizeW: number;
2016-06-17 11:46:47 +00:00
/**
* X position of the trimmed sprite inside original sprite.
*/
2016-08-26 00:18:47 +00:00
spriteSourceSizeX: number;
2016-06-17 11:46:47 +00:00
/**
* Y position of the trimmed sprite inside original sprite.
*/
2016-08-26 00:18:47 +00:00
spriteSourceSizeY: number;
2016-06-17 11:46:47 +00:00
/**
* Was it trimmed when packed?
*/
2016-08-26 00:18:47 +00:00
trimmed: boolean;
uuid: string;
2016-06-17 11:46:47 +00:00
/**
* Width of the frame.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* X position within the image to cut from.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* Y position within the image to cut from.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Clones this Frame into a new Phaser.Frame object and returns it.
* Note that all properties are cloned, including the name, index and UUID.
* @return An exact copy of this Frame object.
*/
2016-08-26 00:18:47 +00:00
clone(): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* Returns a Rectangle set to the dimensions of this Frame.
*
* @param out A rectangle to copy the frame dimensions to.
* @return A rectangle.
*/
2016-08-26 00:18:47 +00:00
getRect(out?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTrim(trimmed: boolean, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resize(width: number, height: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
*/
2016-08-26 00:18:47 +00:00
class FrameData {
2016-06-17 11:46:47 +00:00
/**
* The total number of frames in this FrameData set.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addFrame(frame: Frame): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkFrameName(name: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(): Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* Get a Frame by its numerical index.
*
* @param index The index of the frame you want to get.
* @return The frame, if found.
*/
2016-08-26 00:18:47 +00:00
getFrame(index: number): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* Get a Frame by its frame name.
*
* @param name The name of the frame you want to get.
* @return The frame, if found.
*/
2016-08-26 00:18:47 +00:00
getFrameByName(name: string): Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameIndexes(frames?: number[], useNumericIndex?: boolean, output?: number[]): number[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrameRange(start: number, end: number, output: Phaser.Frame[]): Phaser.Frame[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFrames(frames?: number[], useNumericIndex?: boolean, output?: Phaser.Frame[]): Phaser.Frame[];
}
interface IGameConfig {
enableDebug?: boolean;
width?: number;
height?: number;
renderer?: number;
parent?: any;
transparent?: boolean;
antialias?: boolean;
resolution?: number;
preserveDrawingBuffer?: boolean;
physicsConfig?: any;
seed?: string;
state?: Phaser.State;
forceSetTimeOut: boolean;
}
2016-06-17 11:46:47 +00:00
/**
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*/
2016-08-26 00:18:47 +00:00
class Game {
2016-06-17 11:46:47 +00:00
/**
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*
* @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.CANVAS or Phaser.HEADLESS (no rendering at all). - Default: Phaser.AUTO
* @param parent The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself. - 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.
*/
2016-08-26 00:18:47 +00:00
constructor(width?: number | string, height?: number | string, renderer?: number, parent?: any, state?: any, transparent?: boolean, antialias?: boolean, physicsConfig?: any);
2016-06-17 11:46:47 +00:00
/**
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*
* @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.CANVAS or Phaser.HEADLESS (no rendering at all). - Default: Phaser.AUTO
* @param parent The DOM element into which this games canvas will be injected. Either a DOM ID (string) or the element itself. - 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.
*/
2016-08-26 00:18:47 +00:00
constructor(config: IGameConfig);
2016-06-17 11:46:47 +00:00
/**
* Reference to the Phaser.GameObjectFactory.
*/
2016-08-26 00:18:47 +00:00
add: Phaser.GameObjectFactory;
2016-06-17 11:46:47 +00:00
/**
* Anti-alias graphics. By default scaled images are smoothed in Canvas and WebGL, set anti-alias to false to disable this globally.
* Default: true
*/
2016-08-26 00:18:47 +00:00
antialias: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the assets cache.
*/
2016-08-26 00:18:47 +00:00
cache: Phaser.Cache;
2016-06-17 11:46:47 +00:00
/**
* A handy reference to world.camera.
*/
2016-08-26 00:18:47 +00:00
camera: Phaser.Camera;
2016-06-17 11:46:47 +00:00
/**
* A handy reference to renderer.view, the canvas that the game is being rendered in to.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
* Default: true
*/
2016-08-26 00:18:47 +00:00
clearBeforeRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Phaser.Game configuration object.
*/
2016-08-26 00:18:47 +00:00
config: IGameConfig;
2016-06-17 11:46:47 +00:00
/**
* A handy reference to renderer.context (only set for CANVAS games, not WebGL)
*/
2016-08-26 00:18:47 +00:00
context: CanvasRenderingContext2D;
count: number;
2016-06-17 11:46:47 +00:00
/**
* The Asset Generator.
*/
2016-08-26 00:18:47 +00:00
create: Phaser.Create;
2016-06-17 11:46:47 +00:00
/**
* A set of useful debug utilities.
*/
2016-08-26 00:18:47 +00:00
debug: Phaser.Utils.Debug;
2016-06-17 11:46:47 +00:00
/**
* Contains device information and capabilities.
*/
2016-08-26 00:18:47 +00:00
device: Phaser.Device;
2016-06-17 11:46:47 +00:00
/**
* Should the game loop force a logic update, regardless of the delta timer? Set to true if you know you need this. You can toggle it on the fly.
*/
2016-08-26 00:18:47 +00:00
forceSingleUpdate: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fpsProblemNotifier: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The current Game Height in pixels.
*
* _Do not modify this property directly:_ use {@link Phaser.ScaleManager#setGameSize} - eg. `game.scale.setGameSize(width, height)` - instead.
* Default: 600
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* Phaser Game ID (for when Pixi supports multiple instances).
*/
2016-08-26 00:18:47 +00:00
id: number;
2016-06-17 11:46:47 +00:00
/**
* Reference to the input manager
*/
2016-08-26 00:18:47 +00:00
input: Phaser.Input;
2016-06-17 11:46:47 +00:00
/**
* Whether the game engine is booted, aka available.
*/
2016-08-26 00:18:47 +00:00
isBooted: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is game running or paused?
*/
2016-08-26 00:18:47 +00:00
isRunning: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the assets loader.
*/
2016-08-26 00:18:47 +00:00
load: Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
lockRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the GameObject Creator.
*/
2016-08-26 00:18:47 +00:00
make: Phaser.GameObjectCreator;
2016-06-17 11:46:47 +00:00
/**
* Reference to the math helper.
*/
2016-08-26 00:18:47 +00:00
math: Phaser.Math;
2016-06-17 11:46:47 +00:00
/**
* Reference to the network class.
*/
2016-08-26 00:18:47 +00:00
net: Phaser.Net;
2016-06-17 11:46:47 +00:00
/**
* This event is fired when the game no longer has focus (typically on page hide).
*/
2016-08-26 00:18:47 +00:00
onBlur: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is fired when the game has focus (typically on page show).
*/
2016-08-26 00:18:47 +00:00
onFocus: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is fired when the game pauses.
*/
2016-08-26 00:18:47 +00:00
onPause: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is fired when the game resumes from a paused state.
*/
2016-08-26 00:18:47 +00:00
onResume: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The Games DOM parent.
*/
2016-08-26 00:18:47 +00:00
parent: HTMLElement;
2016-06-17 11:46:47 +00:00
/**
* The Particle Manager.
*/
2016-08-26 00:18:47 +00:00
particles: Phaser.Particles;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* An internal property used by enableStep, but also useful to query from your own game objects.
*/
2016-08-26 00:18:47 +00:00
pendingStep: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the physics manager.
*/
2016-08-26 00:18:47 +00:00
physics: Phaser.Physics;
2016-06-17 11:46:47 +00:00
/**
* The Phaser.Physics.World configuration object.
*/
2016-08-26 00:18:47 +00:00
physicsConfig: any;
2016-06-17 11:46:47 +00:00
/**
* Reference to the plugin manager.
*/
2016-08-26 00:18:47 +00:00
plugins: PluginManager;
2016-06-17 11:46:47 +00:00
/**
* The value of the preserveDrawingBuffer flag affects whether or not the contents of the stencil buffer is retained after rendering.
*/
2016-08-26 00:18:47 +00:00
preserveDrawingBuffer: Boolean;
2016-06-17 11:46:47 +00:00
/**
* Automatically handles the core game loop via requestAnimationFrame or setTimeout
*/
2016-08-26 00:18:47 +00:00
raf: Phaser.RequestAnimationFrame;
2016-06-17 11:46:47 +00:00
/**
* The Pixi Renderer.
*/
2016-08-26 00:18:47 +00:00
renderer: PIXI.CanvasRenderer | PIXI.WebGLRenderer;
2016-06-17 11:46:47 +00:00
/**
* The Renderer this game will use. Either Phaser.AUTO, Phaser.CANVAS, Phaser.WEBGL, or Phaser.HEADLESS.
*/
2016-08-26 00:18:47 +00:00
renderType: number;
2016-06-17 11:46:47 +00:00
/**
* The resolution of your game. This value is read only, but can be changed at start time it via a game configuration object.
* Default: 1
*/
2016-08-26 00:18:47 +00:00
resolution: number;
2016-06-17 11:46:47 +00:00
/**
* Instance of repeatable random data generator helper.
*/
2016-08-26 00:18:47 +00:00
rnd: Phaser.RandomDataGenerator;
2016-06-17 11:46:47 +00:00
/**
* The game scale manager.
*/
2016-08-26 00:18:47 +00:00
scale: Phaser.ScaleManager;
scratch: Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* Reference to the sound manager.
*/
2016-08-26 00:18:47 +00:00
sound: Phaser.SoundManager;
2016-06-17 11:46:47 +00:00
/**
* Reference to the stage.
*/
2016-08-26 00:18:47 +00:00
stage: Phaser.Stage;
2016-06-17 11:46:47 +00:00
/**
* The StateManager.
*/
2016-08-26 00:18:47 +00:00
state: Phaser.StateManager;
2016-06-17 11:46:47 +00:00
/**
* When stepping is enabled this contains the current step cycle.
*/
2016-08-26 00:18:47 +00:00
stepCount: number;
2016-06-17 11:46:47 +00:00
/**
* Enable core loop stepping with Game.enableStep().
*/
2016-08-26 00:18:47 +00:00
stepping: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the core game clock.
*/
2016-08-26 00:18:47 +00:00
time: Phaser.Time;
2016-06-17 11:46:47 +00:00
/**
* Use a transparent canvas background or not.
*/
2016-08-26 00:18:47 +00:00
transparent: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the tween manager.
*/
2016-08-26 00:18:47 +00:00
tweens: Phaser.TweenManager;
2016-06-17 11:46:47 +00:00
/**
* The ID of the current/last logic update applied this render frame, starting from 0.
* The first update is `currentUpdateID === 0` and the last update is `currentUpdateID === updatesThisFrame.`
*/
2016-08-26 00:18:47 +00:00
currentUpdateID: number;
2016-06-17 11:46:47 +00:00
/**
* Number of logic updates expected to occur this render frame; will be 1 unless there are catch-ups required (and allowed).
*/
2016-08-26 00:18:47 +00:00
updatesThisFrame: number;
2016-06-17 11:46:47 +00:00
/**
* The current Game Width in pixels.
*
* _Do not modify this property directly:_ use {@link Phaser.ScaleManager#setGameSize} - eg. `game.scale.setGameSize(width, height)` - instead.
* Default: 800
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Reference to the world.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.World;
2016-06-17 11:46:47 +00:00
/**
* Initialize engine sub modules and start the game.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Disables core game loop stepping.
*/
2016-08-26 00:18:47 +00:00
disableStep(): void;
2016-06-17 11:46:47 +00:00
/**
* 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!
*/
2016-08-26 00:18:47 +00:00
enableStep(): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Stage visibility handler.
*
* @param event The DOM event that caused the game to pause, if any.
*/
2016-08-26 00:18:47 +00:00
focusGain(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Stage visibility handler.
*
* @param event The DOM event that caused the game to pause, if any.
*/
2016-08-26 00:18:47 +00:00
focusLoss(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Stage visibility handler.
*
* @param event The DOM event that caused the game to pause, if any.
*/
2016-08-26 00:18:47 +00:00
gamePaused(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Stage visibility handler.
*
* @param event The DOM event that caused the game to pause, if any.
*/
2016-08-26 00:18:47 +00:00
gameResumed(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Parses a Game configuration object.
*/
2016-08-26 00:18:47 +00:00
parseConfig(config: any): void;
removeFromDOM(canvas: HTMLCanvasElement): void;
2016-06-17 11:46:47 +00:00
/**
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
*/
2016-08-26 00:18:47 +00:00
setUpRenderer(): void;
2016-06-17 11:46:47 +00:00
/**
* Displays a Phaser version debug header in the console.
*/
2016-08-26 00:18:47 +00:00
showDebugHeader(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
step(): void;
2016-06-17 11:46:47 +00:00
/**
* The core game loop.
*
* @param time The current time as provided by RequestAnimationFrame.
*/
2016-08-26 00:18:47 +00:00
update(time: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates all logic subsystems in Phaser. Called automatically by Game.update.
*
* @param timeStep The current timeStep value as determined by Game.update.
*/
2016-08-26 00:18:47 +00:00
updateLogic(timeStep: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*
* @param elapsedTime The time elapsed since the last update.
*/
2016-08-26 00:18:47 +00:00
updateRender(timeStep: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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`}.
*/
2016-08-26 00:18:47 +00:00
class GameObjectCreator {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game world.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.World;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
audio(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
audioSprite(key: string): Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bitmapData(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bitmapText(x: number, y: number, font: string, text?: string, size?: number, align?: string): Phaser.BitmapText;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
button(x?: number, y?: number, key?: string, callback?: Function, callbackContext?: any, overFrame?: any, outFrame?: any, downFrame?: any, upFrame?: any): Phaser.Button;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
emitter(x?: number, y?: number, maxParticles?: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
filter(filter: any, ...args: any[]): Phaser.Filter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
graphics(x?: number, y?: number): Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @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.
*/
2016-08-26 00:18:47 +00:00
group(parent?: any, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number): Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
image(x: number, y: number, key?: any, frame?: any): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderTexture(width?: number, height?: number, key?: any, addToCache?: boolean): Phaser.RenderTexture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
retroFont(font: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number): Phaser.RetroFont;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rope(x: number, y: number, key: any, frame?: any, points?: Phaser.Point[]): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sound(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sprite(x: number, y: number, key?: any, frame?: any): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
spriteBatch(parent: any, name?: String, addToStage?: boolean): Phaser.SpriteBatch;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text(x: number, y: number, text?: string, style?: any): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
tilemap(key: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): Phaser.Tilemap;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tileSprite(x: number, y: number, width: number, height: number, key: any, frame: any): Phaser.TileSprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tween(obj: any): Phaser.Tween;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class GameObjectFactory {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game world.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.World;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
audio(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
audioSprite(key: string): Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bitmapData(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bitmapText(x: number, y: number, font: string, text?: string, size?: number, group?: Phaser.Group): Phaser.BitmapText;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
button(x?: number, y?: number, key?: string, callback?: Function, callbackContext?: any, overFrame?: any, outFrame?: any, downFrame?: any, upFrame?: any, group?: Phaser.Group): Phaser.Button;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
emitter(x?: number, y?: number, maxParticles?: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
existing(object: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
filter(filter: string, ...args: any[]): Phaser.Filter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
graphics(x: number, y: number, group?: Phaser.Group): Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
group(parent?: any, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number): Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
image(x: number, y: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
physicsGroup(physicsBodyType?: number, parent?: any, name?: string, addToStage?: boolean): Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
plugin(plugin: Phaser.Plugin, ...parameter: any[]): Phaser.Plugin;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderTexture(width?: number, height?: number, key?: string, addToCache?: boolean): Phaser.RenderTexture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
retroFont(font: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number): Phaser.RetroFont;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rope(x: number, y: number, key: any, frame?: any, points?: Phaser.Point[]): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sound(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sprite(x: number, y: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
spriteBatch(parent: any, name?: string, addToStage?: boolean): Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text(x: number, y: number, text: string, style: any, group?: Phaser.Group): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tilemap(key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): Phaser.Tilemap;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tileSprite(x: number, y: number, width: number, height: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.TileSprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tween(obj: any): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return A Weapon instance.
*/
2016-08-26 00:18:47 +00:00
weapon(quantity?: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Weapon;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
video(key?: string, url?: string): Phaser.Video;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Gamepad {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* If the gamepad input is active or not - if not active it should not be updated from Input.js
*/
2016-08-26 00:18:47 +00:00
active: boolean;
2016-06-17 11:46:47 +00:00
/**
* The context under which the callbacks are run.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* Gamepad input will only be processed if enabled.
* Default: true
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
onAxisCallBack: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time any gamepad is connected
*/
2016-08-26 00:18:47 +00:00
onConnectCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time any gamepad is disconnected
*/
2016-08-26 00:18:47 +00:00
onDisconnectCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time any gamepad button is pressed down.
*/
2016-08-26 00:18:47 +00:00
onDownCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1.
*/
2016-08-26 00:18:47 +00:00
onFloatCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time any gamepad button is released.
*/
2016-08-26 00:18:47 +00:00
onUpCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* Gamepad #1
*/
2016-08-26 00:18:47 +00:00
pad1: Phaser.SinglePad;
2016-06-17 11:46:47 +00:00
/**
* Gamepad #2
*/
2016-08-26 00:18:47 +00:00
pad2: Phaser.SinglePad;
2016-06-17 11:46:47 +00:00
/**
* Gamepad #3
*/
2016-08-26 00:18:47 +00:00
pad3: Phaser.SinglePad;
2016-06-17 11:46:47 +00:00
/**
* Gamepad #4
*/
2016-08-26 00:18:47 +00:00
pad4: Phaser.SinglePad;
2016-06-17 11:46:47 +00:00
/**
* How many live gamepads are currently connected.
*/
2016-08-26 00:18:47 +00:00
padsConnected: number;
2016-06-17 11:46:47 +00:00
/**
* Whether or not gamepads are supported in current browser.
*/
2016-08-26 00:18:47 +00:00
supported: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
addCallbacks(context: any, callbacks: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isDown(buttonCode: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justPressed(buttonCode: number, duration?: number): boolean;
justReleased(buttonCode: number, duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Reset all buttons/axes of all gamepads
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the deadZone variable for all four gamepads
*/
2016-08-26 00:18:47 +00:00
setDeadZones(value: any): void;
2016-06-17 11:46:47 +00:00
/**
* Starts the Gamepad event handling.
* This MUST be called manually before Phaser will start polling the Gamepad API.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* Stops the Gamepad event handling.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* Main gamepad update loop. Should not be called manually.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* 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:
*
* ```
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
class Graphics extends PIXI.Graphics {
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* 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:
*
* ```
* 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.
2016-06-17 11:46:47 +00:00
*
* @param game Current game instance.
* @param x X position of the new graphics object.
* @param y Y position of the new graphics object.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x?: number, y?: number);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* `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.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The height of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
2016-08-26 00:18:47 +00:00
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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 the millisecond equivalent of `game.time.physicsElapsed` each frame.
* When it reaches zero it will call the `kill` method.
*
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
2016-08-26 00:18:47 +00:00
outOfBoundsKill: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Destroy this Graphics instance.
*
* @param destroyChildren Should every child of this object have its destroy method called? - Default: true
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
drawTriangle(points: Phaser.Point[], cull?: boolean): void;
drawTriangles(vertices: Phaser.Point[] | number[], indices?: number[], cull?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
kill(): Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* Automatically called by World
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
revive(health?: number): Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Group extends PIXI.DisplayObjectContainer {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, parent?: PIXI.DisplayObjectContainer, name?: string, addToStage?: boolean, enableBody?: boolean, physicsBodyType?: number);
2016-06-17 11:46:47 +00:00
/**
* A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg.
*/
2016-08-26 00:18:47 +00:00
static RETURN_CHILD: number;
2016-06-17 11:46:47 +00:00
/**
* A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg.
*/
2016-08-26 00:18:47 +00:00
static RETURN_NONE: number;
2016-06-17 11:46:47 +00:00
/**
* A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg.
*/
2016-08-26 00:18:47 +00:00
static RETURN_TOTAL: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* A returnType value, as specified in {@link Phaser.Group#iterate iterate} eg.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static RETURN_ALL: number;
2016-06-17 11:46:47 +00:00
/**
* A sort ordering value, as specified in {@link Phaser.Group#sort sort} eg.
*/
2016-08-26 00:18:47 +00:00
static SORT_ASCENDING: number;
2016-07-01 15:57:13 +00:00
2016-08-26 00:18:47 +00:00
/**
* A sort ordering value, as specified in {@link Phaser.Group#sort sort} eg.
*/
static SORT_DESCENDING: number;
2016-06-17 11:46:47 +00:00
/**
* The alpha value of the group container.
*/
2016-08-26 00:18:47 +00:00
alpha: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The bottom coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The center x coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-07-08 14:46:26 +00:00
/**
* The center y coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* The type of objects that will be created when using {@link Phaser.Group#create create} or {@link Phaser.Group#createMultiple createMultiple}.
*
* Any object may be used but it should extend either Sprite or Image and accept the same constructor arguments:
* when a new object is created it is passed the following parameters to its constructor: `(game, x, y, key, frame)`.
* Default: {@link Phaser.Sprite}
*/
2016-08-26 00:18:47 +00:00
classType: any;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
cursor: any;
2016-06-17 11:46:47 +00:00
/**
* The current index of the Group cursor. Advance it with Group.next.
*/
2016-08-26 00:18:47 +00:00
cursorIndex: number;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
enableBody: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enableBodyDebug: boolean;
2016-06-17 11:46:47 +00:00
/**
* If exists is true the group is updated, otherwise it is skipped.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
hash: PIXI.DisplayObject[];
2016-06-17 11:46:47 +00:00
/**
* A group with `ignoreDestroy` set to `true` ignores all calls to its `destroy` method.
*/
2016-08-26 00:18:47 +00:00
ignoreDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inputEnableChildren: boolean;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The left coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* Total number of children in this group, regardless of exists/alive status.
*/
2016-08-26 00:18:47 +00:00
length: number;
2016-06-17 11:46:47 +00:00
/**
* A name for this group. Not used internally but useful for debugging.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onChildInputDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onChildInputUp: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onChildInputOver: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onChildInputOut: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched when the group is destroyed.
*/
2016-08-26 00:18:47 +00:00
onDestroy: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
physicsBodyType: number;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
physicsSortDirection: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The right coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* The angle of rotation of the group container, in radians.
*
* This will adjust the group container itself by modifying its rotation.
* This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
*/
2016-08-26 00:18:47 +00:00
rotation: number;
scale: Phaser.Point;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The top coordinate of this Group.
*
* It is derived by calling `getBounds`, calculating the Groups dimensions based on its
* visible children.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* Total number of existing children in the group.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* Internal Phaser Type value.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The visible state of the group. Non-visible Groups and all of their children are not rendered.
*/
2016-08-26 00:18:47 +00:00
visible: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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#addAt addAt} to control where a child is added. 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.
*/
2016-08-26 00:18:47 +00:00
add(child: any, silent?: boolean, index?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addAt(child: any, index: number, silent?: boolean): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addMultiple(children: any[], silent?: boolean): any[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addToHash(child: PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
2016-08-26 00:18:47 +00:00
* The grid dimensions are determined by the first four arguments. The `width` and `height` arguments
2016-06-17 11:46:47 +00:00
* 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.
*
2016-08-26 00:18:47 +00:00
* You can choose to set _either_ the `width` or `height` value to -1. Doing so tells the method
2016-06-17 11:46:47 +00:00
* 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)`
*
2016-08-26 00:18:47 +00:00
* ... will align the children so that there are 8 children vertically (the second argument),
2016-06-17 11:46:47 +00:00
* 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.
*
2016-08-26 00:18:47 +00:00
* @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.
2016-06-17 11:46:47 +00:00
* @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.
2016-08-26 00:18:47 +00:00
* @return True if the Group children were aligned, otherwise false.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
align(width: number, height: number, cellWidth: number, cellHeight: number, position?: number, offset?: number): boolean;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* Aligns this Group 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 Groups within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Group 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`.
*
* Groups are placed in such a way that their _bounds_ align with the
* container, taking into consideration rotation and scale of its children.
* This allows you to neatly align Groups, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Group. For example:
*
* `group.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `group` 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 Group 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 Group.
*/
2016-08-26 00:18:47 +00:00
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;
2016-07-08 14:46:26 +00:00
/**
* Aligns this Group 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 Groups within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Group 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`.
*
* Groups are placed in such a way that their _bounds_ align with the
* parent, taking into consideration rotation and scale of the children.
* This allows you to neatly align Groups, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Group. For example:
*
* `group.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `group` 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 Group 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 Group.
*/
2016-08-26 00:18:47 +00:00
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;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bringToTop(child: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
callAll(method: string, context: any, ...parameters: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
callAllExists(callback: string, existsValue: boolean, ...parameters: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
callbackFromArray(child: any, callback: Function, length: number): void;
2016-06-17 11:46:47 +00:00
/**
* Quickly check 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 set. 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 If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
*/
2016-08-26 00:18:47 +00:00
checkAll(key: string[], value: any, checkAlive?: boolean, checkVisible?: boolean, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks a property for the given value on the child.
*
* @param child The child to check 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 checked.
* @param force If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
* @return True if the property was was equal to value, false if not.
*/
2016-08-26 00:18:47 +00:00
checkProperty(child: any, key: string[], value: any, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Get the number of dead children in this group.
* @return The number of children flagged as dead.
*/
2016-08-26 00:18:47 +00:00
countDead(): number;
2016-06-17 11:46:47 +00:00
/**
* Get the number of living children in this group.
* @return The number of children flagged as alive.
*/
2016-08-26 00:18:47 +00:00
countLiving(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
create(x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, exists?: boolean, index?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return An array containing all of the Sprites that were created.
*/
2016-08-26 00:18:47 +00:00
createMultiple(quantity: number, key: string | string[], frame?: any | any[], exists?: boolean): any[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
customSort(sortHandler: Function, context?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean, soft?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
divideAll(property: string, amount: number, checkAlive?: boolean, checkVisible?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
forEach(callback: Function, callbackContext: any, checkExists?: boolean, ...args: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
forEachAlive(callback: Function, callbackContext: any, ...args: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
forEachDead(callback: Function, callbackContext: any, ...args: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
forEachExists(callback: Function, callbackContext: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
filter(predicate: Function, checkExists?: boolean): ArraySet;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getAt(index: number): PIXI.DisplayObject | number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBottom(): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getByName(name: string): any;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Get the closest child to given Object, with optional callback to filter children.
2016-06-17 11:46:47 +00:00
*
* 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.
*
2016-07-01 15:57:13 +00:00
* 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`.
*
2016-06-17 11:46:47 +00:00
* @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.
2016-07-01 15:57:13 +00:00
* @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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
getClosestTo(object: any, callback?: Function, callbackContext?: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFirstAlive(createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFirstDead(createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getFirstExists(exists: boolean, createIfNull?: boolean, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Get the child furthest away from the given Object, with optional callback to filter children.
2016-06-17 11:46:47 +00:00
*
* 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.
*
2016-07-01 15:57:13 +00:00
* 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`.
*
2016-06-17 11:46:47 +00:00
* @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.
2016-07-01 15:57:13 +00:00
* @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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
getFurthestFrom(object: any, callback?: Function, callbackContext?: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getIndex(child: any): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a random child from the group.
*
2016-08-26 00:18:47 +00:00
* @param startIndex Offset from the front of the group (lowest child).
2016-06-17 11:46:47 +00:00
* @param length Restriction on the number of values you want to randomly select from. - Default: (to top)
* @return A random child of this Group.
*/
2016-08-26 00:18:47 +00:00
getRandom(startIndex?: number, length?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTop(): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hasProperty(child: any, key: string[]): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
iterate(key: string, value: any, returnType: number, callback?: Function, callbackContext?: any, ...args: any[]): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveAll(group: Phaser.Group, silent?: boolean): Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveDown(child: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveUp(child: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
multiplyAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
next(): void;
2016-06-17 11:46:47 +00:00
/**
* The core postUpdate - as called by World.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* The core preUpdate - as called by World.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
previous(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
remove(child: any, destroy?: boolean, silent?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeAll(destroy?: boolean, silent?: boolean, destroyTexture?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBetween(startIndex: number, endIndex?: number, destroy?: boolean, silent?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeFromHash(child: PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
replace(oldChild: any, newChild: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
resetChild(child: any, x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resetCursor(index?: number): any;
2016-06-17 11:46:47 +00:00
/**
* Reverses all children in this group.
*
* This operation applies only to immediate children and does not propagate to subgroups.
*/
2016-08-26 00:18:47 +00:00
reverse(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sendToBack(child: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
set(child: any, key: string[], value: any, operation?: number, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setAll(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean, operation?: number, force?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setAllChildren(key: string, value: any, checkAlive?: boolean, checkVisible?: boolean, operation?: number, force?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setProperty(child: any, key: string[], value: any, operation?: number, force?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
sort(key?: string, order?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
subAll(property: string, amount: number, checkAlive: boolean, checkVisible: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
swap(child1: any, child2: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* The core update - as called by World.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateZ(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
xy(index: number, x: number, y: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Image extends PIXI.Sprite {
2016-06-17 11:46:47 +00:00
/**
* 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 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.
* @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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number);
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* The anchor sets the origin point of the texture.
* The default is 0,0 this means the texture's origin is the top left
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right corner
*/
2016-08-26 00:18:47 +00:00
anchor: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The center x coordinate of the Game Object.
* This is the same as `(x - offsetX) + (width / 2)`.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* The center y coordinate of the Game Object.
* This is the same as `(y - offsetY) + (height / 2)`.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cropRect: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
2016-08-26 00:18:47 +00:00
customRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
deltaX: number;
deltaY: number;
deltaZ: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frame: string | number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frameName: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* 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 the millisecond equivalent of `game.time.physicsElapsed` each frame.
* When it reaches zero it will call the `kill` method.
*
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
scale: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Brings this Game Object to the top of its parents display list.
* Visually this means it will render over the top of any old child in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
bringToTop(): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
crop(rect: Phaser.Rectangle, copy?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present
* and nulls its reference to `game`, freeing it up for garbage collection.
*
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
*
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
* @param destroyChildren Should every child of this object have its destroy method called as well? - Default: true
* @param destroyTexture Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
kill(): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveDown(): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* Moves this Game Object up one place in its parents 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.
*/
2016-08-26 00:18:47 +00:00
moveUp(): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* Internal method called by the World postUpdate cycle.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
2016-08-26 00:18:47 +00:00
resetFrame(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
revive(health?: number): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* Sends this Game Object to the bottom of its parents display list.
* Visually this means it will render below all other children in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
sendToBack(): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrame(frame: Phaser.Frame): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateCrop(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class ImageCollection {
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: any);
2016-06-17 11:46:47 +00:00
/**
* The name of the Image Collection.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* The Tiled firstgid value.
* This is the starting index of the first image index this Image Collection contains.
*/
2016-08-26 00:18:47 +00:00
firstgid: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the widest image (in pixels).
*/
2016-08-26 00:18:47 +00:00
imageWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the tallest image (in pixels).
*/
2016-08-26 00:18:47 +00:00
imageHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The margin around the images in the collection (in pixels).
* Use `setSpacing` to change.
*/
2016-08-26 00:18:47 +00:00
imageMargin: number;
2016-06-17 11:46:47 +00:00
/**
* The spacing between each image in the collection (in pixels).
* Use `setSpacing` to change.
*/
2016-08-26 00:18:47 +00:00
imageSpacing: number;
2016-06-17 11:46:47 +00:00
/**
* Image Collection-specific properties that are typically defined in the Tiled editor.
*/
2016-08-26 00:18:47 +00:00
properties: any;
2016-06-17 11:46:47 +00:00
/**
* The cached images that are a part of this collection.
*/
2016-08-26 00:18:47 +00:00
images: any[];
2016-06-17 11:46:47 +00:00
/**
* The total number of images in the image collection.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addImage(gid: number, image: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
containsImageIndex(imageIndex: number): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Input {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* The maximum number of pointers that can be added. This excludes the mouse pointer.
*/
2016-08-26 00:18:47 +00:00
static MAX_POINTERS: number;
static MOUSE_OVERRIDES_TOUCH: number;
static MOUSE_TOUCH_COMBINE: number;
static TOUCH_OVERRIDES_MOUSE: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
activePointer: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
circle: Phaser.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click.
* Default: 300
*/
2016-08-26 00:18:47 +00:00
doubleTapRate: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The Gamepad Input manager.
*/
2016-08-26 00:18:47 +00:00
gamepad: Phaser.Gamepad;
2016-06-17 11:46:47 +00:00
/**
* The canvas to which single pixels are drawn in order to perform pixel-perfect hit detection.
*/
2016-08-26 00:18:47 +00:00
hitCanvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* The context of the pixel perfect hit canvas.
*/
2016-08-26 00:18:47 +00:00
hitContext: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event.
* Default: 2000
*/
2016-08-26 00:18:47 +00:00
holdRate: number;
2016-06-17 11:46:47 +00:00
/**
* A list of interactive objects. The InputHandler components add and remove themselves from this list.
*/
2016-08-26 00:18:47 +00:00
interactiveItems: Phaser.ArraySet;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds below which the Pointer is considered justPressed.
* Default: 200
*/
2016-08-26 00:18:47 +00:00
justPressedRate: number;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds below which the Pointer is considered justReleased .
* Default: 200
*/
2016-08-26 00:18:47 +00:00
justReleasedRate: number;
2016-06-17 11:46:47 +00:00
/**
* The Keyboard Input manager.
*/
2016-08-26 00:18:47 +00:00
keyboard: Phaser.Keyboard;
2016-06-17 11:46:47 +00:00
/**
* 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. For lots of games it's useful to set this to 1.
* Default: -1 (Limited by total pointers.)
*/
2016-08-26 00:18:47 +00:00
maxPointers: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
minPriorityID: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
mouse: Phaser.Mouse;
2016-06-17 11:46:47 +00:00
/**
* The mouse has its own unique Phaser.Pointer object which you can use if making a desktop specific game.
*/
2016-08-26 00:18:47 +00:00
mousePointer: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
moveCallbacks: (pointer: Phaser.Pointer, x: number, y: number) => void[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
mspointer: Phaser.MSPointer;
2016-06-17 11:46:47 +00:00
/**
* Controls the expected behavior when using a mouse and touch together on a multi-input device.
*/
2016-08-26 00:18:47 +00:00
multiInputOverride: number;
2016-06-17 11:46:47 +00:00
/**
* A Signal that is dispatched each time a pointer is pressed down.
*/
2016-08-26 00:18:47 +00:00
onDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* A Signal that is dispatched each time a pointer is held down.
*/
2016-08-26 00:18:47 +00:00
onHold: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* A Signal that is dispatched each time a pointer is tapped.
*/
2016-08-26 00:18:47 +00:00
onTap: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* A Signal that is dispatched each time a pointer is released.
*/
2016-08-26 00:18:47 +00:00
onUp: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer1: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer2: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer3: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer4: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer5: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer6: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer7: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer8: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer9: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object.
*/
2016-08-26 00:18:47 +00:00
pointer10: Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* True if the Input is currently poll rate locked.
*/
2016-08-26 00:18:47 +00:00
pollLocked: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pollRate: number;
2016-06-17 11:46:47 +00:00
/**
* A point object representing the current position of the Pointer.
*/
2016-08-26 00:18:47 +00:00
position: Phaser.Point;
pointer: Phaser.Pointer[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
recordLimit: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
recordPointerHistory: boolean;
2016-06-17 11:46:47 +00:00
/**
* The rate in milliseconds at which the Pointer objects should update their tracking history.
* Default: 100
*/
2016-08-26 00:18:47 +00:00
recordRate: number;
2016-06-17 11:46:47 +00:00
/**
* If the Input Manager has been reset locked then all calls made to InputManager.reset,
* such as from a State change, are ignored.
*/
2016-08-26 00:18:47 +00:00
resetLocked: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scale: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* A point object representing the speed of the Pointer. Only really useful in single Pointer games; otherwise see the Pointer objects directly.
*/
2016-08-26 00:18:47 +00:00
speed: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click.
* Default: 200
*/
2016-08-26 00:18:47 +00:00
tapRate: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of active Pointers, not counting the mouse pointer.
*/
2016-08-26 00:18:47 +00:00
totalActivePointers: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of inactive Pointers.
*/
2016-08-26 00:18:47 +00:00
totalInactivePointers: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
touch: Phaser.Touch;
2016-06-17 11:46:47 +00:00
/**
* The world X coordinate of the most recently active pointer.
*/
2016-08-26 00:18:47 +00:00
worldX: number;
2016-06-17 11:46:47 +00:00
/**
* The world Y coordinate of the most recently active pointer.
*/
2016-08-26 00:18:47 +00:00
worldY: number;
2016-06-17 11:46:47 +00:00
/**
* The X coordinate of the most recently active pointer.
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The Y coordinate of the most recently active pointer.
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addPointer(): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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 4 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).
*
* 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.
*/
2016-08-26 00:18:47 +00:00
addMoveCallback(callback: Function, context: any): number;
2016-06-17 11:46:47 +00:00
/**
* Starts the Input Manager running.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
countActivePointers(limit?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deleteMoveCallback(callback: Function, context?: any): void;
2016-06-17 11:46:47 +00:00
/**
* Stops all of the Input Managers from running.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getLocalPosition(displayObject: any, pointer: Phaser.Pointer): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPointer(isActive?: boolean): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPointerFromId(pointerID: number): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPointerFromIdentifier(identifier: number): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hitTest(displayObject: PIXI.DisplayObject, pointer: Phaser.Pointer, localPoint: Phaser.Point): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(hard?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the speed and old position properties.
*
* @param x Sets the oldPosition.x value.
* @param y Sets the oldPosition.y value.
*/
2016-08-26 00:18:47 +00:00
resetSpeed(x: number, y: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setInteractiveCandidateHandler(callback: Function, context?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
startPointer(event: any): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
stopPointer(event: any): Phaser.Pointer;
2016-06-17 11:46:47 +00:00
/**
* Updates the Input Manager. Called by the core Game loop.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updatePointer(event: any): Phaser.Pointer;
}
2016-06-17 11:46:47 +00:00
/**
* The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite.
*/
2016-08-26 00:18:47 +00:00
class InputHandler {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(sprite: Phaser.Sprite);
2016-06-17 11:46:47 +00:00
/**
* Controls if the Sprite is allowed to be dragged horizontally.
* Default: true
*/
2016-08-26 00:18:47 +00:00
allowHorizontalDrag: boolean;
2016-06-17 11:46:47 +00:00
/**
* Controls if the Sprite is allowed to be dragged vertically.
* Default: true
*/
2016-08-26 00:18:47 +00:00
allowVerticalDrag: boolean;
2016-06-17 11:46:47 +00:00
/**
* A region of the game world within which the sprite is restricted during drag.
*/
2016-08-26 00:18:47 +00:00
boundsRect: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* A Sprite the bounds of which this sprite is restricted during drag.
*/
2016-08-26 00:18:47 +00:00
boundsSprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within.
*/
2016-08-26 00:18:47 +00:00
bringToTop: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Point object containing the coordinates of the Pointer when it was first pressed down onto this Sprite.
*/
2016-08-26 00:18:47 +00:00
downPoint: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The distance, in pixels, the pointer has to move while being held down, before the Sprite thinks it is being dragged.
*/
2016-08-26 00:18:47 +00:00
dragDistanceThreshold: number;
2016-06-17 11:46:47 +00:00
/**
* The offset from the Sprites position that dragging takes place from.
*/
2016-08-26 00:18:47 +00:00
dragOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Is the Sprite dragged from its center, or the point at which the Pointer was pressed down upon it?
*/
2016-08-26 00:18:47 +00:00
dragFromCenter: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is this sprite allowed to be dragged by the mouse? true = yes, false = no
*/
2016-08-26 00:18:47 +00:00
draggable: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Point from which the most recent drag started from. Useful if you need to return an object to its starting position.
*/
2016-08-26 00:18:47 +00:00
dragStartPoint: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
dragStopBlocksInputUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* The amount of time, in ms, the pointer has to be held down over the Sprite before it thinks it is being dragged.
*/
2016-08-26 00:18:47 +00:00
dragTimeThreshold: number;
2016-06-17 11:46:47 +00:00
/**
* If enabled the Input Handler will process input requests and monitor pointer activity.
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Warning: EXPERIMENTAL
*
* @param x
*/
2016-08-26 00:18:47 +00:00
globalToLocalX(x: number): number;
2016-06-17 11:46:47 +00:00
/**
* Warning: EXPERIMENTAL
*
* @param y
*/
2016-08-26 00:18:47 +00:00
globalToLocalY(y: number): number;
2016-06-17 11:46:47 +00:00
/**
* true if the Sprite is being currently dragged.
*/
2016-08-26 00:18:47 +00:00
isDragged: boolean;
2016-06-17 11:46:47 +00:00
/**
* The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.
* Default: 255
*/
2016-08-26 00:18:47 +00:00
pixelPerfectAlpha: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pixelPerfectClick: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pixelPerfectOver: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
priorityID: number;
2016-06-17 11:46:47 +00:00
/**
* EXPERIMENTAL: Please do not use this property unless you know what it does. Likely to change in the future.
*/
2016-08-26 00:18:47 +00:00
scaleLayer: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Point object that contains by how far the Sprite snap is offset.
*/
2016-08-26 00:18:47 +00:00
snapOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* This defines the top-left X coordinate of the snap grid.
*/
2016-08-26 00:18:47 +00:00
snapOffsetX: number;
2016-06-17 11:46:47 +00:00
/**
* This defines the top-left Y coordinate of the snap grid..
*/
2016-08-26 00:18:47 +00:00
snapOffsetY: number;
2016-06-17 11:46:47 +00:00
/**
* When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not.
*/
2016-08-26 00:18:47 +00:00
snapOnDrag: boolean;
2016-06-17 11:46:47 +00:00
/**
* When the Sprite is dragged this controls if the Sprite will be snapped on release.
*/
2016-08-26 00:18:47 +00:00
snapOnRelease: boolean;
2016-06-17 11:46:47 +00:00
/**
* If the sprite is set to snap while dragging this holds the point of the most recent 'snap' event.
*/
2016-08-26 00:18:47 +00:00
snapPoint: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* When a Sprite has snapping enabled this holds the width of the snap grid.
*/
2016-08-26 00:18:47 +00:00
snapX: number;
2016-06-17 11:46:47 +00:00
/**
* When a Sprite has snapping enabled this holds the height of the snap grid.
*/
2016-08-26 00:18:47 +00:00
snapY: number;
2016-06-17 11:46:47 +00:00
/**
* The Sprite object to which this Input Handler belongs.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite.
*/
2016-08-26 00:18:47 +00:00
useHandCursor: boolean;
2016-06-17 11:46:47 +00:00
/**
* Bounds Rect check for the sprite drag
*/
2016-08-26 00:18:47 +00:00
checkBoundsRect(): void;
2016-06-17 11:46:47 +00:00
/**
* Parent Sprite Bounds check for the sprite drag.
*/
2016-08-26 00:18:47 +00:00
checkBoundsSprite(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
checkPixel(x: number, y: number, pointer?: Phaser.Pointer): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkPointerDown(pointer: Phaser.Pointer, fastTest?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
checkPointerOver(pointer: Phaser.Pointer, fastTest?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Clean up memory.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
disableDrag(): void;
2016-06-17 11:46:47 +00:00
/**
* Stops the sprite from snapping to a grid during drag or release.
*/
2016-08-26 00:18:47 +00:00
disableSnap(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
downDuration(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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 5 parameters: `sprite`, `pointer`, `dragX`, `dragY` and `snapPoint`.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
enableDrag(lockCenter?: boolean, bringToTop?: boolean, pixelPerfect?: boolean, alphaThreshold?: number, boundsRect?: Phaser.Rectangle, boundsSprite?: Phaser.Sprite): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enableSnap(snapX: number, snapY: number, onDrag?: boolean, onRelease?: boolean, snapOffsetX?: number, snapOffsetY?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Is this object using pixel perfect checking?
* @return True if the this InputHandler has either `pixelPerfectClick` or `pixelPerfectOver` set to `true`.
*/
2016-08-26 00:18:47 +00:00
isPixelPerfect(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justOut(pointerId?: number, delay?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justOver(pointerId?: number, delay?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justPressed(pointerId?: number, delay?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justReleased(pointerId?: number, delay?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
overDuration(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerDown(pointerId?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Is this sprite being dragged by the mouse or not?
*
* @param pointerId
* @return True if the pointer is dragging an object, otherwise false.
*/
2016-08-26 00:18:47 +00:00
pointerDragged(pointerId?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerOut(pointerId?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerOver(pointerId?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer first touched the touchscreen.
*
* @param pointerId - Default: (check all)
*/
2016-08-26 00:18:47 +00:00
pointerTimeDown(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer left the touchscreen.
*
* @param pointerId
*/
2016-08-26 00:18:47 +00:00
pointerTimeOut(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer first touched the touchscreen.
*
* @param pointerId
*/
2016-08-26 00:18:47 +00:00
pointerTimeOver(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer left the touchscreen.
*
* @param pointerId
*/
2016-08-26 00:18:47 +00:00
pointerTimeUp(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerUp(pointerId?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerX(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerY(pointerId?: number): number;
2016-06-17 11:46:47 +00:00
/**
* Resets the Input Handler and disables it.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setDragLock(allowHorizontal?: boolean, allowVertical?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
start(priority: number, useHandCursor: boolean): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
*
* @param pointer
*/
2016-08-26 00:18:47 +00:00
startDrag(pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
* Stops the Input Handler from running.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
*
* @param pointer
*/
2016-08-26 00:18:47 +00:00
stopDrag(pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(pointer: Phaser.Pointer): void;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* Called as a Pointer actively drags this Game Object.
2016-06-17 11:46:47 +00:00
*
2016-07-08 14:46:26 +00:00
* @param pointer The Pointer causing the drag update.
* @param fromStart True if this is the first update, immediately after the drag has started.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
updateDrag(pointer: Phaser.Pointer): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
validForInput(highestID: number, highestRenderID: number, includePixelPerfect?: boolean): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects.
*/
2016-08-26 00:18:47 +00:00
class Key {
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, keycode: number);
2016-06-17 11:46:47 +00:00
/**
* The down state of the ALT key, if pressed at the same time as this key.
*/
2016-08-26 00:18:47 +00:00
altKey: boolean;
2016-06-17 11:46:47 +00:00
/**
* The down state of the CTRL key, if pressed at the same time as this key.
*/
2016-08-26 00:18:47 +00:00
ctrlKey: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
duration: number;
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Stores the most recent DOM event.
*/
2016-08-26 00:18:47 +00:00
event: any;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The "down" state of the key. This will remain `true` for as long as the keyboard thinks this key is held down.
*/
2016-08-26 00:18:47 +00:00
isDown: boolean;
2016-06-17 11:46:47 +00:00
/**
* The "up" state of the key. This will remain `true` for as long as the keyboard thinks this key is up.
* Default: true
*/
2016-08-26 00:18:47 +00:00
isUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
*/
2016-08-26 00:18:47 +00:00
_justDown: boolean;
justDown: boolean;
2016-06-17 11:46:47 +00:00
/**
* True if the key has just been pressed (NOTE: requires to be reset, see justDown getter)
*/
2016-08-26 00:18:47 +00:00
_justUp: boolean;
justUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* The keycode of this key.
*/
2016-08-26 00:18:47 +00:00
keyCode: number;
2016-06-17 11:46:47 +00:00
/**
* This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
*/
2016-08-26 00:18:47 +00:00
onDown: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second.
*/
2016-08-26 00:18:47 +00:00
onHoldCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The context under which the onHoldCallback will be called.
*/
2016-08-26 00:18:47 +00:00
onHoldContext: any;
2016-06-17 11:46:47 +00:00
/**
* This Signal is dispatched every time this Key is released. It is only dispatched once (until the key is pressed and released again).
*/
2016-08-26 00:18:47 +00:00
onUp: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* If a key is held down this holds down the number of times the key has 'repeated'.
*/
2016-08-26 00:18:47 +00:00
repeats: number;
2016-06-17 11:46:47 +00:00
/**
* The down state of the SHIFT key, if pressed at the same time as this key.
*/
2016-08-26 00:18:47 +00:00
shiftKey: boolean;
2016-06-17 11:46:47 +00:00
/**
* The timestamp when the key was last pressed down. This is based on Game.time.now.
*/
2016-08-26 00:18:47 +00:00
timeDown: number;
2016-06-17 11:46:47 +00:00
/**
* The timestamp when the key was last released. This is based on Game.time.now.
*/
2016-08-26 00:18:47 +00:00
timeUp: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
downDuration(duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by Phaser.Keyboard.
*
* @param event The DOM event that triggered this.
*/
2016-08-26 00:18:47 +00:00
processKeyDown(event: KeyboardEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by Phaser.Keyboard.
*
* @param event The DOM event that triggered this.
*/
2016-08-26 00:18:47 +00:00
processKeyUp(event: KeyboardEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reset(hard?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by Phaser.Keyboard.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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 released. Given in ms. - Default: 50
* @return True if the key was released within the given duration.
*/
2016-08-26 00:18:47 +00:00
upDuration(duration?: number): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Keyboard {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* The context under which the callbacks are run.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* Keyboard input will only be processed if enabled.
* Default: true
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* The most recent DOM event from keydown or keyup. This is updated every time a new key is pressed or released.
*/
2016-08-26 00:18:47 +00:00
event: any;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Returns the string value of the most recently pressed key.
*/
2016-08-26 00:18:47 +00:00
lastChar: string;
2016-06-17 11:46:47 +00:00
/**
* Returns the most recently pressed Key. This is a Phaser.Key object and it changes every time a key is pressed.
*/
2016-08-26 00:18:47 +00:00
lastKey: Phaser.Key;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a key is pressed down, including key repeats when a key is held down.
*/
2016-08-26 00:18:47 +00:00
onDownCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a DOM onkeypress event is raised, which is only for printable keys.
*/
2016-08-26 00:18:47 +00:00
onPressCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a key is released.
*/
2016-08-26 00:18:47 +00:00
onUpCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The most recent DOM event from keypress.
*/
2016-08-26 00:18:47 +00:00
pressEvent: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addCallbacks(context: any, onDown?: Function, onUp?: Function, onPress?: Function): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addKey(keycode: number): Phaser.Key;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addKeys(keys: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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]`.
*/
2016-08-26 00:18:47 +00:00
addKeyCapture(keycode: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createCursorKeys(): Phaser.CursorKeys;
2016-06-17 11:46:47 +00:00
/**
* Clear all set key captures.
*/
2016-08-26 00:18:47 +00:00
clearCaptures(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
downDuration(keycode: number, duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isDown(keycode: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Process the keydown event.
*
* @param event
*/
2016-08-26 00:18:47 +00:00
processKeyDown(event: KeyboardEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Process the keypress event.
*
* @param event
*/
2016-08-26 00:18:47 +00:00
processKeyPress(event: KeyboardEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Process the keyup event.
*
* @param event
*/
2016-08-26 00:18:47 +00:00
processKeyUp(event: KeyboardEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Removes a Key object from the Keyboard manager.
*
* @param keycode The {@link Phaser.KeyCode keycode} of the key to remove.
*/
2016-08-26 00:18:47 +00:00
removeKey(keycode: number): void;
2016-06-17 11:46:47 +00:00
/**
* Removes an existing key capture.
*
* @param keycode The {@link Phaser.KeyCode keycode} to remove capturing of.
*/
2016-08-26 00:18:47 +00:00
removeKeyCapture(keycode: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reset(hard?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Starts the Keyboard event listeners running (keydown and keyup). They are attached to the window.
* This is called automatically by Phaser.Input and should not normally be invoked directly.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* Stops the Keyboard event listeners from running (keydown, keyup and keypress). They are removed from the window.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates all currently defined keys.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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 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.
*/
2016-08-26 00:18:47 +00:00
upDuration(keycode: number, duration?: number): boolean;
}
2016-07-01 15:57:13 +00:00
2016-08-26 00:18:47 +00:00
/**
* 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;
}
2016-06-17 11:46:47 +00:00
/**
* Creates a new Line object with a start and an end point.
*/
2016-08-26 00:18:47 +00:00
class Line {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(x1?: number, y1?: number, x2?: number, y2?: number);
2016-06-17 11:46:47 +00:00
/**
* Gets the angle of the line in radians.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* The end point of the line.
*/
2016-08-26 00:18:47 +00:00
end: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Gets the height of this bounds of this line.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the left-most point of this line.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the length of the line segment.
*/
2016-08-26 00:18:47 +00:00
length: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the angle in radians of the normal of this line (line.angle - 90 degrees.)
*/
2016-08-26 00:18:47 +00:00
normalAngle: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the x component of the left-hand normal of this line.
*/
2016-08-26 00:18:47 +00:00
normalX: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the y component of the left-hand normal of this line.
*/
2016-08-26 00:18:47 +00:00
normalY: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the perpendicular slope of the line (x/y).
*/
2016-08-26 00:18:47 +00:00
perpSlope: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the right-most point of this line.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the slope of the line (y/x).
*/
2016-08-26 00:18:47 +00:00
slope: number;
2016-06-17 11:46:47 +00:00
/**
* The start point of the line.
*/
2016-08-26 00:18:47 +00:00
start: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Gets the top-most point of this line.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the width of this bounds of this line.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the x coordinate of the top left of the bounds around this line.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the y coordinate of the top left of the bounds around this line.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersectsPoints(a: Phaser.Point, b: Phaser.Point, e: Phaser.Point, f: Phaser.Point, asSegment?: boolean, result?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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.
* The line segment intersects one of the 4 rectangle edges.
*
* The for the purposes of this function rectangles are considered 'solid'.
*
* @param line The line to check for intersection 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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static reflect(a: Phaser.Line, b: Phaser.Line): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
centerOn(x: number, y: number): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output: Phaser.Line): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
coordinatesOnLine(stepRate: number, results: any[]): any[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
fromAngle(x: number, y: number, angle: number, length: number): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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.center.x, if false startSprite.x. Note that Sprites don't have a center property by default, so only enable if you've over-ridden your Sprite with a custom class.
* @return This line object
*/
2016-08-26 00:18:47 +00:00
fromSprite(startSprite: Phaser.Sprite, endSprite: Phaser.Sprite, useCenter?: boolean): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersects(line: Phaser.Line, asSegment?: boolean, result?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
midPoint(out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Tests if the given coordinates fall on this line. See 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.
* @return True if the point is on the line, false if not.
*/
2016-08-26 00:18:47 +00:00
pointOnLine(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Tests if the given coordinates fall on this line and within the segment. See 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.
* @return True if the point is on the line and segment, false if not.
*/
2016-08-26 00:18:47 +00:00
pointOnSegment(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
random(out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reflect(line: Phaser.Line): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
rotate(angle: number, asDegrees?: boolean): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
rotateAround(x: number, y: number, angle: number, asDegrees?: boolean): Phaser.Line;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setTo(x1?: number, y1?: number, x2?: number, y2?: number): Phaser.Line;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class LinkedList {
2016-06-17 11:46:47 +00:00
/**
* First element in the list.
*/
2016-08-26 00:18:47 +00:00
first: any;
2016-06-17 11:46:47 +00:00
/**
* Last element in the list.
*/
2016-08-26 00:18:47 +00:00
last: any;
2016-06-17 11:46:47 +00:00
/**
* Next element in the list.
*/
2016-08-26 00:18:47 +00:00
next: any;
2016-06-17 11:46:47 +00:00
/**
* Previous element in the list.
*/
2016-08-26 00:18:47 +00:00
prev: any;
2016-06-17 11:46:47 +00:00
/**
* Number of elements in the list.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(item: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
callAll(callback: Function): void;
2016-06-17 11:46:47 +00:00
/**
* Removes the given element from this linked list if it exists.
*
* @param item The item to be removed from the list.
*/
2016-08-26 00:18:47 +00:00
remove(item: any): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the first, last, next and previous node pointers in this list.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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/)
*/
2016-08-26 00:18:47 +00:00
class Loader {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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 "/".
*/
2016-08-26 00:18:47 +00:00
baseURL: string;
2016-06-17 11:46:47 +00:00
/**
* Local reference to the Phaser.Cache.
*/
2016-08-26 00:18:47 +00:00
cache: Phaser.Cache;
2016-06-17 11:46:47 +00:00
/**
* The crossOrigin value applied to loaded images. Very often this needs to be set to 'anonymous'.
*/
2016-08-26 00:18:47 +00:00
crossOrigin: boolean | string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enableParallel: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* True if all assets in the queue have finished loading.
*/
2016-08-26 00:18:47 +00:00
hasLoaded: boolean;
2016-06-17 11:46:47 +00:00
/**
* True if the Loader is in the process of loading the queue.
*/
2016-08-26 00:18:47 +00:00
isLoading: boolean;
2016-06-17 11:46:47 +00:00
/**
* The number of concurrent / parallel resources to try and fetch at once.
*
* Many current browsers limit 6 requests per domain; this is slightly conservative.
*/
2016-08-26 00:18:47 +00:00
maxParallelDownloads: number;
2016-06-17 11:46:47 +00:00
/**
* 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)`
*/
2016-08-26 00:18:47 +00:00
onFileStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onFileComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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)`
*/
2016-08-26 00:18:47 +00:00
onFileError: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when the final file in the load queue has either loaded or failed.
*/
2016-08-26 00:18:47 +00:00
onLoadComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onLoadStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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)`
*/
2016-08-26 00:18:47 +00:00
onPackComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The value of `path`, if set, is placed before any _relative_ file path given. For example:
*
* `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 "/".
*/
2016-08-26 00:18:47 +00:00
path: string;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
preloadSprite: any;
2016-06-17 11:46:47 +00:00
/**
* The rounded load progress percentage value (from 0 to 100). See {@link Phaser.Loader#progressFloat}.
*/
2016-08-26 00:18:47 +00:00
progress: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
progressFloat: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resetLocked: boolean;
2016-06-17 11:46:47 +00:00
/**
* If true and if the browser supports XDomainRequest, it will be used in preference for XHR.
*
* This is only relevant for IE 9 and should _only_ be enabled for IE 9 clients when required by the server/CDN.
*/
2016-08-26 00:18:47 +00:00
useXDomainRequest: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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: ''
*/
2016-08-26 00:18:47 +00:00
asyncComplete(file: any, errorMessage?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addSyncPoint(type: string, key: string): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addToFileList(type: string, key: string, url?: string, properties?: any, overwrite?: boolean, extension?: string): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
atlas(key: string, textureURL?: string, atlasURL?: string, atlasData?: any, format?: number): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
atlasJSONArray(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
atlasJSONHash(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
atlasXML(key: string, textureURL?: string, atlasURL?: string, atlasData?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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:<opus_resource>", 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.
*/
2016-08-26 00:18:47 +00:00
audio(key: string, urls: string | string[] | any, autoDecode?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* A legacy alias for Loader.audioSprite. Please see that method for documentation.
2016-06-17 11:46:47 +00:00
*
* @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.
*/
2016-08-26 00:18:47 +00:00
audiosprite(key: string, urls: string[], jsonURL?: string, jsonData?: string | any, autoDecode?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
binary(key: string, url?: string, callback?: Function, callbackContext?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
bitmapFont(key: string, textureURL?: string, atlasURL?: string, atlasData?: any, xSpacing?: number, ySpacing?: number): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkKeyExists(type: string, key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* Successfully loaded a CSV file - only used for certain types.
*
* @param file File associated with this request
* @param xhr
*/
2016-08-26 00:18:47 +00:00
csvLoadComplete(file: any, xhr: XMLHttpRequest): void;
2016-06-17 11:46:47 +00:00
/**
* Called when a file/resources had been downloaded and needs to be processed further.
*
* @param file File loaded
* @param xhr XHR request, unspecified if loaded via other means (eg. tags)
*/
2016-08-26 00:18:47 +00:00
fileComplete(file: any, xhr: XMLHttpRequest): void;
2016-06-17 11:46:47 +00:00
/**
* Error occurred when loading a file.
*
* @param file
* @param xhr XHR request, unspecified if loaded via other means (eg. tags)
* @param reason
*/
2016-08-26 00:18:47 +00:00
fileError(file: any, xhr: XMLHttpRequest, reason: string): void;
2016-06-17 11:46:47 +00:00
/**
* The loading is all finished.
*
* @param abnormal True if the loading finished abnormally. - Default: true
*/
2016-08-26 00:18:47 +00:00
finishedLoading(abnormal?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getAsset(type: string, key: string): any;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
getAssetIndex(type: string, key: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getAudioURL(urls: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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 `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
* @param overwrite If an unloaded file with a matching key already exists in the queue, this entry will overwrite it.
* @return This Loader instance.
*/
2016-08-26 00:18:47 +00:00
image(key: string, url?: string, overwrite?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
images(keys: string[], urls?: string[]): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
json(key: string, url?: string, overwrite?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* Successfully loaded a JSON file - only used for certain types.
*
* @param file File associated with this request
* @param xhr
*/
2016-08-26 00:18:47 +00:00
jsonLoadComplete(file: any, xhr: XMLHttpRequest): void;
2016-06-17 11:46:47 +00:00
/**
* Continue async loading through an Audio tag.
*/
2016-08-26 00:18:47 +00:00
loadAudioTag(file: any): void;
2016-06-17 11:46:47 +00:00
/**
* Start fetching a resource.
*
* All code paths, async or otherwise, from this function must return to `asyncComplete`.
*
* @param file
*/
2016-08-26 00:18:47 +00:00
loadFile(file: any): void;
2016-06-17 11:46:47 +00:00
/**
* Continue async loading through an Image tag.
*/
2016-08-26 00:18:47 +00:00
loadImageTag(file: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pack(key: string, url?: string, data?: any, callbackContext?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
parseXml(data: string): XMLDocument;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
physics(key: string, url?: string, data?: any, format?: string): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
processLoadQueue(): void;
2016-06-17 11:46:47 +00:00
/**
* Process pack data. This will usually modify the file list.
*
* @param pack
*/
2016-08-26 00:18:47 +00:00
processPack(pack: any): void;
2016-06-17 11:46:47 +00:00
/**
* Remove all file loading requests - this is _insufficient_ to stop current loading. Use `reset` instead.
*/
2016-08-26 00:18:47 +00:00
removeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeFile(type: string, key: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
replaceInFileList(type: string, key: string, url: string, properties: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(hard?: boolean, clearEvents?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by ScaleManager when the game resizes in RESIZE scalemode.
*
* This can be used to adjust the preloading sprite size, eg.
*/
2016-08-26 00:18:47 +00:00
resize(): void;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
script(key: string, url?: String, callback?: Function, callbackContext?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
shader(key: string, url?: String, overwrite?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setPreloadSprite(sprite: Phaser.Sprite | Phaser.Image, direction?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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 `<key>.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 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.
* @return This Loader instance.
*/
2016-08-26 00:18:47 +00:00
spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* Start loading the assets. Normally you don't need to call this yourself as the StateManager will do so.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
text(key: string, url?: string, overwrite?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* Adds a Tile Map data file to the current load queue.
*
2016-08-26 00:18:47 +00:00
* 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
*
2016-06-17 11:46:47 +00:00
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
tilemap(key: string, url?: string, data?: any, format?: number): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
totalLoadedFiles(): number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
totalLoadedPacks(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
totalQueuedFiles(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
totalQueuedPacks(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
transformUrl(url: string, file?: any): string;
updateProgress(): void;
2016-06-17 11:46:47 +00:00
/**
* 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:<opus_resource>", 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.
*/
2016-08-26 00:18:47 +00:00
video(key: string, urls: string | string[] | any, loadEvent?: string, asBlob?: boolean): Phaser.Loader;
withSyncPoint(callback: Function, callbackContext?: any): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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 `<key>.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.
*/
2016-08-26 00:18:47 +00:00
xml(key: string, url?: string, overwrite?: boolean): Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
xhrLoad(file: any, url: string, type: string, onload: Function, onerror?: Function): void;
xhrLoadWithXDR(file: any, url: string, type: string, onload: Function, onerror?: Function): void;
2016-06-17 11:46:47 +00:00
/**
* Successfully loaded an XML file - only used for certain types.
*
* @param file File associated with this request
* @param xhr
*/
2016-08-26 00:18:47 +00:00
xmlLoadComplete(file: any, xhr: XMLHttpRequest): void;
}
2016-06-17 11:46:47 +00:00
/**
* Phaser.LoaderParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into the Cache.
*/
2016-08-26 00:18:47 +00:00
class LoaderParser {
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return The parsed Bitmap Font data.
*/
2016-08-26 00:18:47 +00:00
static bitmapFont(xml: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return The parsed Bitmap Font data.
*/
2016-08-26 00:18:47 +00:00
static xmlBitmapFont(xml: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return The parsed Bitmap Font data.
*/
2016-08-26 00:18:47 +00:00
static jsonBitmapFont(json: any, baseTexture: PIXI.BaseTexture, xSpacing?: number, ySpacing?: number): any;
}
2016-06-17 11:46:47 +00:00
/**
* The Matrix is a 3x3 matrix mostly used for display transforms within the renderer.
*
* It is represented like so:
*
* | a | b | tx |
* | c | d | ty |
* | 0 | 0 | 1 |
*/
2016-08-26 00:18:47 +00:00
class Matrix extends PIXI.Matrix {
2016-06-17 11:46:47 +00:00
/**
*
* Default: 1
*/
2016-08-26 00:18:47 +00:00
a: number;
2016-06-17 11:46:47 +00:00
/**
*
* Default: 0
*/
2016-08-26 00:18:47 +00:00
b: number;
2016-06-17 11:46:47 +00:00
/**
*
* Default: 0
*/
2016-08-26 00:18:47 +00:00
c: number;
2016-06-17 11:46:47 +00:00
/**
*
* Default: 1
*/
2016-08-26 00:18:47 +00:00
d: number;
2016-06-17 11:46:47 +00:00
/**
*
* Default: 0
*/
2016-08-26 00:18:47 +00:00
tx: number;
2016-06-17 11:46:47 +00:00
/**
*
* Default: 0
*/
2016-08-26 00:18:47 +00:00
ty: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The Matrix is a 3x3 matrix mostly used for display transforms within the renderer.
*
* It is represented like so:
*
* | a | b | tx |
* | c | 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
*/
2016-08-26 00:18:47 +00:00
constructor(a?: number, b?: number, c?: number, d?: number, tx?: number, ty?: number);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
apply(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
applyInverse(pos: Phaser.Point, newPos?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output?: Phaser.Matrix): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* Copies the properties from the given Matrix into this Matrix.
*
* @param matrix The Matrix to copy from.
* @return This Matrix object.
*/
2016-08-26 00:18:47 +00:00
copyFrom(matrix: Phaser.Matrix): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* Copies the properties from this Matrix to the given Matrix.
*
* @param matrix The Matrix to copy from.
* @return The destination Matrix object.
*/
2016-08-26 00:18:47 +00:00
copyTo(matrix: Phaser.Matrix): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fromArray(array: number[]): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTo(a: number, b: number, c: number, d: number, tx: number, ty: number): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
toArray(transpose?: boolean, array?: number[]): number[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
translate(x: number, y: number): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scale(x: number, y: number): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* Applies a rotation transformation to this matrix.
*
* @param angle The angle to rotate by, given in radians.
* @return This Matrix object.
*/
2016-08-26 00:18:47 +00:00
rotate(angle: number): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* Appends the given Matrix to this Matrix.
*
* @param matrix The matrix to append to this one.
* @return This Matrix object.
*/
2016-08-26 00:18:47 +00:00
append(matrix: Phaser.Matrix): Phaser.Matrix;
2016-06-17 11:46:47 +00:00
/**
* Resets this Matrix to an identity (default) matrix.
* @return This Matrix object.
*/
2016-08-26 00:18:47 +00:00
identity(): Phaser.Matrix;
}
2016-06-17 11:46:47 +00:00
/**
* A collection of useful mathematical functions.
*
* These are normally accessed through `game.math`.
*/
2016-08-26 00:18:47 +00:00
class Math {
2016-06-17 11:46:47 +00:00
/**
* Find the angle of a segment from (x1, y1) -> (x2, y2).
*
2016-07-08 14:46:26 +00:00
* @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.
2016-06-17 11:46:47 +00:00
* @return The angle, in radians.
*/
2016-08-26 00:18:47 +00:00
static angleBetween(x1: number, y1: number, x2: number, y2: number): number;
2016-06-17 11:46:47 +00:00
/**
* Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).
*
2016-07-08 14:46:26 +00:00
* @param point1 The first point.
* @param point2 The second point.
* @return The angle between the two points, in radians.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static angleBetweenPoints(point1: Phaser.Point, point2: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* Find the angle of a segment from (x1, y1) -> (x2, y2).
2016-07-08 14:46:26 +00:00
*
* The difference between this method and Math.angleBetween is that this assumes the y coordinate travels
2016-06-17 11:46:47 +00:00
* down the screen.
*
2016-07-08 14:46:26 +00:00
* @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.
2016-06-17 11:46:47 +00:00
* @return The angle, in radians.
*/
2016-08-26 00:18:47 +00:00
static angleBetweenY(x1: number, y1: number, x2: number, y2: number): number;
2016-06-17 11:46:47 +00:00
/**
* Find the angle of a segment from (point1.x, point1.y) -> (point2.x, point2.y).
*
* @param point1
* @param point2
* @return The angle, in radians.
*/
2016-08-26 00:18:47 +00:00
static angleBetweenPointsY(point1: Phaser.Point, point2: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* Averages all values passed to the function and returns the result.
* @return The average of all given values.
*/
2016-08-26 00:18:47 +00:00
static average(...numbers: number[]): number;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param n
* @param i
*/
2016-08-26 00:18:47 +00:00
static bernstein(n: number, i: number): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a number between the `min` and `max` values.
*
* @param min The minimum value. Must be positive, and less than 'max'.
* @param max The maximum value. Must be position, and greater than 'min'.
* @return A value between the range min to max.
*/
2016-08-26 00:18:47 +00:00
static between(min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static bezierInterpolation(v: number[], k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Calculates a catmum rom value.
*
* @param p0
* @param p1
* @param p2
* @param p3
* @param t
*/
2016-08-26 00:18:47 +00:00
static catmullRom(p0: number, p1: number, p2: number, p3: number, t: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static catmullRomInterpolation(v: number[], k: number): number;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* 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.
2016-06-17 11:46:47 +00:00
*
* @param value The value to round.
* @param place The place to round to.
2016-07-08 14:46:26 +00:00
* @param base The base to round in. Default is 10 for decimal. - Default: 10
* @return The rounded value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static ceilTo(value: number, place?: number, base?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static clamp(x: number, a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* Clamp `x` to the range `[a, Infinity)`.
* Roughly the same as `Math.max(x, a)`, except for NaN handling.
*
* @param x
* @param a
*/
2016-08-26 00:18:47 +00:00
static clampBottom(x: number, a: number): number;
2016-06-17 11:46:47 +00:00
/**
* Convert degrees to radians.
*
* @param degrees Angle in degrees.
* @return Angle in radians.
*/
2016-08-26 00:18:47 +00:00
static degToRad(degrees: number): number;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* The absolute difference between two values.
2016-06-17 11:46:47 +00:00
*
2016-07-08 14:46:26 +00:00
* @param a The first value to check.
* @param b The second value to check.
* @return The absolute difference between the two values.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static difference(a: number, b: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static distance(x1: number, y1: number, x2: number, y2: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static distanceSq(x1: number, y1: number, x2: number, y2: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static distancePow(xy: number, y1: number, x2: number, y2: number, pow?: number): number;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param value the number you want to evaluate
*/
2016-08-26 00:18:47 +00:00
static factorial(value: number): number;
2016-06-17 11:46:47 +00:00
/**
2016-07-08 14:46:26 +00:00
* 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.
2016-06-17 11:46:47 +00:00
*
* @param value The value to round.
* @param place The place to round to.
2016-07-08 14:46:26 +00:00
* @param base The base to round in. Default is 10 for decimal. - Default: 10
* @return The rounded value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static floorTo(value: number, place: number, base: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static fuzzyCeil(val: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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|<epsilon
*/
2016-08-26 00:18:47 +00:00
static fuzzyEqual(a: number, b: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* `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<b+epsilon
*/
2016-08-26 00:18:47 +00:00
static fuzzyLessThan(a: Number, b: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Applies a fuzzy floor to the given value.
*
* @param val The value to floor.
* @param epsilon The epsilon (a small value used in the calculation) - Default: 0.0001
* @return floor(val+epsilon)
*/
2016-08-26 00:18:47 +00:00
static fuzzyFloor(val: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* `a` is fuzzyGreaterThan `b` if it is more 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>b+epsilon
*/
2016-08-26 00:18:47 +00:00
static fuzzyGreaterThan(a: number, b: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* `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<b+epsilon
*/
2016-08-26 00:18:47 +00:00
static fuzzyLessThan(a: number, b: number, epsilon?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the number given is even.
*
* @param n The number to check.
* @return True if the given number is even. False if the given number is odd.
*/
2016-08-26 00:18:47 +00:00
static isEven(n: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the number given is odd.
*
* @param n The number to check.
* @return True if the given number is odd. False if the given number is even.
*/
2016-08-26 00:18:47 +00:00
static isOdd(n: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Calculates a linear (interpolation) value over t.
*
* @param p0
* @param p1
2016-07-08 14:46:26 +00:00
* @param t A value between 0 and 1.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static linear(p0: number, p1: number, t: number): number;
2016-06-17 11:46:47 +00:00
/**
* A Linear 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
*/
2016-08-26 00:18:47 +00:00
static linearInterpolation(v: number[], k: number): number;
2016-06-17 11:46:47 +00:00
/**
* Linear mapping from range <a1, a2> to range <b1, b2>
*
2016-07-08 14:46:26 +00:00
* @param x The value to map
* @param a1 First endpoint of the range <a1, a2>
* @param a2 Final endpoint of the range <a1, a2>
* @param b1 First endpoint of the range <b1, b2>
* @param b2 Final endpoint of the range <b1, b2>
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static max(...numbers: number[]): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-08 14:46:26 +00:00
* @return The new value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static maxAdd(value: number, amount: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static maxProperty(...numbers: number[]): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static min(...numbers: number[]): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static minProperty(...numbers: number[]): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static minSub(value: number, amount: number, min: number): number;
2016-06-17 11:46:47 +00:00
/**
* Normalizes an angle to the [0,2pi) range.
*
* @param angleRad The angle to normalize, in radians.
2016-07-08 14:46:26 +00:00
* @return The angle, fit within the [0,2pi] range, in radians.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static normalizeAngle(angle: number, radians?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static percent(a: number, b: number, base?: number): number;
static p2px(v: number): number;
2016-06-17 11:46:47 +00:00
/**
* Twice PI.
* Default: ~6.283
*/
2016-08-26 00:18:47 +00:00
static PI2: number;
2016-06-17 11:46:47 +00:00
/**
* Convert radians to degrees.
*
* @param radians Angle in radians.
* @return Angle in degrees
*/
2016-08-26 00:18:47 +00:00
static radToDeg(radians: number): number;
2016-06-17 11:46:47 +00:00
/**
* Reverses an angle.
*
* @param angleRad The angle to reverse, in radians.
2016-07-08 14:46:26 +00:00
* @return The reverse angle, in radians.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Round to the next whole number _away_ from zero.
*
* @param value Any number.
* @return The rounded value of that number.
*/
2016-08-26 00:18:47 +00:00
static roundAwayFromZero(value: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-08 14:46:26 +00:00
* @param base The base to round in. Default is 10 for decimal. - Default: 10
* @return The rounded value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static roundTo(value: number, place?: number, base?: number): number;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param n
* @return n mod 1
*/
2016-08-26 00:18:47 +00:00
static shear(n: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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}
*/
2016-08-26 00:18:47 +00:00
static sign(x: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static sinCosGenerator(length: number, sinAmplitude?: number, cosAmplitude?: number, frequency?: number): { sin: number[]; cos: number[]; };
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static smootherstep(x: number, min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static smoothstep(x: number, min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-08 14:46:26 +00:00
* @return The snapped value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static snapTo(input: number, gap: number, start?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-08 14:46:26 +00:00
* @return The snapped value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static snapToCeil(input: number, gap: number, start?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-08 14:46:26 +00:00
* @return The snapped value.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static snapToFloor(input: number, gap: number, start?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static within(a: number, b: number, tolerance: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static wrap(value: number, min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static wrapAngle(angle: number, radians?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Mouse {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* This property was removed in Phaser 2.4 and should no longer be used.
* Instead please see the Pointer button properties such as `Pointer.leftButton`, `Pointer.rightButton` and so on.
* Or Pointer.button holds the DOM event button value if you require that.
*/
2016-08-26 00:18:47 +00:00
button: number;
2016-06-17 11:46:47 +00:00
/**
* The context under which callbacks are called.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* If true the DOM mouse events will have event.preventDefault applied to them, if false they will propagate fully.
*/
2016-08-26 00:18:47 +00:00
capture: boolean;
2016-06-17 11:46:47 +00:00
/**
* Mouse input will only be processed if enabled.
* Default: true
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
event: MouseEvent;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Phaser Input Manager.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.Input;
2016-06-17 11:46:47 +00:00
/**
* If the mouse has been Pointer Locked successfully this will be set to true.
*/
2016-08-26 00:18:47 +00:00
locked: boolean;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired when the mouse is pressed down.
*/
2016-08-26 00:18:47 +00:00
mouseDownCallback: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired when the mouse is no longer over the game canvas.
*/
2016-08-26 00:18:47 +00:00
mouseOutCallback: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired when the mouse enters the game canvas (usually after a mouseout).
*/
2016-08-26 00:18:47 +00:00
mouseOverCallback: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired when the mouse is released from a pressed down state.
*/
2016-08-26 00:18:47 +00:00
mouseUpCallback: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired when the mousewheel is used.
*/
2016-08-26 00:18:47 +00:00
mouseWheelCallback: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseDown: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseMove: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseUp: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseOut: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseOver: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Internal event handler reference.
*/
2016-08-26 00:18:47 +00:00
_onMouseWheel: (event: MouseEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Wheel proxy event object, if required. Shared for all wheel events for this mouse.
*/
2016-08-26 00:18:47 +00:00
_wheelEvent: WheelEventProxy;
2016-06-17 11:46:47 +00:00
/**
* This event is dispatched when the browser enters or leaves pointer lock state.
*/
2016-08-26 00:18:47 +00:00
pointerLock: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* If true Pointer.stop will be called if the mouse leaves the game canvas.
*/
2016-08-26 00:18:47 +00:00
stopOnGameOut: boolean;
2016-06-17 11:46:47 +00:00
/**
* The direction of the _last_ mousewheel usage 1 for up -1 for down.
*/
2016-08-26 00:18:47 +00:00
wheelDelta: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseDown(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseMove(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseOut(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseOver(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseUp(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onMouseUpGlobal(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* The internal method that handles the mouse wheel event from the browser.
*
* @param event The native event from the browser.
*/
2016-08-26 00:18:47 +00:00
onMouseWheel(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Internal pointerLockChange handler.
*
* @param event The native event from the browser. This gets stored in Mouse.event.
*/
2016-08-26 00:18:47 +00:00
pointerLockChange(event: MouseEvent): void;
2016-06-17 11:46:47 +00:00
/**
* Internal release pointer lock handler.
*/
2016-08-26 00:18:47 +00:00
releasePointerLock(): void;
2016-06-17 11:46:47 +00:00
/**
* If the browser supports it you can request that the pointer be locked to the browser window.
* This is classically known as 'FPS controls', where the pointer can't leave the browser until the user presses an exit key.
* If the browser successfully enters a locked state the event Phaser.Mouse.pointerLock will be dispatched and the first parameter will be 'true'.
*/
2016-08-26 00:18:47 +00:00
requestPointerLock(): void;
2016-06-17 11:46:47 +00:00
/**
* Starts the event listeners running.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* Stop the event listeners.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
}
2016-06-17 11:46:47 +00:00
/**
* The MSPointer class handles Microsoft touch interactions with the game and the resulting Pointer objects.
*
* It will work only in Internet Explorer 10+ and Windows Store or Windows Phone 8 apps using JavaScript.
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
*
* 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.
*
* Please note that at the current time of writing Phaser does not yet support chorded button interactions:
* http://www.w3.org/TR/pointerevents/#chorded-button-interactions
*/
2016-08-26 00:18:47 +00:00
class MSPointer {
2016-06-17 11:46:47 +00:00
/**
* The MSPointer class handles Microsoft touch interactions with the game and the resulting Pointer objects.
*
* It will work only in Internet Explorer 10+ and Windows Store or Windows Phone 8 apps using JavaScript.
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
*
* 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.
*
* Please note that at the current time of writing Phaser does not yet support chorded button interactions:
* http://www.w3.org/TR/pointerevents/#chorded-button-interactions
*
* @param game A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* This property was removed in Phaser 2.4 and should no longer be used.
* Instead please see the Pointer button properties such as `Pointer.leftButton`, `Pointer.rightButton` and so on.
* Or Pointer.button holds the DOM event button value if you require that.
*/
2016-08-26 00:18:47 +00:00
button: number;
2016-06-17 11:46:47 +00:00
/**
* If true the Pointer events will have event.preventDefault applied to them, if false they will propagate fully.
*/
2016-08-26 00:18:47 +00:00
capture: boolean;
2016-06-17 11:46:47 +00:00
/**
* The context under which callbacks are called (defaults to game).
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* The browser MSPointer DOM event. 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.
*/
2016-08-26 00:18:47 +00:00
event: MSPointerEvent;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Phaser Input Manager.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a MSPointerDown event.
*/
2016-08-26 00:18:47 +00:00
pointerDownCallback: (event: MSPointerEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a MSPointerMove event.
*/
2016-08-26 00:18:47 +00:00
pointerMoveCallback: (event: MSPointerEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a MSPointerUp event.
*/
2016-08-26 00:18:47 +00:00
pointerUpCallback: (event: MSPointerEvent) => void;
2016-06-17 11:46:47 +00:00
/**
* Starts the event listeners running.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* Stop the event listeners.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
}
2016-06-17 11:46:47 +00:00
/**
* Phaser.Net handles browser URL related tasks such as checking host names, domain names and query string manipulation.
*/
2016-08-26 00:18:47 +00:00
class Net {
2016-06-17 11:46:47 +00:00
/**
* Phaser.Net handles browser URL related tasks such as checking host names, domain names and query string manipulation.
*
* @param game A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Compares the given domain name against the hostname of the browser containing the game.
* If the domain name is found it returns true.
* You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc.
* Do not include 'http://' at the start.
*
* @param domain
* @return true if the given domain fragment can be found in the window.location.hostname
*/
2016-08-26 00:18:47 +00:00
checkDomainName(domain: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* Takes a Uniform Resource Identifier (URI) component (previously created by encodeURIComponent or by a similar routine) and
* decodes it, replacing \ with spaces in the return. Used internally by the Net classes.
*
* @param value The URI component to be decoded.
* @return The decoded value.
*/
2016-08-26 00:18:47 +00:00
decodeURI(value: string): string;
2016-06-17 11:46:47 +00:00
/**
* Returns the hostname given by the browser.
*/
2016-08-26 00:18:47 +00:00
getHostName(): string;
2016-06-17 11:46:47 +00:00
/**
* Returns the Query String as an object.
* If you specify a parameter it will return just the value of that parameter, should it exist.
*
* @param parameter If specified this will return just the value for that key. - Default: ''
* @return An object containing the key value pairs found in the query string or just the value if a parameter was given.
*/
2016-08-26 00:18:47 +00:00
getQueryString(parameter?: string): string;
2016-06-17 11:46:47 +00:00
/**
* Updates a value on the Query String and returns it in full.
* If the value doesn't already exist it is set.
* If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string.
* Optionally you can redirect to the new url, or just return it as a string.
*
* @param key The querystring key to update.
* @param value The new value to be set. If it already exists it will be replaced.
* @param redirect If true the browser will issue a redirect to the url with the new querystring.
* @param url The URL to modify. If none is given it uses window.location.href.
* @return If redirect is false then the modified url and query string is returned.
*/
2016-08-26 00:18:47 +00:00
updateQueryString(key: string, value: any, redirect?: boolean, url?: string): string;
}
2016-06-17 11:46:47 +00:00
/**
* Create a new `Particle` object. Particles are extended Sprites that are emitted by a particle emitter such as Phaser.Particles.Arcade.Emitter.
*/
2016-08-26 00:18:47 +00:00
class Particle extends Phaser.Sprite {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, key?: any, frame?: any);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* Called by the Emitter when this particle is emitted. Left empty for you to over-ride as required.
*/
2016-08-26 00:18:47 +00:00
onEmit(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.Particle;
2016-06-17 11:46:47 +00:00
/**
* Called by the Emitter if autoAlpha has been enabled. Passes over the alpha ease data and resets the alpha counter.
*/
2016-08-26 00:18:47 +00:00
setAlphaData(data: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Emitter if autoScale has been enabled. Passes over the scale ease data and resets the scale counter.
*/
2016-08-26 00:18:47 +00:00
setScaleData(data: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the Particle scale or alpha if autoScale and autoAlpha are set.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* Phaser.Particles is the Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it.
*/
2016-08-26 00:18:47 +00:00
class Particles {
2016-06-17 11:46:47 +00:00
/**
* Phaser.Particles is the Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it.
*
* @param game A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* Internal emitters store.
*/
2016-08-26 00:18:47 +00:00
emitters: any;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* -
*/
2016-08-26 00:18:47 +00:00
ID: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(emitter: Phaser.Particles.Arcade.Emitter): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* Removes an existing Particle Emitter from the Particle Manager.
*
* @param emitter The emitter to remove.
*/
2016-08-26 00:18:47 +00:00
remove(emitter: Phaser.Particles.Arcade.Emitter): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the core game loop. Updates all Emitters who have their exists value set to true.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
module Particles {
module Arcade {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Emitter extends Phaser.Group {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x?: number, y?: number, maxParticles?: number);
2016-06-17 11:46:47 +00:00
/**
* An array of the calculated alpha easing data applied to particles with alphaRates > 0.
*/
2016-08-26 00:18:47 +00:00
alphaData: any[];
2016-06-17 11:46:47 +00:00
/**
* When a new Particle is emitted this controls if it will automatically change alpha. Use Emitter.setAlpha to configure.
*/
2016-08-26 00:18:47 +00:00
autoAlpha: boolean;
2016-06-17 11:46:47 +00:00
/**
* When a new Particle is emitted this controls if it will automatically scale in size. Use Emitter.setScale to configure.
*/
2016-08-26 00:18:47 +00:00
autoScale: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* The angular drag component of particles launched from the emitter if they are rotating.
*/
2016-08-26 00:18:47 +00:00
angularDrag: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the bottom position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce.
*/
2016-08-26 00:18:47 +00:00
bounce: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
emitX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
emitY: number;
2016-06-17 11:46:47 +00:00
/**
* If exists is true the group is updated, otherwise it is skipped.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* How often a particle is emitted in ms (if emitter is started with Explode === false).
* Default: 100
*/
2016-08-26 00:18:47 +00:00
frequency: number;
2016-06-17 11:46:47 +00:00
/**
* Sets the `body.gravity.y` of each particle sprite to this value on launch.
* Default: 100
*/
2016-08-26 00:18:47 +00:00
gravity: number;
group: Phaser.Group;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the height of the Emitter. This is the region in which a particle can be emitted.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the left position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of particles in this emitter.
*/
2016-08-26 00:18:47 +00:00
maxParticles: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
maxParticleScale: number;
2016-06-17 11:46:47 +00:00
/**
* The maximum possible velocity of a particle.
*/
2016-08-26 00:18:47 +00:00
maxParticleSpeed: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The maximum possible angular velocity of a particle.
* Default: 360
*/
2016-08-26 00:18:47 +00:00
maxRotation: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
minParticleScale: number;
2016-06-17 11:46:47 +00:00
/**
* The minimum possible velocity of a particle.
*/
2016-08-26 00:18:47 +00:00
minParticleSpeed: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The minimum possible angular velocity of a particle.
*/
2016-08-26 00:18:47 +00:00
minRotation: number;
2016-06-17 11:46:47 +00:00
/**
* A handy string name for this emitter. Can be set to anything.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* Determines whether the emitter is currently emitting particles. It is totally safe to directly toggle this.
*/
2016-08-26 00:18:47 +00:00
on: boolean;
2016-07-01 15:57:13 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
particleAnchor: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* If this is `true` then when the Particle is emitted it will be bought to the top of the Emitters display list.
*/
2016-08-26 00:18:47 +00:00
particleBringToTop: boolean;
2016-06-17 11:46:47 +00:00
/**
* If this is `true` then when the Particle is emitted it will be sent to the back of the Emitters display list.
*/
2016-08-26 00:18:47 +00:00
particleSendToBack: boolean;
2016-06-17 11:46:47 +00:00
/**
* For emitting your own particle class types. They must extend Phaser.Particle.
*/
2016-08-26 00:18:47 +00:00
particleClass: any;
2016-06-17 11:46:47 +00:00
/**
* The X and Y drag component of particles launched from the emitter.
*/
2016-08-26 00:18:47 +00:00
particleDrag: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Gets the right position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* An array of the calculated scale easing data applied to particles with scaleRates > 0.
*/
2016-08-26 00:18:47 +00:00
scaleData: any[];
2016-06-17 11:46:47 +00:00
/**
* Gets the top position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* Internal Phaser Type value.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the width of the Emitter. This is the region in which a particle can be emitted.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the x position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the y position of the Emitter.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Change the emitters center to match the center of any object with a `center` property, such as a Sprite.
* If the object doesn't have a center property it will be set to object.x + object.width / 2
*
* @param object The object that you wish to match the center with.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
at(object: any): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
emitParticle(x?: number, y?: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
explode(lifespan?: number, quantity?: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* Call this function to start emitting a flow of particles at the given frequency.
* It will carry on going until the total given is reached.
* Each time the flow is run the quantity number of particles will be emitted together.
* If you set the total to be 20 and quantity to be 5 then flow will emit 4 times in total (4 x 5 = 20 total)
* If you set the total to be -1 then no quantity cap is used and it will keep emitting.
*
* @param lifespan How long each particle lives once emitted in ms. 0 = forever.
* @param frequency Frequency is how often to emit the particles, given in ms. - Default: 250
* @param quantity How many particles to launch each time the frequency is met. Can never be > Emitter.maxParticles. - Default: 1
* @param total How many particles to launch 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.
*/
2016-08-26 00:18:47 +00:00
flow(lifespan?: number, frequency?: number, quantity?: number, total?: number, immediate?: boolean): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* Call this function to turn off all the particles and the emitter.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
kill(): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
makeParticles(keys: any, frames?: any, quantity?: number, collide?: boolean, collideWorldBounds?: boolean): Phaser.Particles.Arcade.Emitter;
reset(x: number, y: number, health?: number): Phaser.Particles;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setAlpha(min?: number, max?: number, rate?: number, ease?: (k: number) => number, yoyo?: boolean): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setRotation(min?: number, max?: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setScale(minX?: number, maxX?: number, minY?: number, maxY?: number, rate?: number, ease?: (k: number) => number, yoyo?: boolean): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setSize(width: number, height: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setXSpeed(min: number, max: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setYSpeed(min: number, max: number): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* Call this function to start emitting particles.
*
* @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 Ignored if Explode is set to true. Frequency is how often to emit 1 particle. Value given in ms. - Default: 250
* @param quantity How many particles to launch. 0 = "all of the particles" which will keep emitting until Emitter.maxParticles is reached.
* @param forceQuantity If `true` and creating a particle flow, the quantity emitted will be forced to the be quantity given in this call. This can never exceed Emitter.maxParticles.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
start(explode?: boolean, lifespan?: number, frequency?: number, quantity?: number, forceQuantity?: boolean): Phaser.Particles.Arcade.Emitter;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by the game loop, decides when to launch particles and when to "die".
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
* @return This Emitter instance.
*/
2016-08-26 00:18:47 +00:00
revive(): Phaser.Particles.Arcade.Emitter;
}
}
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Physics {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, config?: any);
static ARCADE: number;
static P2JS: number;
static NINJA: number;
static BOX2D: number;
static CHIPMUNK: number;
static MATTERJS: number;
2016-06-17 11:46:47 +00:00
/**
* The Arcade Physics system.
*/
2016-08-26 00:18:47 +00:00
arcade: Phaser.Physics.Arcade;
2016-06-17 11:46:47 +00:00
/**
* The physics configuration object as passed to the game on creation.
*/
2016-08-26 00:18:47 +00:00
config: any;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The N+ Ninja Physics system.
*/
2016-08-26 00:18:47 +00:00
ninja: Phaser.Physics.Ninja;
2016-06-17 11:46:47 +00:00
/**
* The P2.JS Physics system.
*/
2016-08-26 00:18:47 +00:00
p2: Phaser.Physics.P2;
2016-06-17 11:46:47 +00:00
/**
* The Box2D Physics system.
*/
2016-08-26 00:18:47 +00:00
box2d: any;
2016-06-17 11:46:47 +00:00
/**
* Clears down all active physics systems. This doesn't destroy them, it just clears them of objects and is called when the State changes.
*/
2016-08-26 00:18:47 +00:00
clear(): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys all active physics systems. Usually only called on a Game Shutdown, not on a State swap.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enable(object: any, system?: number, debug?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Parses the Physics Configuration object passed to the Game constructor and starts any physics systems specified within.
*/
2016-08-26 00:18:47 +00:00
parseConfig(): void;
2016-06-17 11:46:47 +00:00
/**
* preUpdate checks.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the active physics system. Called automatically on a Phaser.State swap.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the physics bounds to match the world dimensions.
*/
2016-08-26 00:18:47 +00:00
setBoundsToWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
startSystem(system: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates all running physics systems.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
export class Video {
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The key of the Video in the Cache, if stored there. Will be `null` if this Video is using the webcam instead.
* Default: null
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* The HTML Video Element that is added to the document.
*/
2016-08-26 00:18:47 +00:00
video: HTMLVideoElement;
baseTexture: PIXI.BaseTexture;
2016-06-17 11:46:47 +00:00
/**
* The PIXI.Texture.
*/
2016-08-26 00:18:47 +00:00
texture: PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* The Frame this video uses for rendering.
*/
2016-08-26 00:18:47 +00:00
textureFrame: Phaser.Frame;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* If true this video will never send its image data to the GPU when its dirty flag is true. This only applies in WebGL.
*/
2016-08-26 00:18:47 +00:00
disableTextureUpload: boolean;
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* The current time of the video in seconds. If set the video will attempt to seek to that point in time.
*/
2016-08-26 00:18:47 +00:00
currentTime: number;
2016-06-17 11:46:47 +00:00
/**
* The duration of the video in seconds.
*/
2016-08-26 00:18:47 +00:00
duration: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
progress: number;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the muted state of the Video.
*/
2016-08-26 00:18:47 +00:00
mute: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
volume: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the playback rate of the Video. This is the speed at which the video is playing.
*/
2016-08-26 00:18:47 +00:00
playbackRate: boolean;
2016-06-17 11:46:47 +00:00
/**
* True if the video is currently playing (and not paused or ended), otherwise false.
*/
2016-08-26 00:18:47 +00:00
playing: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
loop: boolean;
2016-06-17 11:46:47 +00:00
/**
* The width of the video in pixels.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the video in pixels.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The Video Stream data. Only set if this Video is streaming from the webcam via `startMediaStream`.
*/
2016-08-26 00:18:47 +00:00
videoStream: any;
2016-06-17 11:46:47 +00:00
/**
* Is there a streaming video source? I.e. from a webcam.
*/
2016-08-26 00:18:47 +00:00
isStreaming: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
snapshot: Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* The amount of ms allowed to elapsed before the Video.onTimeout signal is dispatched while waiting for webcam access.
* Default: 15000
*/
2016-08-26 00:18:47 +00:00
timeout: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
retryLimit: number;
2016-06-17 11:46:47 +00:00
/**
* The current retry attempt.
*/
2016-08-26 00:18:47 +00:00
retry: number;
2016-06-17 11:46:47 +00:00
/**
* The number of ms between each retry at monitoring the status of a downloading video.
* Default: 500
*/
2016-08-26 00:18:47 +00:00
retryInterval: number;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched if the user allows access to their webcam.
*/
2016-08-26 00:18:47 +00:00
onAccess: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onError: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onPlay: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onComplete: Phaser.Signal;
onUpdate: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onTimeout: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* true if this video is currently locked awaiting a touch event. This happens on some mobile devices, such as iOS.
*/
2016-08-26 00:18:47 +00:00
touchLocked: boolean;
complete: () => void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, key?: string, url?: string);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(object: Phaser.Sprite | Phaser.Sprite[] | Phaser.Image | Phaser.Image[]): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addToWorld(x?: number, y?: number, anchorX?: number, anchorY?: Number, scaleX?: number, scaleY?: number): Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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: `Blob([new Uint8Array(data)])`
* @return This Video object for method chaining.
*/
2016-08-26 00:18:47 +00:00
createVideoFromBlob(blob: Blob): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return This Video object for method chaining or false if the device doesn't support getUserMedia.
*/
2016-08-26 00:18:47 +00:00
startMediaStream(captureAudio?: boolean, width?: number, height?: number): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* Creates a new Video element from the given URL.
*
* @param url The URL of the video.
* @param autoplay Automatically start the video?
* @return This Video object for method chaining.
*/
2016-08-26 00:18:47 +00:00
createVideoFromURL(url: string, autoplay?: boolean): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
changeSource(src: string, autoplay?: boolean): Phaser.Video;
connectToMediaStram(video: any, stream: any): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Starts this video playing if it's not already doing so.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
play(loop?: boolean, playbackRate?: number): Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* Called when the video starts to play. Updates the texture.
*/
2016-08-26 00:18:47 +00:00
playHandler(): void;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
render(): void;
2016-06-17 11:46:47 +00:00
/**
* Removes the Video element from the DOM by calling parentNode.removeChild on itself.
* Also removes the autoplay and src attributes and nulls the reference.
*/
2016-08-26 00:18:47 +00:00
removeVideoElement(): void;
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the Input Manager touch callback to be Video.unlock.
* Required for mobile video unlocking. Mostly just used internally.
*/
2016-08-26 00:18:47 +00:00
setTouchLock(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
grab(clear?: boolean, alpha?: number, blendMode?: string): Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
unlock(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateTexture(event?: any, width?: number, height?: number): void;
}
module Physics {
2016-06-17 11:46:47 +00:00
/**
* The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods.
*/
2016-08-26 00:18:47 +00:00
class Arcade {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static SORT_NONE: number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static LEFT_RIGHT: number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static RIGHT_LEFT: number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static TOP_BOTTOM: number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static BOTTOM_TOP: number;
2016-06-17 11:46:47 +00:00
/**
* A value added to the delta values during collision checks.
*/
2016-08-26 00:18:47 +00:00
static OVERLAP_BIAS: number;
static TILE_BIAS: number;
2016-06-17 11:46:47 +00:00
/**
* The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods.
*
* @param game reference to the current game instance.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* The bounds inside of which the physics world exists. Defaults to match the world bounds.
*/
2016-08-26 00:18:47 +00:00
bounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Set the checkCollision properties to control for which bounds collision is processed.
* For example checkCollision.down = false means Bodies cannot collide with the World.bounds.bottom. An object containing allowed collision flags.
*/
2016-08-26 00:18:47 +00:00
checkCollision: { up?: boolean; down?: boolean; left?: boolean; right?: boolean; };
2016-06-17 11:46:47 +00:00
/**
* If true World.separate will always separate on the X axis before Y. Otherwise it will check gravity totals first.
*/
2016-08-26 00:18:47 +00:00
forceX: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The World gravity setting. Defaults to x: 0, y: 0, or no gravity.
*/
2016-08-26 00:18:47 +00:00
gravity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The world QuadTree.
*/
2016-08-26 00:18:47 +00:00
quadTree: Phaser.QuadTree;
2016-06-17 11:46:47 +00:00
/**
* Used by the QuadTree to set the maximum number of objects per quad.
*/
2016-08-26 00:18:47 +00:00
maxObjects: number;
2016-06-17 11:46:47 +00:00
/**
* Used by the QuadTree to set the maximum number of iteration levels.
*/
2016-08-26 00:18:47 +00:00
maxLevels: number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
skipQuadTree: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sortDirection: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
accelerationFromRotation(rotation: number, speed?: number, point?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
accelerateToObject(displayObject: any, destination: any, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
accelerateToPointer(displayObject: any, pointer?: Phaser.Pointer, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
accelerateToXY(displayObject: any, x: number, y: number, speed?: number, xSpeedMax?: number, ySpeedMax?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angleBetween(source: any, target: any, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
angleToPointer(displayObject: any, pointer?: Phaser.Pointer, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
angleToXY(displayObject: any, x: number, y: number, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
* 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.
* 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.
* NOTE: This function is not recursive, and will not test against children of objects passed (i.e. Groups or Tilemaps within other Groups).
*
* @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.
*/
2016-08-26 00:18:47 +00:00
collide(object1: any, object2?: any, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
computeVelocity(axis: number, body: Phaser.Physics.Arcade.Body, velocity: number, acceleration: number, drag: number, max?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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)
* @return The distance between the source and target objects.
*/
2016-08-26 00:18:47 +00:00
distanceBetween(source: any, target: any, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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 the method distanceBetweenCenters()
*
* 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.
*/
2016-08-26 00:18:47 +00:00
distanceToPointer(displayObject: any, pointer?: Phaser.Pointer, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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 the method distanceBetweenCenters()
*
* 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.
*/
2016-08-26 00:18:47 +00:00
distanceToXY(displayObject: any, x: number, y: number, world?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enable(object: any, children?: Boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enableBody(object: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getObjectsAtLocation(x: number, y: number, group: Phaser.Group, callback?: (callbackArg: any, object: any) => void, callbackContext?: any, callbackArg?: any): Sprite[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getOverlapX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getOverlapY(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersects(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveToObject(displayObject: any, destination: any, speed?: number, maxTime?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveToPointer(displayObject: any, speed?: number, pointer?: Phaser.Pointer, maxTime?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveToXY(displayObject: any, x: number, y: number, speed?: number, maxTime?: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
* 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.
* NOTE: This function is not recursive, and will not test against children of objects passed (i.e. Groups within Groups).
*
* @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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setBounds(x: number, y: number, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the size of this physics world to match the size of the game world.
*/
2016-08-26 00:18:47 +00:00
setBoundsToWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
separate(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, processCallback?: Function, callbackContext?: any, overlapOnly?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
separateX(body1: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, overlapOnly: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateMotion(body: Phaser.Physics.Arcade.Body): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
velocityFromAngle(angle: number, speed?: number, point?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
velocityFromRotation(rotation: number, speed?: number, point?: Phaser.Point): Phaser.Point;
}
module Arcade {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Body {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(sprite: Phaser.Sprite);
2016-06-17 11:46:47 +00:00
/**
* The acceleration is the rate of change of the velocity. Measured in pixels per second squared.
*/
2016-08-26 00:18:47 +00:00
acceleration: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Allow this Body to be influenced by gravity? Either world or local.
* Default: true
*/
2016-08-26 00:18:47 +00:00
allowGravity: boolean;
2016-06-17 11:46:47 +00:00
/**
* Allow this Body to be rotated? (via angularVelocity, etc)
* Default: true
*/
2016-08-26 00:18:47 +00:00
allowRotation: boolean;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The angle of the Body's velocity in radians.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The angular acceleration is the rate of change of the angular velocity. Measured in degrees per second squared.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
angularAcceleration: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The drag applied during the rotation of the Body. Measured in degrees per second squared.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
angularDrag: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The angular velocity controls the rotation speed of the Body. It is measured in degrees per second.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
angularVelocity: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
blocked: FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The bottom value of this Body (same as Body.y + Body.height)
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* The elasticity of the Body when colliding. bounce.x/y = 1 means full rebound, bounce.x/y = 0.5 means 50% rebound velocity.
*/
2016-08-26 00:18:47 +00:00
bounce: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The center coordinate of the Physics Body.
*/
2016-08-26 00:18:47 +00:00
center: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Set the checkCollision properties to control which directions collision is processed for this Body.
2016-08-26 00:18:47 +00:00
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
checkCollision: FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
customSeparateX: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
customSeparateY: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Sprite position is updated based on the delta x/y values. You can set a cap on those (both +-) using deltaMax.
*/
2016-08-26 00:18:47 +00:00
deltaMax: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* If this Body in a preUpdate (true) or postUpdate (false) state?
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* The drag applied to the motion of the Body.
*/
2016-08-26 00:18:47 +00:00
drag: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
embedded: boolean;
2016-06-17 11:46:47 +00:00
/**
* A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run.
* Default: true
*/
2016-08-26 00:18:47 +00:00
enable: boolean;
2016-06-17 11:46:47 +00:00
/**
* A const reference to the direction the Body is traveling or facing.
*/
2016-08-26 00:18:47 +00:00
facing: number;
2016-06-17 11:46:47 +00:00
/**
* The amount of movement that will occur if another object 'rides' this one.
*/
2016-08-26 00:18:47 +00:00
friction: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A local gravity applied to this Body. If non-zero this over rides any world gravity, unless Body.allowGravity is set to false.
*/
2016-08-26 00:18:47 +00:00
gravity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The calculated width / 2 of the physics body.
*/
2016-08-26 00:18:47 +00:00
halfWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The calculated height / 2 of the physics body.
*/
2016-08-26 00:18:47 +00:00
halfHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The calculated height of the physics body.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* An immovable Body will not receive any impacts from other bodies.
*/
2016-08-26 00:18:47 +00:00
immovable: boolean;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isCircle: boolean;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* Set by the `moveTo` and `moveFrom` methods.
*/
2016-08-26 00:18:47 +00:00
isMoving: boolean;
2016-06-17 11:46:47 +00:00
/**
* The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity.
* Default: 1
*/
2016-08-26 00:18:47 +00:00
mass: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The maximum angular velocity in degrees per second that the Body can reach.
2016-06-17 11:46:47 +00:00
* Default: 1000
*/
2016-08-26 00:18:47 +00:00
maxAngular: number;
2016-06-17 11:46:47 +00:00
/**
* The maximum velocity in pixels per second sq. that the Body can reach.
*/
2016-08-26 00:18:47 +00:00
maxVelocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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. Set to true to allow the Physics system to move this Body, otherwise false to move it manually.
* Default: true
*/
2016-08-26 00:18:47 +00:00
moves: boolean;
2016-06-17 11:46:47 +00:00
/**
* Optional callback. If set, invoked during the running of `moveTo` or `moveFrom` events.
*/
2016-08-26 00:18:47 +00:00
movementCallback: any;
2016-06-17 11:46:47 +00:00
/**
* Context in which to call the movementCallback.
*/
2016-08-26 00:18:47 +00:00
movementCallbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* The new velocity. Calculated during the Body.preUpdate and applied to its position.
*/
2016-08-26 00:18:47 +00:00
newVelocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The offset of the Physics Body from the Sprite x/y position.
*/
2016-08-26 00:18:47 +00:00
offset: Phaser.Point;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onCollide: Phaser.Signal;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* Listen for the completion of `moveTo` or `moveFrom` events.
*/
2016-08-26 00:18:47 +00:00
onMoveComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onOverlap: Phaser.Signal;
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onWorldBounds: Phaser.Signal;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* When this body collides with another, the amount of overlap is stored here. The amount of horizontal overlap during the collision.
*/
2016-08-26 00:18:47 +00:00
overlapX: number;
2016-06-17 11:46:47 +00:00
/**
* When this body collides with another, the amount of overlap is stored here. The amount of vertical overlap during the collision.
*/
2016-08-26 00:18:47 +00:00
overlapY: number;
phase: number;
2016-06-17 11:46:47 +00:00
/**
* The position of the physics body.
*/
2016-08-26 00:18:47 +00:00
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The previous rotation of the physics body.
*/
2016-08-26 00:18:47 +00:00
preRotation: number;
2016-06-17 11:46:47 +00:00
/**
* The previous position of the physics body.
*/
2016-08-26 00:18:47 +00:00
prev: Phaser.Point;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* The radius of the circular collision shape this Body is using if Body.setCircle has been enabled.
* If you wish to change the radius then call `setCircle` again with the new value.
* If you wish to stop the Body using a circle then call `setCircle` with a radius of zero (or undefined).
*/
2016-08-26 00:18:47 +00:00
radius: number;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* The right value of this Body (same as Body.x + Body.width)
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* The Body's rotation in degrees, as calculated by its angularVelocity and angularAcceleration. Please understand that the collision Body
2016-06-17 11:46:47 +00:00
* itself never rotates, it is always axis-aligned. However these values are passed up to the parent Sprite and updates its rotation.
*/
2016-08-26 00:18:47 +00:00
rotation: number;
2016-06-17 11:46:47 +00:00
/**
* If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree.
*/
2016-08-26 00:18:47 +00:00
skipQuadTree: boolean;
2016-06-17 11:46:47 +00:00
/**
* The un-scaled original size.
*/
2016-08-26 00:18:47 +00:00
sourceWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The un-scaled original size.
*/
2016-08-26 00:18:47 +00:00
sourceHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The speed of the Body as calculated by its velocity.
*/
2016-08-26 00:18:47 +00:00
speed: number;
2016-06-17 11:46:47 +00:00
/**
* Reference to the parent Sprite.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Set by the `moveTo` and `moveFrom` methods.
*/
2016-08-26 00:18:47 +00:00
stopVelocityOnCollide: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
syncBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tilePadding: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
touching: FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The type of physics system this body belongs to.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* This object is populated with previous touching values from the bodies previous collision. An object containing previous touching results.
*/
2016-08-26 00:18:47 +00:00
wasTouching: FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The calculated width of the physics body.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
worldBounce: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The velocity, or rate of change in speed of the Body. Measured in pixels per second.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The x position.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y position.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Internal method.
2016-07-08 14:46:26 +00:00
* @return True if the Body collided with the world bounds, otherwise false.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaX(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaY(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaZ(): number;
2016-06-17 11:46:47 +00:00
/**
* Returns the absolute delta x value.
* @return The absolute delta value.
*/
2016-08-26 00:18:47 +00:00
deltaAbsX(): number;
2016-06-17 11:46:47 +00:00
/**
* Returns the absolute delta y value.
* @return The absolute delta value.
*/
2016-08-26 00:18:47 +00:00
deltaAbsY(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBounds(obj: any): any;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hitTest(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveFrom(duration: number, speed?: number, direction?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveTo(duration: number, distance: number, direction?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onFloor(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onWall(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Internal method.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
render(context: any, body: Phaser.Physics.Arcade.Body, color?: string, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
renderBodyInfo(debug: Phaser.Utils.Debug, body: Phaser.Physics.Arcade.Body): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number): void;
2016-06-17 11:46:47 +00:00
2016-07-08 14:46:26 +00:00
/**
* 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 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.
*
* 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 Sprite position.
* @param offsetY The Y offset of the Body from the Sprite position.
*/
2016-08-26 00:18:47 +00:00
setCircle(radius: number, offsetX?: number, offsetY?: number): void;
2016-07-08 14:46:26 +00:00
2016-06-17 11:46:47 +00:00
/**
* 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. 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, 32, 24, 34)`
*
* Where the first two parameters is the new Body size (32x32 pixels).
* 24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34
* is the vertical offset.
*
2016-07-08 14:46:26 +00:00
* Calling `setSize` on a Body that has already had `setCircle` will reset all of the Circle
* properties, making this Body rectangular again.
*
2016-06-17 11:46:47 +00:00
* @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.
*/
2016-08-26 00:18:47 +00:00
setSize(width: number, height: number, offsetX?: number, offsetY?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method.
*/
2016-08-26 00:18:47 +00:00
updateBounds(): boolean;
}
class FaceChoices {
none: boolean;
any: boolean;
up: boolean;
down: boolean;
left: boolean;
right: boolean;
}
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Ninja {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The World gravity setting.
*/
2016-08-26 00:18:47 +00:00
gravity: number;
2016-06-17 11:46:47 +00:00
/**
* The bounds inside of which the physics world exists. Defaults to match the world bounds.
*/
2016-08-26 00:18:47 +00:00
bounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Used by the QuadTree to set the maximum number of objects per quad.
*/
2016-08-26 00:18:47 +00:00
maxObjects: number;
2016-06-17 11:46:47 +00:00
/**
* Used by the QuadTree to set the maximum number of iteration levels.
*/
2016-08-26 00:18:47 +00:00
maxLevels: number;
2016-06-17 11:46:47 +00:00
/**
* The world QuadTree.
*/
2016-08-26 00:18:47 +00:00
quadTree: Phaser.QuadTree;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.time.
*/
2016-08-26 00:18:47 +00:00
time: Phaser.Time;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clearTilemapLayerBodies(map: Phaser.Tilemap, layer: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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 occured otherwise false.
*/
2016-08-26 00:18:47 +00:00
collide(object1: any, object2: any, collideCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
convertTilemap(map: Phaser.Tilemap, layer: any, slopeMap: any): Phaser.Physics.Ninja.Tile[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enableAABB(object: any, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enableCircle(object: any, radius: number, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enableTile(object: any, id: number, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enable(object: any, type?: number, id?: number, radius?: number, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enableBody(object: any, type?: number, id?: number, radius?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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 occured otherwise false.
*/
2016-08-26 00:18:47 +00:00
overlap(object1: any, object2: any, overlapCallback?: Function, processCallback?: Function, callbackContext?: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
separate(body1: Phaser.Physics.Ninja.Body, body2: Phaser.Physics.Ninja.Body, processCallback?: Function, callbackContext?: any, overlapOnly?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setBounds(x: number, y: number, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the size of this physics world to match the size of the game world.
*/
2016-08-26 00:18:47 +00:00
setBoundsToWorld(): void;
}
module Ninja {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Body {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(system: Phaser.Physics.Ninja, sprite: Phaser.Sprite, type?: number, id?: number, radius?: number, x?: number, y?: number, width?: number, height?: number);
2016-06-17 11:46:47 +00:00
/**
* The AABB object this body is using for collision.
*/
2016-08-26 00:18:47 +00:00
aabb: Phaser.Physics.Ninja.AABB;
2016-06-17 11:46:47 +00:00
/**
* The angle of this Body
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* The bottom value of this Body (same as Body.y + Body.height)
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
bounce: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkCollision: Phaser.Physics.Arcade.FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The Circle object this body is using for collision.
*/
2016-08-26 00:18:47 +00:00
circle: Phaser.Physics.Ninja.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* The drag applied to this object as it moves.
* Default: 1
*/
2016-08-26 00:18:47 +00:00
drag: number;
2016-06-17 11:46:47 +00:00
/**
* A const reference to the direction the Body is traveling or facing.
*/
2016-08-26 00:18:47 +00:00
facing: number;
2016-06-17 11:46:47 +00:00
/**
* The friction applied to this object as it moves.
* Default: 0.05
*/
2016-08-26 00:18:47 +00:00
friction: number;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* How much of the world gravity should be applied to this object? 1 = all of it, 0.5 = 50%, etc.
* Default: 1
*/
2016-08-26 00:18:47 +00:00
gravityScale: number;
2016-06-17 11:46:47 +00:00
/**
* The height of this Body
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* An immovable Body will not receive any impacts from other bodies. Not fully implemented.
*/
2016-08-26 00:18:47 +00:00
immovable: boolean;
2016-06-17 11:46:47 +00:00
/**
* The maximum speed this body can travel at (taking drag and friction into account)
* Default: 8
*/
2016-08-26 00:18:47 +00:00
maxSpeed: number;
2016-06-17 11:46:47 +00:00
/**
* The right value of this Body (same as Body.x + Body.width)
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* Reference to the parent Sprite.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* The parent physics system.
*/
2016-08-26 00:18:47 +00:00
system: Phaser.Physics.Ninja;
2016-06-17 11:46:47 +00:00
/**
* The Tile object this body is using for collision.
*/
2016-08-26 00:18:47 +00:00
tile: Phaser.Physics.Ninja.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
touching: Phaser.Physics.Arcade.FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The type of physics system this body belongs to.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* A local reference to the body shape.
*/
2016-08-26 00:18:47 +00:00
shape: any;
2016-06-17 11:46:47 +00:00
/**
* The speed of this Body
*/
2016-08-26 00:18:47 +00:00
speed: number;
2016-06-17 11:46:47 +00:00
/**
* The velocity in pixels per second sq. of the Body.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* This object is populated with previous touching values from the bodies previous collision. An object containing previous touching results.
*/
2016-08-26 00:18:47 +00:00
wasTouching: Phaser.Physics.Arcade.FaceChoices;
2016-06-17 11:46:47 +00:00
/**
* The width of this Body
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The x position.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y position.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Returns the absolute delta x value.
* @return The absolute delta value.
*/
2016-08-26 00:18:47 +00:00
deltaAbsX(): number;
2016-06-17 11:46:47 +00:00
/**
* Returns the absolute delta y value.
* @return The absolute delta value.
*/
2016-08-26 00:18:47 +00:00
deltaAbsY(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaX(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaY(): number;
2016-06-17 11:46:47 +00:00
/**
* Destroys this body's reference to the sprite and system, and destroys its shape.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Stops all movement of this body.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Internal method.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
render(context: any, body: Phaser.Physics.Ninja.Body, color?: string, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Resets all Body values and repositions on the Sprite.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
}
2016-06-17 11:46:47 +00:00
/**
* Ninja Physics AABB constructor.
* Note: This class could be massively optimised and reduced in size. I leave that challenge up to you.
*/
2016-08-26 00:18:47 +00:00
class AABB {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* All of the collision response handlers.
*/
2016-08-26 00:18:47 +00:00
aabbTileProjections: any;
2016-06-17 11:46:47 +00:00
/**
* A reference to the body that owns this shape.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Ninja.Body;
2016-06-17 11:46:47 +00:00
/**
* The height.
*/
2016-08-26 00:18:47 +00:00
height: number;
oldPos: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position of this object.
*/
2016-08-26 00:18:47 +00:00
pos: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* A reference to the physics system.
*/
2016-08-26 00:18:47 +00:00
system: Phaser.Physics.Ninja;
2016-06-17 11:46:47 +00:00
/**
* The width.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The velocity of this object.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Half the width.
*/
2016-08-26 00:18:47 +00:00
xw: number;
2016-06-17 11:46:47 +00:00
/**
* Half the height.
*/
2016-08-26 00:18:47 +00:00
yw: number;
2016-06-17 11:46:47 +00:00
/**
* Collides this AABB against the world bounds.
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds(): void;
2016-06-17 11:46:47 +00:00
/**
* Collides this AABB against a AABB.
*
* @param aabb The AABB to collide against.
*/
2016-08-26 00:18:47 +00:00
collideAABBVsAABB(aabb: Phaser.Physics.Ninja.AABB): boolean;
2016-06-17 11:46:47 +00:00
/**
* Collides this AABB against a Tile.
*
* @param tile The Tile to collide against.
*/
2016-08-26 00:18:47 +00:00
collideAABBVsTile(tile: Phaser.Physics.Ninja.Tile): boolean;
2016-06-17 11:46:47 +00:00
/**
* Destroys this AABB's reference to Body and System
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates this AABBs position.
*/
2016-08-26 00:18:47 +00:00
integrate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
render(context: any, xOffset: number, yOffset: number, color: string, filled: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reportCollision(px: number, py: number, dx: number, dy: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reportCollisionVsBody(px: number, py: number, dx: number, dy: number, obj: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resolveTile(x: number, y: number, body: Phaser.Physics.Ninja.AABB, tile: Phaser.Physics.Ninja.Tile): boolean;
reverse(): void;
}
2016-06-17 11:46:47 +00:00
/**
* Ninja Physics Circle constructor.
* Note: This class could be massively optimised and reduced in size. I leave that challenge up to you.
*/
2016-08-26 00:18:47 +00:00
class Circle {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(body: Phaser.Physics.Ninja.Body, x: number, y: number, radius: number);
COL_NONE: number;
COL_AXIS: number;
COL_OTHER: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the body that owns this shape.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Ninja.Body;
2016-06-17 11:46:47 +00:00
/**
* All of the collision response handlers.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* The height.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The position of this object.
*/
2016-08-26 00:18:47 +00:00
pos: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The radius of this circle shape.
*/
2016-08-26 00:18:47 +00:00
radius: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the physics system.
*/
2016-08-26 00:18:47 +00:00
system: Phaser.Physics.Ninja;
type: number;
2016-06-17 11:46:47 +00:00
/**
* The velocity of this object.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The width.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Half the width.
*/
2016-08-26 00:18:47 +00:00
xw: number;
2016-06-17 11:46:47 +00:00
/**
* Half the height.
*/
2016-08-26 00:18:47 +00:00
yw: number;
2016-06-17 11:46:47 +00:00
/**
* Collides this Circle with a Tile.
*
* @param t The Tile involved in the collision.
* @return True if they collide, otherwise false.
*/
2016-08-26 00:18:47 +00:00
collideCircleVsTile(tile: Phaser.Physics.Ninja.Tile): boolean;
2016-06-17 11:46:47 +00:00
/**
* Collides this Circle against the world bounds.
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds(): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys this Circle's reference to Body and System
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
distance(dest: number, round?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* Updates this Circles position.
*/
2016-08-26 00:18:47 +00:00
integrate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
render(context: any, xOffset: number, yOffset: number, color: string, filled: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void;
reportCollisionVsBody(px: number, py: number, dx: number, dy: number, obj: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Tile {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(body: Phaser.Physics.Ninja.Body, x: number, y: number, width: number, height: number, type?: number);
2016-06-17 11:46:47 +00:00
/**
* A reference to the body that owns this shape.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Ninja.Body;
2016-06-17 11:46:47 +00:00
/**
* The bottom value of this Body (same as Body.y + Body.height)
*/
2016-08-26 00:18:47 +00:00
bottom: number;
flipped: boolean;
2016-06-17 11:46:47 +00:00
/**
* The height.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The ID of this Tile.
*/
2016-08-26 00:18:47 +00:00
id: number;
2016-06-17 11:46:47 +00:00
/**
* The position of this object in the previous update.
*/
2016-08-26 00:18:47 +00:00
oldpos: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position of this object.
*/
2016-08-26 00:18:47 +00:00
pos: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The right value of this Body (same as Body.x + Body.width)
*/
2016-08-26 00:18:47 +00:00
right: number;
rotation: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the physics system.
*/
2016-08-26 00:18:47 +00:00
system: Phaser.Physics.Ninja;
2016-06-17 11:46:47 +00:00
/**
* The type of this Tile.
*/
2016-08-26 00:18:47 +00:00
type: Phaser.Physics.Ninja.TileType;
2016-06-17 11:46:47 +00:00
/**
* The velocity of this object.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The width.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Half the width.
*/
2016-08-26 00:18:47 +00:00
xw: number;
2016-06-17 11:46:47 +00:00
/**
* Half the height.
*/
2016-08-26 00:18:47 +00:00
yw: number;
2016-06-17 11:46:47 +00:00
/**
* The x position.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y position.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Sets this tile to be empty.
*/
2016-08-26 00:18:47 +00:00
clear(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds(): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys this Tiles reference to Body and System.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates this objects position.
*/
2016-08-26 00:18:47 +00:00
integrate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setType(id: number): number;
}
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class P2 {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, config?: any);
2016-06-17 11:46:47 +00:00
/**
* Enable to automatically apply body damping each step.
*/
2016-08-26 00:18:47 +00:00
applyDamping: boolean;
2016-06-17 11:46:47 +00:00
/**
* Enable to automatically apply gravity each step.
*/
2016-08-26 00:18:47 +00:00
applyGravity: boolean;
2016-06-17 11:46:47 +00:00
/**
* Enable to automatically apply spring forces each step.
*/
2016-08-26 00:18:47 +00:00
applySpringForces: boolean;
2016-06-17 11:46:47 +00:00
/**
* An array of the bodies the world bounds collides with.
*/
2016-08-26 00:18:47 +00:00
boundsCollidesWith: Phaser.Physics.P2.Body[];
2016-06-17 11:46:47 +00:00
/**
* A default collision group.
*/
2016-08-26 00:18:47 +00:00
boundsCollisionGroup: Phaser.Physics.P2.CollisionGroup;
2016-06-17 11:46:47 +00:00
/**
* The p2 World configuration object.
*/
2016-08-26 00:18:47 +00:00
config: any;
2016-06-17 11:46:47 +00:00
/**
* The context under which the callbacks are fired.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* An array containing the collision groups that have been defined in the World.
*/
2016-08-26 00:18:47 +00:00
collisionGroups: Phaser.Physics.P2.CollisionGroup[];
2016-06-17 11:46:47 +00:00
/**
* The default Contact Material being used by the World.
*/
2016-08-26 00:18:47 +00:00
contactMaterial: Phaser.Physics.P2.ContactMaterial;
2016-06-17 11:46:47 +00:00
/**
* Set to true if you want to the world to emit the "impact" event. Turning this off could improve performance.
*/
2016-08-26 00:18:47 +00:00
emitImpactEvent: boolean;
2016-06-17 11:46:47 +00:00
/**
* A default collision group.
*/
2016-08-26 00:18:47 +00:00
everythingCollisionGroup: Phaser.Physics.P2.CollisionGroup;
2016-06-17 11:46:47 +00:00
/**
* The frame rate the world will be stepped at. Defaults to 1 / 60, but you can change here. Also see useElapsedTime property.
*/
2016-08-26 00:18:47 +00:00
frameRate: number;
2016-06-17 11:46:47 +00:00
/**
* Friction between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.
*/
2016-08-26 00:18:47 +00:00
friction: number;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The gravity applied to all bodies each step.
*/
2016-08-26 00:18:47 +00:00
gravity: Phaser.Physics.P2.InversePointProxy;
2016-06-17 11:46:47 +00:00
/**
* A local array of all created Materials.
*/
2016-08-26 00:18:47 +00:00
materials: Phaser.Physics.P2.Material[];
2016-06-17 11:46:47 +00:00
/**
* A default collision group.
*/
2016-08-26 00:18:47 +00:00
nothingCollisionGroup: Phaser.Physics.P2.CollisionGroup;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onBodyAdded: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onBodyRemoved: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onBeginContact: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onConstraintAdded: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onConstraintRemoved: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onContactMaterialAdded: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onContactMaterialRemoved: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onEndContact: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onSpringAdded: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onSpringRemoved: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The paused state of the P2 World.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
postBroaddphaseCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* Default coefficient of restitution between colliding bodies. This value is used if no matching ContactMaterial is found for a Material pair.
*/
2016-08-26 00:18:47 +00:00
restitution: number;
2016-06-17 11:46:47 +00:00
/**
* Enable/disable constraint solving in each step.
*/
2016-08-26 00:18:47 +00:00
solveConstraints: boolean;
2016-06-17 11:46:47 +00:00
/**
* The World time.
*/
2016-08-26 00:18:47 +00:00
time: any;
2016-06-17 11:46:47 +00:00
/**
* The total number of bodies in the world.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* If true the frameRate value will be ignored and instead p2 will step with the value of Game.Time.physicsElapsed, which is a delta time value.
*/
2016-08-26 00:18:47 +00:00
useElapsedTime: boolean;
2016-06-17 11:46:47 +00:00
/**
* An object containing the 4 wall bodies that bound the physics world.
*/
2016-08-26 00:18:47 +00:00
walls: {
left?: Phaser.Physics.P2.Body;
right?: Phaser.Physics.P2.Body;
top?: Phaser.Physics.P2.Body;
bottom?: Phaser.Physics.P2.Body;
};
2016-06-17 11:46:47 +00:00
/**
* The p2 World in which the simulation is run.
*/
2016-08-26 00:18:47 +00:00
world: p2.World;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addBody(body: Phaser.Physics.P2.Body): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addContactMaterial(material: Phaser.Physics.P2.ContactMaterial): Phaser.Physics.P2.ContactMaterial;
2016-06-17 11:46:47 +00:00
/**
* Adds a Constraint to the world.
*
* @param constraint The Constraint to add to the World.
* @return The Constraint that was added.
*/
2016-08-26 00:18:47 +00:00
addConstraint<T>(constraint: T): T;
2016-06-17 11:46:47 +00:00
/**
* Adds a Spring to the world.
*
* @param spring The Spring to add to the World.
* @return The Spring that was added.
*/
2016-08-26 00:18:47 +00:00
addSpring(spring: Phaser.Physics.P2.Spring): Phaser.Physics.P2.Spring;
2016-06-17 11:46:47 +00:00
/**
* Handles a p2 begin contact event.
*
* @param event The event data.
*/
2016-08-26 00:18:47 +00:00
beginContactHandler(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clear(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clearTilemapLayerBodies(map: Phaser.Tilemap, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* Converts all of the polylines objects inside a Tiled ObjectGroup into physics bodies that are added to the world.
* Note that the polylines 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.
*/
2016-08-26 00:18:47 +00:00
convertCollisionObjects(map: Phaser.Tilemap, layer?: any, addToWorld?: boolean): Phaser.Physics.P2.Body[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
convertTilemap(map: Phaser.Tilemap, layer?: any, addToWorld?: Boolean, optimize?: boolean): Phaser.Physics.P2.Body[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createBody(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[][]): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createBody(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[]): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createCollisionGroup(group?: Phaser.Group): Phaser.Physics.P2.CollisionGroup;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createCollisionGroup(group?: Phaser.Sprite): Phaser.Physics.P2.CollisionGroup;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createContactMaterial(materialA: Phaser.Physics.P2.Material, materialB: Phaser.Physics.P2.Material, options?: p2.ContactMaterialOptions): Phaser.Physics.P2.ContactMaterial;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createDistanceConstraint(bodyA: any, bodyB: any, distance: number, localAnchorA?: number[], localAnchorB?: number[], maxForce?: number): Phaser.Physics.P2.DistanceConstraint;
2016-06-17 11:46:47 +00:00
/**
* Creates a constraint that tries to keep the distance 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
*/
2016-08-26 00:18:47 +00:00
createGearConstraint(bodyA: any, bodyB: any, angle?: number, ratio?: number): Phaser.Physics.P2.GearConstraint;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createLockConstraint(bodyA: any, bodyB: any, offset?: number[], angle?: number, maxForce?: number): Phaser.Physics.P2.LockConstraint;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createMaterial(name?: string, body?: Phaser.Physics.P2.Body): Phaser.Physics.P2.Material;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createParticle(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[][]): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createParticle(x: number, y: number, mass: number, addToWorld?: boolean, options?: p2.BodyOptions, data?: number[]): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createPrismaticConstraint(body: any, bodyB: any, lockRotation?: boolean, anchorA?: number[], anchorB?: number[], axis?: Float32Array, maxForce?: number): Phaser.Physics.P2.PrismaticConstraint;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createRevoluteConstraint(bodyA: any, pivotA: number[], bodyB: any, pivotB: number[], maxForce?: number, worldPivot?: number[]): Phaser.Physics.P2.RevoluteConstraint;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createRotationalSpring(bodyA: any, bodyB: any, restAngle?: number, stiffness?: number, damping?: number): p2.RotationalSpring;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
createSpring(bodyA: any, bodyB: any, restLength?: number, stiffness?: number, damping?: number, worldA?: number[], worldB?: number[], localA?: number[], localB?: number[]): Phaser.Physics.P2.Spring;
2016-06-17 11:46:47 +00:00
/**
* Clears all bodies from the simulation and unlinks World from Game. Should only be called on game shutdown. Call `clear` on a State change.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
enable(object: any, debug?: boolean, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
enableBody(object: any, debug: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Handles a p2 end contact event.
*
* @param event The event data.
*/
2016-08-26 00:18:47 +00:00
endContactHandler(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBodies(): Phaser.Physics.P2.Body[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getBody(object: any): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getConstraints(): p2.Constraint[];
2016-06-17 11:46:47 +00:00
/**
* Populates and returns an array of all current Springs in the world.
* @return An array containing all current Springs in the world.
*/
2016-08-26 00:18:47 +00:00
getSprings(): Phaser.Physics.P2.Spring[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getContactMaterial(materialA: Phaser.Physics.P2.Material, materialB: Phaser.Physics.P2.Material): Phaser.Physics.P2.ContactMaterial;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hitTest(worldPoint: Phaser.Point, bodies?: any[], precision?: number, filterStatic?: boolean): Phaser.Physics.P2.Body[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
mpx(v: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
mpxi(v: number): number;
2016-06-17 11:46:47 +00:00
/**
* Pauses the P2 World independent of the game pause state.
*/
2016-08-26 00:18:47 +00:00
pause(): void;
2016-06-17 11:46:47 +00:00
/**
* Called at the start of the core update loop. Purges flagged bodies from the world.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pxm(v: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pxmi(v: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBody(body: Phaser.Physics.P2.Body): Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeBodyNextStep(body: Phaser.Physics.P2.Body): void;
2016-06-17 11:46:47 +00:00
/**
* Removes a Constraint from the world.
*
* @param constraint The Constraint to be removed from the World.
* @return The Constraint that was removed.
*/
2016-08-26 00:18:47 +00:00
removeConstraint<T>(constraint: T): T;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeContactMaterial(material: Phaser.Physics.P2.ContactMaterial): Phaser.Physics.P2.ContactMaterial;
2016-06-17 11:46:47 +00:00
/**
* Removes a Spring from the world.
*
* @param spring The Spring to remove from the World.
* @return The Spring that was removed.
*/
2016-08-26 00:18:47 +00:00
removeSpring(spring: Phaser.Physics.P2.Spring): Phaser.Physics.P2.Spring;
2016-06-17 11:46:47 +00:00
/**
* Called by Phaser.Physics when a State swap occurs.
* Starts the begin and end Contact listeners again.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* Resumes a paused P2 World.
*/
2016-08-26 00:18:47 +00:00
resume(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setImpactEvents(state: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setMaterial(material: Phaser.Physics.P2.Material, bodies?: Phaser.Physics.P2.Body[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setPostBroadphaseCallback(callback: Function, context: any): void;
setWorldMaterial(material: Phaser.Physics.P2.Material, left?: boolean, right?: boolean, top?: boolean, bottom?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Converts the current world into a JSON object.
* @return A JSON representation of the world.
*/
2016-08-26 00:18:47 +00:00
toJSON(): any;
2016-06-17 11:46:47 +00:00
/**
* Internal P2 update loop.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
updateBoundsCollisionGroup(setCollisionGroup?: boolean): void;
}
module P2 {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Body {
2016-06-17 11:46:47 +00:00
/**
* Dynamic body. Dynamic bodies body can move and respond to collisions and forces.
*/
2016-08-26 00:18:47 +00:00
static DYNAMIC: number;
2016-06-17 11:46:47 +00:00
/**
* Static body. Static bodies do not move, and they do not respond to forces or collision.
*/
2016-08-26 00:18:47 +00:00
static STATIC: number;
2016-06-17 11:46:47 +00:00
/**
* Kinematic body. Kinematic bodies only moves according to its .velocity, and does not respond to collisions or force.
*/
2016-08-26 00:18:47 +00:00
static KINEMATIC: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, sprite?: Phaser.Sprite, x?: number, y?: number, mass?: number);
2016-06-17 11:46:47 +00:00
/**
* -
*/
2016-08-26 00:18:47 +00:00
allowSleep: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angularDamping: number;
2016-06-17 11:46:47 +00:00
/**
* The angular force acting on the body.
*/
2016-08-26 00:18:47 +00:00
angularForce: number;
2016-06-17 11:46:47 +00:00
/**
* The angular velocity of the body.
*/
2016-08-26 00:18:47 +00:00
angularVelocity: number;
2016-06-17 11:46:47 +00:00
/**
* Array of CollisionGroups that this Bodies shapes collide with.
*/
2016-08-26 00:18:47 +00:00
collidesWith: Phaser.Physics.P2.CollisionGroup[];
2016-06-17 11:46:47 +00:00
/**
* 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 effect 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?
*/
2016-08-26 00:18:47 +00:00
collideWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
damping: number;
2016-06-17 11:46:47 +00:00
/**
* The p2 Body data.
*/
2016-08-26 00:18:47 +00:00
data: p2.Body;
2016-06-17 11:46:47 +00:00
/**
* Enable or disable debug drawing of this body
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the debug body.
*/
2016-08-26 00:18:47 +00:00
debugBody: Phaser.Physics.P2.BodyDebug;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static.
*/
2016-08-26 00:18:47 +00:00
dynamic: boolean;
2016-06-17 11:46:47 +00:00
/**
* -
*/
2016-08-26 00:18:47 +00:00
fixedRotation: boolean;
2016-06-17 11:46:47 +00:00
/**
* The force applied to the body.
*/
2016-08-26 00:18:47 +00:00
force: Phaser.Physics.P2.InversePointProxy;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static.
*/
2016-08-26 00:18:47 +00:00
kinematic: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented.
*/
2016-08-26 00:18:47 +00:00
gravity: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The Body ID. Each Body that has been added to the World has a unique ID.
*/
2016-08-26 00:18:47 +00:00
id: number;
2016-06-17 11:46:47 +00:00
/**
* The inertia of the body around the Z axis..
*/
2016-08-26 00:18:47 +00:00
inertia: number;
2016-06-17 11:46:47 +00:00
/**
* The mass of the body.
*/
2016-08-26 00:18:47 +00:00
mass: number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
motionState: number;
2016-06-17 11:46:47 +00:00
/**
* The offset of the Physics Body from the Sprite x/y position.
*/
2016-08-26 00:18:47 +00:00
offset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onBeginContact: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onEndContact: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rotation: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeNextStep: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the parent Sprite.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* .
*/
2016-08-26 00:18:47 +00:00
sleepSpeedLimit: number;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic.
*/
2016-08-26 00:18:47 +00:00
static: boolean;
2016-06-17 11:46:47 +00:00
/**
* The type of physics system this body belongs to.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
velocity: Phaser.Physics.P2.InversePointProxy;
2016-06-17 11:46:47 +00:00
/**
* Local reference to the P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
2016-06-17 11:46:47 +00:00
/**
* The x coordinate of this Body.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of this Body.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Adds this physics body to the world.
*/
2016-08-26 00:18:47 +00:00
addToWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addCapsule(length: number, radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Capsule;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addFixture(fixtureData: string): p2.Shape[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addLine(length: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Line;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addParticle(offsetX?: number, offsetY?: number, rotation?: number): p2.Particle;
2016-06-17 11:46:47 +00:00
/**
* 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, ...],
* 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.
*/
2016-08-26 00:18:47 +00:00
addPolygon(options: { optimalDecomp?: boolean; skipSimpleCheck?: boolean; removeCollinearPoints?: boolean; }, points: number[][]): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
addPhaserPolygon(key: string, object: string): Phaser.Physics.P2.FixtureList;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addPlane(offsetX?: number, offsetY?: number, rotation?: number): p2.Plane;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addRectangle(width: number, height: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addShape(shape: p2.Shape, offsetX?: number, offsetY?: number, rotation?: number): p2.Shape;
2016-06-17 11:46:47 +00:00
/**
* Moves the shape offsets so their center of mass becomes the body center of mass.
*/
2016-08-26 00:18:47 +00:00
adjustCenterOfMass(): void;
2016-06-17 11:46:47 +00:00
/**
* Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details.
*
* @param dt Current time step.
*/
2016-08-26 00:18:47 +00:00
applyDamping(dt: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
applyForce(force: number[], worldX: number, worldY: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
applyImpulse(impulse: number[], worldX: number, worldY: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
applyImpulseLocal(impulse: number[], localX: number, localY: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clearCollision(clearGroup?: boolean, cleanMask?: boolean, shape?: p2.Shape): void;
2016-06-17 11:46:47 +00:00
/**
* Removes all Shapes from this Body.
*/
2016-08-26 00:18:47 +00:00
clearShapes(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
collides(group: any, callback?: Function, callbackContext?: any, shape?: p2.Shape): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createBodyCallback(object: any, callback: Function, callbackContext: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createGroupCallback(group: Phaser.Physics.P2.CollisionGroup, callback: Function, callbackContext: any): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys this Body and all references it holds to other objects.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Gets the collision bitmask from the groups this body collides with.
* @return The bitmask.
*/
2016-08-26 00:18:47 +00:00
getCollisionMask(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getVelocityAtPoint(result: number[], relativePoint: number[]): number[];
2016-06-17 11:46:47 +00:00
/**
* 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.
* @return True on success, else false.
*/
2016-08-26 00:18:47 +00:00
loadPolygon(key: string, object: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveBackward(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveDown(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveForward(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveLeft(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveRight(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveUp(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeCollisionGroup(group: any, clearCallback?: boolean, shape?: p2.Shape): void;
2016-06-17 11:46:47 +00:00
/**
* Removes this physics body from the world.
*/
2016-08-26 00:18:47 +00:00
removeFromWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeShape(shape: p2.Shape): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reverse(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* This will rotate the Body by the given speed to the left (counter-clockwise).
*
* @param speed The speed at which it should rotate.
*/
2016-08-26 00:18:47 +00:00
rotateLeft(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* This will rotate the Body by the given speed to the left (clockwise).
*
* @param speed The speed at which it should rotate.
*/
2016-08-26 00:18:47 +00:00
rotateRight(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, resetDamping?: boolean, resetMass?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the debug draw if any body shapes change.
*/
2016-08-26 00:18:47 +00:00
shapeChanged(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setCollisionGroup(group: Phaser.Physics.P2.CollisionGroup, shape?: p2.Shape): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setRectangle(width?: number, height?: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setRectangleFromSprite(sprite: any): p2.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setMaterial(material: Phaser.Physics.P2.Material, shape?: p2.Shape): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the Body damping and angularDamping to zero.
*/
2016-08-26 00:18:47 +00:00
setZeroDamping(): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the force on the body to zero.
*/
2016-08-26 00:18:47 +00:00
setZeroForce(): void;
2016-06-17 11:46:47 +00:00
/**
* If this Body is dynamic then this will zero its angular velocity.
*/
2016-08-26 00:18:47 +00:00
setZeroRotation(): void;
2016-06-17 11:46:47 +00:00
/**
* If this Body is dynamic then this will zero its velocity on both axis.
*/
2016-08-26 00:18:47 +00:00
setZeroVelocity(): void;
2016-06-17 11:46:47 +00:00
/**
* Transform a world point to local body frame.
*
* @param out The vector to store the result in.
* @param worldPoint The input world vector.
*/
2016-08-26 00:18:47 +00:00
toLocalFrame(out: number[], worldPoint: number[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
thrust(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
thrustLeft(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
thrustRight(speed: number): void;
2016-06-17 11:46:47 +00:00
/**
* Transform a local point to world frame.
*
* @param out The vector to store the result in.
* @param localPoint The input local vector.
*/
2016-08-26 00:18:47 +00:00
toWorldFrame(out: number[], localPoint: number[]): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the collisionMask.
*
* @param shape An optional Shape. If not provided the collision group will be added to all Shapes in this Body.
*/
2016-08-26 00:18:47 +00:00
updateCollisionMask(shape?: p2.Shape): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class BodyDebug extends Phaser.Group {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, body: Phaser.Physics.P2.Body, settings: { pixelsPerLengthUnit?: number; debugPolygons?: boolean; lineWidth?: number; alpha?: number; });
2016-06-17 11:46:47 +00:00
/**
* The P2 Body to display debug data for.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.P2.Body;
2016-06-17 11:46:47 +00:00
/**
* The canvas to render the debug info to.
*/
2016-08-26 00:18:47 +00:00
canvas: Phaser.Graphics;
2016-06-17 11:46:47 +00:00
/**
* Pixels per Length Unit.
*/
2016-08-26 00:18:47 +00:00
ppu: number;
2016-06-17 11:46:47 +00:00
/**
* Core update.
*/
2016-08-26 00:18:47 +00:00
updateSpriteTransform(): void;
2016-06-17 11:46:47 +00:00
/**
* Draws the P2 shapes to the Graphics object.
*/
2016-08-26 00:18:47 +00:00
draw(): void;
}
2016-06-17 11:46:47 +00:00
/**
* Collision Group
*/
2016-08-26 00:18:47 +00:00
class CollisionGroup {
2016-06-17 11:46:47 +00:00
/**
* Collision Group
*
* @param bitmask The CollisionGroup bitmask.
*/
2016-08-26 00:18:47 +00:00
constructor(bitmask: number);
2016-06-17 11:46:47 +00:00
/**
* The CollisionGroup bitmask.
*/
2016-08-26 00:18:47 +00:00
mask: number;
}
2016-06-17 11:46:47 +00:00
/**
* Defines a physics material
*/
2016-08-26 00:18:47 +00:00
class ContactMaterial extends p2.ContactMaterial {
}
2016-06-17 11:46:47 +00:00
/**
* A constraint that tries to keep the distance between two bodies constant.
*/
2016-08-26 00:18:47 +00:00
class DistanceConstraint extends p2.DistanceConstraint {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, distance: number, maxForce: number);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
class FixtureList {
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
constructor(list: any[]);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
flatten(array: any[]): any[];
2016-06-17 11:46:47 +00:00
/**
* Accessor to get either a list of specified fixtures by key or the whole fixture list
*
* @param keys A list of fixture keys
*/
2016-08-26 00:18:47 +00:00
getFixtures(keys: string): any[];
2016-06-17 11:46:47 +00:00
/**
* Accessor to get either a single fixture by its key.
*
* @param key The key of the fixture.
*/
2016-08-26 00:18:47 +00:00
getFixtureByKey(key: string): any[];
2016-06-17 11:46:47 +00:00
/**
* Accessor to get a group of fixtures by its group index.
*
* @param groupID The group index.
*/
2016-08-26 00:18:47 +00:00
getGroup(groupID: number): any[];
init(): void;
2016-06-17 11:46:47 +00:00
/**
* Parser for the output of Phaser.Physics.P2.Body#addPhaserPolygon
*/
2016-08-26 00:18:47 +00:00
parse(): void;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param bit The bit to set as the collision group.
* @param fixtureKey Only apply to the fixture with the given key.
*/
2016-08-26 00:18:47 +00:00
setCategory(bit: number, fictureKey: string): void;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param bit The bit to set as the collision mask
* @param fixtureKey Only apply to the fixture with the given key
*/
2016-08-26 00:18:47 +00:00
setMask(bit: number, fixtureKey: string): void;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param material The contact material for a fixture
* @param fixtureKey Only apply to the fixture with the given key
*/
2016-08-26 00:18:47 +00:00
setMaterial(material: any, fixtureKey: string): void;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param value sensor true or false
* @param fixtureKey Only apply to the fixture with the given key
*/
2016-08-26 00:18:47 +00:00
setSensor(value: boolean, fixtureKey: string): void;
}
2016-06-17 11:46:47 +00:00
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
2016-08-26 00:18:47 +00:00
class GearConstraint extends p2.GearConstraint {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, angle?: number, ratio?: number);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class InversePointProxy {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, destination: any);
2016-06-17 11:46:47 +00:00
/**
* The x property of this InversePointProxy get and set in pixels.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y property of this InversePointProxy get and set in pixels.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* The x property of this InversePointProxy get and set in meters.
*/
2016-08-26 00:18:47 +00:00
mx: number;
2016-06-17 11:46:47 +00:00
/**
* The y property of this InversePointProxy get and set in meters.
*/
2016-08-26 00:18:47 +00:00
my: number;
}
2016-06-17 11:46:47 +00:00
/**
* Locks the relative position between two bodies.
*/
2016-08-26 00:18:47 +00:00
class LockConstraint extends p2.LockConstraint {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, offset?: number[], angle?: number, maxForce?: number);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
2016-06-17 11:46:47 +00:00
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*/
2016-08-26 00:18:47 +00:00
class Material extends p2.Material {
2016-06-17 11:46:47 +00:00
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*
* @param name The user defined name given to this Material.
*/
2016-08-26 00:18:47 +00:00
constructor(name: string);
2016-06-17 11:46:47 +00:00
/**
* The user defined name given to this Material.
*/
2016-08-26 00:18:47 +00:00
name: string;
}
2016-06-17 11:46:47 +00:00
/**
* A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays.
*/
2016-08-26 00:18:47 +00:00
class PointProxy {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, destination: any);
2016-06-17 11:46:47 +00:00
/**
* The x property of this PointProxy get and set in pixels.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y property of this PointProxy get and set in pixels.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* The x property of this PointProxy get and set in meters.
*/
2016-08-26 00:18:47 +00:00
mx: number;
2016-06-17 11:46:47 +00:00
/**
* The x property of this PointProxy get and set in meters.
*/
2016-08-26 00:18:47 +00:00
my: number;
}
2016-06-17 11:46:47 +00:00
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
2016-08-26 00:18:47 +00:00
class PrismaticConstraint extends p2.PrismaticConstraint {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class RevoluteConstraint extends p2.RevoluteConstraint {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, pivotA: number[], bodyB: Phaser.Physics.P2.Body, pivotB: number[], maxForce?: number);
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
2016-06-17 11:46:47 +00:00
/**
* Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
*/
2016-08-26 00:18:47 +00:00
class Spring {
2016-06-17 11:46:47 +00:00
/**
* 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].
*/
2016-08-26 00:18:47 +00:00
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[]);
2016-06-17 11:46:47 +00:00
/**
* The actual p2 spring object.
*/
2016-08-26 00:18:47 +00:00
data: p2.LinearSpring;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Local reference to P2 World.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Physics.P2;
}
}
}
2016-06-17 11:46:47 +00:00
/**
* This is a base Plugin template to use for any Phaser plugin development.
*/
2016-08-26 00:18:47 +00:00
class Plugin implements IStateCycle {
2016-06-17 11:46:47 +00:00
/**
* This is a base Plugin template to use for any Phaser plugin development.
*
* @param game A reference to the currently running game.
* @param parent The object that owns this plugin, usually Phaser.PluginManager.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, parent: Phaser.PluginManager);
2016-06-17 11:46:47 +00:00
/**
* A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
*/
2016-08-26 00:18:47 +00:00
active: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A flag to indicate if this plugin has a postRender method.
*/
2016-08-26 00:18:47 +00:00
hasPostRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* A flag to indicate if this plugin has a postUpdate method.
*/
2016-08-26 00:18:47 +00:00
hasPostUpdate: boolean;
2016-06-17 11:46:47 +00:00
/**
* A flag to indicate if this plugin has a preUpdate method.
*/
2016-08-26 00:18:47 +00:00
hasPreUpdate: boolean;
2016-06-17 11:46:47 +00:00
/**
* A flag to indicate if this plugin has a render method.
*/
2016-08-26 00:18:47 +00:00
hasRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* A flag to indicate if this plugin has an update method.
*/
2016-08-26 00:18:47 +00:00
hasUpdate: boolean;
2016-06-17 11:46:47 +00:00
/**
* The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
2016-08-26 00:18:47 +00:00
parent: PIXI.DisplayObject;
2016-06-17 11:46:47 +00:00
/**
* A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
*/
2016-08-26 00:18:47 +00:00
visible: boolean;
2016-06-17 11:46:47 +00:00
/**
* Clear down this Plugin and null out references
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Post-render is called after the Game Renderer and State.render have run.
* It is only called if visible is set to true.
*/
2016-08-26 00:18:47 +00:00
postRender(): void;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* 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;
2016-07-01 15:57:13 +00:00
2016-08-26 00:18:47 +00:00
/**
* 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;
2016-07-01 15:57:13 +00:00
2016-08-26 00:18:47 +00:00
/**
* 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_ORTHAGONAL: number;
static COST_DIAGAONAL: number;
static DISTANCE_MANHATTEN: 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;
}
class AStarPath {
constructor(nodes: Phaser.Plugin.AStar.AStarNode[], start: Phaser.Plugin.AStar.AStarNode, goal: Phaser.Plugin.AStar.AStarNode);
nodes: Phaser.Plugin.AStar.AStarNode[];
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<T> {
new (...parameters: any[]): T;
}
2016-06-17 11:46:47 +00:00
/**
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
*/
2016-08-26 00:18:47 +00:00
class PluginManager implements IStateCycle {
2016-06-17 11:46:47 +00:00
/**
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
*
* @param game A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* An array of all the plugins being managed by this PluginManager.
*/
2016-08-26 00:18:47 +00:00
plugins: Phaser.Plugin[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add<T extends Phaser.Plugin>(plugin: PluginConstructorOf<T>, ...parameters: any[]): T;
2016-06-17 11:46:47 +00:00
/**
* Clear down this PluginManager, calls destroy on every plugin and nulls out references.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Post-render is called after the Game Renderer and State.render have run.
* It only calls plugins who have visible=true.
*/
2016-08-26 00:18:47 +00:00
postRender(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
remove(plugin: Phaser.Plugin, destroy?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Remove all Plugins from the PluginManager. It calls Plugin.destroy on every plugin before removing it from the manager.
*/
2016-08-26 00:18:47 +00:00
removeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* Render is called right after the Game Renderer completes, but before the State.render.
* It only calls plugins who have visible=true.
*/
2016-08-26 00:18:47 +00:00
render(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Point extends PIXI.Point {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(x?: number, y?: number);
2016-06-17 11:46:47 +00:00
/**
* The x value of the point.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y value of the point.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static add(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static subtract(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static multiply(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static divide(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static equals(a: Phaser.Point, b: Phaser.Point): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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 Is the given angle in radians (false) or degrees (true)?
* @return The angle between the two objects.
*/
2016-08-26 00:18:47 +00:00
static angle(a: Phaser.Point, b: Phaser.Point): number;
static angleSq(a: Phaser.Point, b: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static negative(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static multiplyAdd(a: Phaser.Point, b: Phaser.Point, scale: number, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static interpolate(a: Phaser.Point, b: Phaser.Point, alpha: number, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static parse(obj: any, xProp?: string, yProp?: string): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Make this Point perpendicular (90 degrees rotation)
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
static perp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Make this Point perpendicular (-90 degrees rotation)
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
static rperp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static distance(a: any, b: any, round?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static project(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static projectUnit(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Right-hand normalize (make unit length) this Point.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
static normalRightHand(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Alters the Point object so that its length is 1, but it retains the same direction.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
static normalize(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static rotate(a: Phaser.Point, x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static centroid(points: Phaser.Point[], out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(x: number, y: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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 Is the given angle in radians (false) or degrees (true)?
* @return The angle between the two objects.
*/
2016-08-26 00:18:47 +00:00
angle(a: Phaser.Point, asDegrees?: boolean): number;
angleSq(a: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clamp(min: number, max: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clampX(min: number, max: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clampY(min: number, max: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Copies the x and y properties from any given object to this Point.
*
* @param source The object to copy from.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
copyFrom(source: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Copies the x and y properties from this Point to any given object.
*
* @param dest The object to copy to.
* @return The dest object.
*/
2016-08-26 00:18:47 +00:00
copyTo<T>(dest: T): T;
2016-06-17 11:46:47 +00:00
/**
* Math.ceil() both the x and y properties of this Point.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
ceil(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cross(a: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
divide(x: number, y: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
distance(dest: Phaser.Point, round?: boolean): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
dot(a: Phaser.Point): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
equals(a: Phaser.Point): boolean;
2016-06-17 11:46:47 +00:00
/**
* Math.floor() both the x and y properties of this Point.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
floor(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Calculates the length of the Point object.
* @return The length of the Point.
*/
2016-08-26 00:18:47 +00:00
getMagnitude(): number;
2016-06-17 11:46:47 +00:00
/**
* Calculates the length squared of the Point object.
* @return The length ^ 2 of the Point.
*/
2016-08-26 00:18:47 +00:00
getMagnitudeSq(): number;
2016-06-17 11:46:47 +00:00
/**
* Inverts the x and y values of this Point
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
invert(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Determine if this point is at 0,0.
* @return True if this Point is 0,0, otherwise false.
*/
2016-08-26 00:18:47 +00:00
isZero(): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
multiply(x: number, y: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Alters the Point object so that its length is 1, but it retains the same direction.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
normalize(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Right-hand normalize (make unit length) this Point.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
normalRightHand(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Make this Point perpendicular (90 degrees rotation)
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
perp(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Make this Point perpendicular (-90 degrees rotation)
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
rperp(): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rotate(x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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)`
*
* @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.
*/
2016-08-26 00:18:47 +00:00
set(x: number, y?: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Alters the length of the Point without changing the direction.
*
* @param magnitude The desired magnitude of the resulting Point.
* @return This Point object.
*/
2016-08-26 00:18:47 +00:00
setMagnitude(magnitude: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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)`
*
* @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.
*/
2016-08-26 00:18:47 +00:00
setTo(x: number, y?: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
subtract(x: number, y: number): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Returns a string representation of this object.
* @return A string representation of the instance.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
}
2016-06-17 11:46:47 +00:00
/**
* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
*/
2016-08-26 00:18:47 +00:00
class Pointer {
2016-06-17 11:46:47 +00:00
/**
* 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 TOUCH. - Default: (CURSOR|CONTACT)
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, id: number, pointerMode?: number);
2016-06-17 11:46:47 +00:00
/**
* No buttons at all.
*/
2016-08-26 00:18:47 +00:00
static NO_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* The Left Mouse button, or in PointerEvent devices a Touch contact or Pen contact.
*/
2016-08-26 00:18:47 +00:00
static LEFT_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* The Right Mouse button, or in PointerEvent devices a Pen contact with a barrel button.
*/
2016-08-26 00:18:47 +00:00
static RIGHT_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* The Middle Mouse button.
*/
2016-08-26 00:18:47 +00:00
static MIDDLE_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static BACK_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static FORWARD_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* The Eraser pen button on PointerEvent supported devices only.
*/
2016-08-26 00:18:47 +00:00
static ERASER_BUTTON: number;
2016-06-17 11:46:47 +00:00
/**
* An active pointer is one that is currently pressed down on the display. A Mouse is always active.
*/
2016-08-26 00:18:47 +00:00
active: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
backButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
button: any;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
circle: Phaser.Circle;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
clientX: number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
clientY: number;
2016-06-17 11:46:47 +00:00
/**
* A dirty pointer needs to re-poll any interactive objects it may have been over, regardless if it has moved or not.
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
duration: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
eraserButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* A Pointer object that exists is allowed to be checked for physics collisions and overlaps.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
forceOut: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
forwardButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
justReleasePreventsOver: boolean | number;
2016-06-17 11:46:47 +00:00
/**
* The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
*/
2016-08-26 00:18:47 +00:00
id: number;
2016-06-17 11:46:47 +00:00
/**
* The identifier property of the Pointer as set by the DOM event when this Pointer is started.
*/
2016-08-26 00:18:47 +00:00
identifier: number;
2016-06-17 11:46:47 +00:00
/**
* 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: []
*/
2016-08-26 00:18:47 +00:00
interactiveCandidates: Phaser.InputHandler[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isDown: boolean;
2016-06-17 11:46:47 +00:00
/**
* If the Pointer is a mouse or pen / stylus this is true, otherwise false.
*/
2016-08-26 00:18:47 +00:00
isMouse: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
isUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
leftButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
middleButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* The horizontal processed relative movement of the Pointer in pixels since last event.
*/
2016-08-26 00:18:47 +00:00
movementX: number;
2016-06-17 11:46:47 +00:00
/**
* The vertical processed relative movement of the Pointer in pixels since last event.
*/
2016-08-26 00:18:47 +00:00
movementY: number;
2016-06-17 11:46:47 +00:00
/**
* The number of milliseconds since the last click or touch event.
*/
2016-08-26 00:18:47 +00:00
msSinceLastClick: number;
2016-06-17 11:46:47 +00:00
/**
* The horizontal coordinate of the Pointer relative to whole document.
*/
2016-08-26 00:18:47 +00:00
pageX: number;
2016-06-17 11:46:47 +00:00
/**
* The vertical coordinate of the Pointer relative to whole document.
*/
2016-08-26 00:18:47 +00:00
pageY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pointerId: number;
2016-06-17 11:46:47 +00:00
/**
* The operational mode of this pointer.
*/
2016-08-26 00:18:47 +00:00
pointerMode: number;
2016-06-17 11:46:47 +00:00
/**
* A Phaser.Point object containing the current x/y values of the pointer on the display.
*/
2016-08-26 00:18:47 +00:00
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display.
*/
2016-08-26 00:18:47 +00:00
positionDown: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* A Phaser.Point object containing the x/y values of the pointer when it was last released.
*/
2016-08-26 00:18:47 +00:00
positionUp: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer was last tapped or clicked.
*/
2016-08-26 00:18:47 +00:00
previousTapTime: number;
2016-06-17 11:46:47 +00:00
/**
* The horizontal raw relative movement of the Pointer in pixels since last event.
*/
2016-08-26 00:18:47 +00:00
rawMovementX: number;
2016-06-17 11:46:47 +00:00
/**
* The vertical raw relative movement of the Pointer in pixels since last event.
*/
2016-08-26 00:18:47 +00:00
rawMovementY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
rightButton: Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* The horizontal coordinate of the Pointer relative to the screen.
*/
2016-08-26 00:18:47 +00:00
screenX: number;
2016-06-17 11:46:47 +00:00
/**
* The vertical coordinate of the Pointer relative to the screen.
*/
2016-08-26 00:18:47 +00:00
screenY: number;
2016-06-17 11:46:47 +00:00
/**
* The target property of the Pointer as set by the DOM event when this Pointer is started.
*/
2016-08-26 00:18:47 +00:00
target: any;
2016-06-17 11:46:47 +00:00
/**
* The Game Object this Pointer is currently over / touching / dragging.
*/
2016-08-26 00:18:47 +00:00
targetObject: any;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer first touched the touchscreen.
*/
2016-08-26 00:18:47 +00:00
timeDown: number;
2016-06-17 11:46:47 +00:00
/**
* A timestamp representing when the Pointer left the touchscreen.
*/
2016-08-26 00:18:47 +00:00
timeUp: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of times this Pointer has been touched to the touchscreen.
*/
2016-08-26 00:18:47 +00:00
totalTouches: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* true if the Pointer is over the game canvas, otherwise false.
*/
2016-08-26 00:18:47 +00:00
withinGame: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets the X value of this Pointer in world coordinates based on the world camera.
*/
2016-08-26 00:18:47 +00:00
worldX: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the Y value of this Pointer in world coordinates based on the world camera.
*/
2016-08-26 00:18:47 +00:00
worldY: number;
2016-06-17 11:46:47 +00:00
/**
* The horizontal coordinate of the Pointer. This value is automatically scaled based on the game scale.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The vertical coordinate of the Pointer. This value is automatically scaled based on the game scale.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addClickTrampoline(name: string, callback: Function, callbackContext: any, ...callbackArgs: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justPressed(duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justReleased(duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Called when the Pointer leaves the target area.
*
* @param event The event passed up from the input handler.
*/
2016-08-26 00:18:47 +00:00
leave(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
move(event: any, fromClick?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the states of all the button booleans.
*/
2016-08-26 00:18:47 +00:00
resetButtons(): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the movementX and movementY properties. Use in your update handler after retrieving the values.
*/
2016-08-26 00:18:47 +00:00
resetMovement(): void;
2016-06-17 11:46:47 +00:00
/**
* Called when the Pointer is pressed onto the touchscreen.
*
* @param event The DOM event from the browser.
*/
2016-08-26 00:18:47 +00:00
start(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Called when the Pointer leaves the touchscreen.
*
* @param event The event passed up from the input handler.
*/
2016-08-26 00:18:47 +00:00
stop(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
swapTarget(newTarget: Phaser.InputHandler, silent?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Called by the Input Manager.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* Called when the event.buttons property changes from zero.
* Contains a button bitmask.
*
* @param event The DOM event.
*/
2016-08-26 00:18:47 +00:00
updateButtons(event: MouseEvent): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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, ...)`
*/
2016-08-26 00:18:47 +00:00
class Polygon {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(points: Phaser.Point[] | number[]);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(...points: Phaser.Point[]);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(...points: number[]);
2016-06-17 11:46:47 +00:00
/**
* The area of this Polygon.
*/
2016-08-26 00:18:47 +00:00
area: number;
2016-07-01 15:57:13 +00:00
/**
* Has this Polygon been flattened by a call to `Polygon.flatten` ?
*/
2016-08-26 00:18:47 +00:00
flattened: boolean;
2016-06-17 11:46:47 +00:00
/**
* Sets and modifies the points of this polygon.
*
* See {@link Phaser.Polygon#setTo setTo} for the different kinds of arrays formats that can be assigned. The array of vertex points.
*/
2016-08-26 00:18:47 +00:00
points: number[] | Phaser.Point[];
2016-06-17 11:46:47 +00:00
/**
* The base object type.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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 Polygon)
* @return The cloned (`output`) polygon object.
*/
2016-08-26 00:18:47 +00:00
clone(output: Phaser.Polygon): Phaser.Polygon;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
contains(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* 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`.
2016-06-17 11:46:47 +00:00
* @return This Polygon object
*/
2016-08-26 00:18:47 +00:00
flatten(): Phaser.Polygon;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setTo(points: Phaser.Point[] | number[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setTo(...points: Phaser.Point[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setTo(...points: number[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
toNumberArray(output?: number[]): number[];
}
2016-06-17 11:46:47 +00:00
/**
* 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/
*/
2016-08-26 00:18:47 +00:00
class QuadTree {
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
constructor(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number);
2016-06-17 11:46:47 +00:00
/**
* Object that contains the quadtree bounds.
*/
2016-08-26 00:18:47 +00:00
bounds: {
x: number;
y: number;
width: number;
height: number;
subWidth: number;
subHeight: number;
right: number;
bottom: number;
};
2016-06-17 11:46:47 +00:00
/**
* The current level.
*/
2016-08-26 00:18:47 +00:00
level: number;
2016-06-17 11:46:47 +00:00
/**
* The maximum number of objects per node.
* Default: 10
*/
2016-08-26 00:18:47 +00:00
maxObjects: number;
2016-06-17 11:46:47 +00:00
/**
* The maximum number of levels to break down to.
* Default: 4
*/
2016-08-26 00:18:47 +00:00
maxLevels: number;
2016-06-17 11:46:47 +00:00
/**
* Array of quadtree children.
*/
2016-08-26 00:18:47 +00:00
objects: any[];
2016-06-17 11:46:47 +00:00
/**
* Array of associated child nodes.
*/
2016-08-26 00:18:47 +00:00
nodes: any[];
2016-06-17 11:46:47 +00:00
/**
* Clear the quadtree.
*/
2016-08-26 00:18:47 +00:00
clear(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getIndex(rect: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
insert(body: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
populate(group: Phaser.Group): void;
2016-06-17 11:46:47 +00:00
/**
* Handler for the populate method.
*
* @param sprite The Sprite to check.
*/
2016-08-26 00:18:47 +00:00
populateHandler(sprite: Phaser.Sprite): void;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
retrieve(source: any): any[];
2016-06-17 11:46:47 +00:00
/**
* Split the node into 4 subnodes
*/
2016-08-26 00:18:47 +00:00
split(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
class RandomDataGenerator {
2016-06-17 11:46:47 +00:00
/**
* 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}).
*/
2016-08-26 00:18:47 +00:00
constructor(seeds?: any[] | string);
2016-06-17 11:46:47 +00:00
/**
* Returns a random angle between -180 and 180.
* @return A random number between -180 and 180.
*/
2016-08-26 00:18:47 +00:00
angle(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
between(min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a random real number between 0 and 1.
* @return A random real number between 0 and 1.
*/
2016-08-26 00:18:47 +00:00
frac(): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a random integer between 0 and 2^32.
* @return A random integer between 0 and 2^32.
*/
2016-08-26 00:18:47 +00:00
integer(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
integerInRange(min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a random real number between -1 and 1.
* @return A random real number between -1 and 1.
*/
2016-08-26 00:18:47 +00:00
normal(): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a random member of `array`.
*
* @param ary An Array to pick a random member of.
* @return A random member of the array.
*/
2016-08-26 00:18:47 +00:00
pick<T>(ary: T[]): T;
2016-06-17 11:46:47 +00:00
/**
* Returns a random real number between 0 and 2^32.
* @return A random real number between 0 and 2^32.
*/
2016-08-26 00:18:47 +00:00
real(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
realInRange(min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a sign to be used with multiplication operator.
* @return -1 or +1.
*/
2016-08-26 00:18:47 +00:00
sign(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
sow(seeds: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
state(state?: string): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
timestamp(min: number, max: number): number;
2016-06-17 11:46:47 +00:00
/**
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
* @return A valid RFC4122 version4 ID hex string
*/
2016-08-26 00:18:47 +00:00
uuid(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
weightedPick<T>(ary: T[]): T;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Rectangle {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(x: number, y: number, width: number, height: number);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bottomRight: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bottomLeft: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The x coordinate of the center of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the center of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
empty: boolean;
2016-06-17 11:46:47 +00:00
/**
* Half of the height of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
halfHeight: number;
2016-06-17 11:46:47 +00:00
/**
* Half of the width of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
halfWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the Rectangle. This value should never be set to a negative.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* The perimeter size of the Rectangle. This is the sum of all 4 sides.
*/
2016-08-26 00:18:47 +00:00
perimeter: number;
2016-06-17 11:46:47 +00:00
/**
* A random value between the left and right values (inclusive) of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
randomX: number;
2016-06-17 11:46:47 +00:00
/**
* A random value between the top and bottom values (inclusive) of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
randomY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The location of the Rectangles top left corner as a Point object.
*/
2016-08-26 00:18:47 +00:00
topLeft: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The location of the Rectangles top right corner as a Point object. The location of the Rectangles top left corner as a Point object.
*/
2016-08-26 00:18:47 +00:00
topRight: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The volume of the Rectangle derived from width * height.
*/
2016-08-26 00:18:47 +00:00
volume: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the Rectangle. This value should never be set to a negative.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The x coordinate of the top-left corner of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the top-left corner of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static aabb(points: Phaser.Point[], out?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static clone(a: Phaser.Rectangle, output?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static contains(a: Phaser.Rectangle, x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static containsPoint(a: Phaser.Rectangle, point: Phaser.Point): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static containsRaw(rx: number, ry: number, rw: number, rh: number, x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static containsRect(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static equals(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static inflate(a: Phaser.Rectangle, dx: number, dy: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static inflatePoint(a: Phaser.Rectangle, point: Phaser.Point): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersection(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersects(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static size(a: Phaser.Rectangle, output?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static union(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Runs Math.ceil() on both the x and y values of this Rectangle.
*/
2016-08-26 00:18:47 +00:00
ceil(): void;
2016-06-17 11:46:47 +00:00
/**
* Runs Math.ceil() on the x, y, width and height values of this Rectangle.
*/
2016-08-26 00:18:47 +00:00
ceilAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
centerOn(x: number, y: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clone(output: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
contains(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
containsRect(b: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyFrom(source: any): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copyTo(dest: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
equals(b: Phaser.Rectangle): boolean;
2016-06-17 11:46:47 +00:00
/**
* Runs Math.floor() on both the x and y values of this Rectangle.
*/
2016-08-26 00:18:47 +00:00
floor(): void;
2016-06-17 11:46:47 +00:00
/**
* Runs Math.floor() on the x, y, width and height values of this Rectangle.
*/
2016-08-26 00:18:47 +00:00
floorAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getPoint(position: number, out: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inflate(dx: number, dy: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersection(b: Phaser.Rectangle, out: Phaser.Rectangle): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersects(b: Phaser.Rectangle, tolerance: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offset(dx: number, dy: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetPoint(point: Phaser.Point): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
random(out?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
resize(width: number, height: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setTo(x: number, y: number, width: number, height: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
scale(x: number, y?: number): Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
size(output?: Phaser.Point): Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Returns a string representation of this object.
* @return A string representation of the instance.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
union(b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class RenderTexture extends PIXI.RenderTexture {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, width?: number, height?: number, key?: string, scaleMode?: number, resolution?: number);
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
crop: PIXI.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The key of the RenderTexture in the Cache, if stored there.
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* Base Phaser object type.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
render(displayObject: PIXI.DisplayObject, matrix?: Phaser.Matrix, clear?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderRawXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void;
}
2016-06-17 11:46:47 +00:00
/**
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
*/
2016-08-26 00:18:47 +00:00
class RequestAnimationFrame {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, forceSetTimeOut?: boolean);
2016-06-17 11:46:47 +00:00
/**
* Tell Phaser to use setTimeOut even if raf is available.
*/
2016-08-26 00:18:47 +00:00
forceSetTimeOut: boolean;
2016-06-17 11:46:47 +00:00
/**
* The currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* true if RequestAnimationFrame is running, otherwise false.
*/
2016-08-26 00:18:47 +00:00
isRunning: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the browser using requestAnimationFrame?
*/
2016-08-26 00:18:47 +00:00
isRAF(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the browser using setTimeout?
*/
2016-08-26 00:18:47 +00:00
isSetTimeOut(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Starts the requestAnimationFrame running or setTimeout if unavailable in browser
*/
2016-08-26 00:18:47 +00:00
start(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Stops the requestAnimationFrame from running.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* The update method for the requestAnimationFrame
*/
2016-08-26 00:18:47 +00:00
updateRAF(rafTime: number): void;
2016-06-17 11:46:47 +00:00
/**
* The update method for the setTimeout.
*/
2016-08-26 00:18:47 +00:00
updateSetTimeout(time: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class RetroFont extends Phaser.RenderTexture {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, key: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow?: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number);
2016-06-17 11:46:47 +00:00
/**
* Align each line of multi-line text in the center.
*/
2016-08-26 00:18:47 +00:00
static ALIGN_CENTER: string;
2016-06-17 11:46:47 +00:00
/**
* Align each line of multi-line text to the left.
*/
2016-08-26 00:18:47 +00:00
static ALIGN_LEFT: string;
2016-06-17 11:46:47 +00:00
/**
* Align each line of multi-line text to the right.
*/
2016-08-26 00:18:47 +00:00
static ALIGN_RIGHT: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 1 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET1: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET2: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET3: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET4: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET5: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET6: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET7: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET8: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET9: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET10: string;
2016-06-17 11:46:47 +00:00
/**
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
*/
2016-08-26 00:18:47 +00:00
static TEXT_SET11: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
align: string;
2016-06-17 11:46:47 +00:00
/**
* Automatically convert any text to upper case. Lots of old bitmap fonts only contain upper-case characters, so the default is true.
* Default: true
*/
2016-08-26 00:18:47 +00:00
autoUpperCase: boolean;
2016-06-17 11:46:47 +00:00
/**
* The height of each character in the font set.
*/
2016-08-26 00:18:47 +00:00
characterHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The number of characters per row in the font set.
*/
2016-08-26 00:18:47 +00:00
characterPerRow: number;
2016-06-17 11:46:47 +00:00
/**
* If the characters in the font set have horizontal spacing between them set the required amount here.
*/
2016-08-26 00:18:47 +00:00
characterSpacingX: number;
2016-06-17 11:46:47 +00:00
/**
* If the characters in the font set have vertical spacing between them set the required amount here.
*/
2016-08-26 00:18:47 +00:00
characterSpacingY: number;
2016-06-17 11:46:47 +00:00
/**
* The width of each character in the font set.
*/
2016-08-26 00:18:47 +00:00
characterWidth: number;
2016-06-17 11:46:47 +00:00
/**
* Adds horizontal spacing between each character of the font, in pixels.
*/
2016-08-26 00:18:47 +00:00
customSpacingX: number;
2016-06-17 11:46:47 +00:00
/**
* Adds vertical spacing between each line of multi-line text, set in pixels.
*/
2016-08-26 00:18:47 +00:00
customSpacingY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedWidth: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the image stored in the Game.Cache that contains the font.
*/
2016-08-26 00:18:47 +00:00
fontSet: Image;
2016-06-17 11:46:47 +00:00
/**
* The FrameData representing this Retro Font.
*/
2016-08-26 00:18:47 +00:00
frameData: Phaser.FrameData;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
multiLine: boolean;
2016-06-17 11:46:47 +00:00
/**
* If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* Sets if the stamp is smoothed or not.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The image that is stamped to the RenderTexture for each character in the font.
*/
2016-08-26 00:18:47 +00:00
stamp: Phaser.Image;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text: string;
2016-06-17 11:46:47 +00:00
/**
* Updates the texture with the new text.
*/
2016-08-26 00:18:47 +00:00
buildRetroFontText(): void;
2016-06-17 11:46:47 +00:00
/**
* Works out the longest line of text in _text and returns its length
* @return The length of the longest line of text.
*/
2016-08-26 00:18:47 +00:00
getLongestLine(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pasteLine(line: string, x: number, y: number, customSpacingX: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeUnsupportedCharacters(stripCR?: boolean): string;
2016-06-17 11:46:47 +00:00
/**
* 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'
*/
2016-08-26 00:18:47 +00:00
setFixedWidth(width: number, lineAlignment?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setText(content: string, multiLine?: boolean, characterSpacing?: number, lineSpacing?: number, lineAlignment?: string, allowLowerCase?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateOffset(x?: number, y?: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Rope extends PIXI.Rope {
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video, frame?: string | number, points?: Phaser.Point[]);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* `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.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cropRect: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
2016-08-26 00:18:47 +00:00
customRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaY: number;
2016-06-17 11:46:47 +00:00
/**
* Returns the delta z value. The difference between rotation now and in the previous frame. The delta value.
*/
2016-08-26 00:18:47 +00:00
deltaZ: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frame: string | number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frameName: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
input: Phaser.InputHandler;
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
2016-08-26 00:18:47 +00:00
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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 the millisecond equivalent of `game.time.physicsElapsed` each frame.
* When it reaches zero it will call the `kill` method.
*
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
2016-08-26 00:18:47 +00:00
outOfBoundsKill: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
points: Phaser.Point[];
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The segments that make up the rope body as an array of Phaser.Rectangles
*/
2016-08-26 00:18:47 +00:00
segments: Phaser.Rectangle[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* The callback that will apply any scale limiting to the worldTransform.
*/
2016-08-26 00:18:47 +00:00
transformCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The context under which `transformCallback` is called.
*/
2016-08-26 00:18:47 +00:00
transformCallbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleMin: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleMax: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateAnimation: Function;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the x axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the y axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* Brings this Game Object to the top of its parents display list.
* Visually this means it will render over the top of any old child in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
bringToTop(): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* Adjust scaling limits, if set, to this Game Object.
*
* @param wt The updated worldTransform matrix.
*/
2016-08-26 00:18:47 +00:00
checkTransform(wt: PIXI.Matrix): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
crop(rect: Phaser.Rectangle, copy?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present
* and nulls its reference to `game`, freeing it up for garbage collection.
*
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
*
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
* @param destroyChildren Should every child of this object have its destroy method called as well? - Default: true
* @param destroyTexture Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
kill(): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Moves this Game Object up one place in its parents 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.
*/
2016-08-26 00:18:47 +00:00
moveUp(): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveDown(): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method called by the World postUpdate cycle.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
2016-08-26 00:18:47 +00:00
resetFrame(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
revive(health?: number): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* Sends this Game Object to the bottom of its parents display list.
* Visually this means it will render below all other children in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
sendToBack(): Phaser.Rope;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrame(frame: Phaser.Frame): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateCrop(): void;
2016-06-17 11:46:47 +00:00
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class RoundedRectangle extends PIXI.RoundedRectangle {
2016-06-17 11:46:47 +00:00
/**
* The x coordinate of the top-left corner of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the top-left corner of the Rectangle.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the Rectangle. This value should never be set to a negative.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the Rectangle. This value should never be set to a negative.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The radius of the rounded corners.
*/
2016-08-26 00:18:47 +00:00
radius: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* Returns a new RoundedRectangle object with the same values for the x, y, width, height and
* radius properties as this RoundedRectangle object.
*/
2016-08-26 00:18:47 +00:00
clone(): RoundedRectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
contains(x: number, y: number): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
class Signal {
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
active: boolean;
boundDispatch: Function;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
memorize: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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'.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
add(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addOnce(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
dispatch(...params: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
dispose(): void;
2016-06-17 11:46:47 +00:00
/**
* Forget the currently {@link Phaser.Signal#memorize memorized} event, if any.
*/
2016-08-26 00:18:47 +00:00
forget(): void;
2016-06-17 11:46:47 +00:00
/**
* Gets the total number of listeners attached to this Signal.
* @return Number of listeners attached to the Signal.
*/
2016-08-26 00:18:47 +00:00
getNumListeners(): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
halt(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
has(listener: Function, context?: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
remove(listener: Function, context?: any): Function;
2016-06-17 11:46:47 +00:00
/**
* Remove all event listeners.
*
* @param context If specified only listeners for the given context will be removed.
*/
2016-08-26 00:18:47 +00:00
removeAll(context?: any): void;
2016-06-17 11:46:47 +00:00
/**
* A string representation of the object.
* @return String representation of the object.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param listener Signal handler function.
* @param fnName Function name.
*/
2016-08-26 00:18:47 +00:00
validateListener(listener: Function, fnName: string): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class SignalBinding {
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
constructor(signal: Phaser.Signal, listener: Function, isOnce: boolean, listenerContext?: any, priority?: number, ...args: any[]);
2016-06-17 11:46:47 +00:00
/**
* If binding is active and should be executed.
* Default: true
*/
2016-08-26 00:18:47 +00:00
active: boolean;
2016-06-17 11:46:47 +00:00
/**
* The number of times the handler function has been called.
*/
2016-08-26 00:18:47 +00:00
callCount: number;
2016-06-17 11:46:47 +00:00
/**
* Context on which listener will be executed (object that should represent the `this` variable inside listener function).
*/
2016-08-26 00:18:47 +00:00
context: any;
2016-06-17 11:46:47 +00:00
/**
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters).
*/
2016-08-26 00:18:47 +00:00
params: any[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
execute(paramsArr?: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
detach(): Function;
2016-06-17 11:46:47 +00:00
/**
*
* @return True if binding is still bound to the signal and has a listener.
*/
2016-08-26 00:18:47 +00:00
isBound(): boolean;
2016-06-17 11:46:47 +00:00
/**
*
* @return If SignalBinding will only be executed once.
*/
2016-08-26 00:18:47 +00:00
isOnce(): boolean;
2016-06-17 11:46:47 +00:00
/**
*
* @return Handler function bound to the signal.
*/
2016-08-26 00:18:47 +00:00
getListener(): Function;
2016-06-17 11:46:47 +00:00
/**
*
* @return Signal that listener is currently bound to.
*/
2016-08-26 00:18:47 +00:00
getSignal(): Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
*
* @return String representation of the object.
*/
2016-08-26 00:18:47 +00:00
toString(): string;
}
2016-06-17 11:46:47 +00:00
/**
* A single Phaser Gamepad
*/
2016-08-26 00:18:47 +00:00
class SinglePad {
2016-06-17 11:46:47 +00:00
/**
* A single Phaser Gamepad
*
* @param game Current game instance.
* @param padParent The parent Phaser.Gamepad object (all gamepads reside under this)
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, padParent: any);
2016-06-17 11:46:47 +00:00
/**
* The context under which the callbacks are run.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* Whether or not this particular gamepad is connected or not.
*/
2016-08-26 00:18:47 +00:00
connected: boolean;
2016-06-17 11:46:47 +00:00
/**
* Dead zone for axis feedback - within this value you won't trigger updates.
*/
2016-08-26 00:18:47 +00:00
deadZone: number;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The gamepad index as per browsers data
*/
2016-08-26 00:18:47 +00:00
index: number;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time an axis is changed.
*/
2016-08-26 00:18:47 +00:00
onAxisCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time this gamepad is connected
*/
2016-08-26 00:18:47 +00:00
onConnectCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time this gamepad is disconnected
*/
2016-08-26 00:18:47 +00:00
onDisconnectCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a button is pressed down.
*/
2016-08-26 00:18:47 +00:00
onDownCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a button is changed to a value where value > 0 and value < 1.
*/
2016-08-26 00:18:47 +00:00
onFloatCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This callback is invoked every time a gamepad button is released.
*/
2016-08-26 00:18:47 +00:00
onUpCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* Returns value of requested axis.
*
* @param axisCode The index of the axis to check
* @return Axis value if available otherwise false
*/
2016-08-26 00:18:47 +00:00
axis(axisCode: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
addCallbacks(context: any, callbacks: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
buttonValue(buttonCode: number): number;
2016-06-17 11:46:47 +00:00
/**
* Gamepad connect function, should be called by Phaser.Gamepad.
*
* @param rawPad The raw gamepad object
*/
2016-08-26 00:18:47 +00:00
connect(rawPad: any): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys this object and associated callback references.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Gamepad disconnect function, should be called by Phaser.Gamepad.
*/
2016-08-26 00:18:47 +00:00
disconnect(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getButton(buttonCode: number): Phaser.DeviceButton;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isDown(buttonCode: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isUp(buttonCode: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justPressed(buttonCode: number, duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
justReleased(buttonCode: number, duration?: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Main update function called by Phaser.Gamepad.
*/
2016-08-26 00:18:47 +00:00
pollStatus(): void;
2016-06-17 11:46:47 +00:00
/**
* Handles changes in axis.
*
* @param axisState State of the relevant axis
*/
2016-08-26 00:18:47 +00:00
processAxisChange(axisState: any): void;
2016-06-17 11:46:47 +00:00
/**
* Handles button down press.
*
* @param buttonCode Which buttonCode of this button
* @param value Button value
*/
2016-08-26 00:18:47 +00:00
processButtonDown(buttonCode: number, value: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
processButtonFloat(buttonCode: number, value: any): void;
2016-06-17 11:46:47 +00:00
/**
* Handles button release.
*
* @param buttonCode Which buttonCode of this button
* @param value Button value
*/
2016-08-26 00:18:47 +00:00
processButtonUp(buttonCode: number, value: any): void;
2016-06-17 11:46:47 +00:00
/**
* Reset all buttons/axes of this gamepad.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
}
2016-06-17 11:46:47 +00:00
/**
* The Sound class constructor.
*/
2016-08-26 00:18:47 +00:00
class Sound {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, key: string, volume?: number, loop?: boolean, connect?: boolean);
2016-06-17 11:46:47 +00:00
/**
* Boolean indicating whether the sound should start automatically.
*/
2016-08-26 00:18:47 +00:00
autoplay: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
allowMultiple: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the AudioContext instance.
*/
2016-08-26 00:18:47 +00:00
context: any;
2016-06-17 11:46:47 +00:00
/**
* The string ID of the currently playing marker, if any.
*/
2016-08-26 00:18:47 +00:00
currentMarker: string;
2016-06-17 11:46:47 +00:00
/**
* The current time the sound is at.
*/
2016-08-26 00:18:47 +00:00
currentTime: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
destroy(remove?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* The duration of the current sound marker in seconds.
*/
2016-08-26 00:18:47 +00:00
duration: number;
2016-06-17 11:46:47 +00:00
/**
* The duration of the current sound marker in ms.
*/
2016-08-26 00:18:47 +00:00
durationMS: number;
2016-06-17 11:46:47 +00:00
/**
* If defined this Sound won't connect to the SoundManager master gain node, but will instead connect to externalNode.
*/
2016-08-26 00:18:47 +00:00
externalNode: any;
2016-06-17 11:46:47 +00:00
/**
* The tween that fades the audio, set via Sound.fadeIn and Sound.fadeOut.
*/
2016-08-26 00:18:47 +00:00
fadeTween: Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The gain node in a Web Audio system.
*/
2016-08-26 00:18:47 +00:00
gainNode: any;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the sound file has decoded.
*/
2016-08-26 00:18:47 +00:00
isDecoded: boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the sound file is still decoding.
*/
2016-08-26 00:18:47 +00:00
isDecoding: boolean;
2016-06-17 11:46:47 +00:00
/**
* true if the sound is currently playing, otherwise false.
*/
2016-08-26 00:18:47 +00:00
isPlaying: boolean;
2016-06-17 11:46:47 +00:00
/**
* Asset key for the sound.
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* Whether or not the sound or current sound marker will loop.
*/
2016-08-26 00:18:47 +00:00
loop: boolean;
2016-06-17 11:46:47 +00:00
/**
* The sound markers.
*/
2016-08-26 00:18:47 +00:00
markers: any;
2016-06-17 11:46:47 +00:00
/**
* The master gain node in a Web Audio system.
*/
2016-08-26 00:18:47 +00:00
masterGainNode: any;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the muted state of this sound.
*/
2016-08-26 00:18:47 +00:00
mute: boolean;
2016-06-17 11:46:47 +00:00
/**
* Name of the sound.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* The onDecoded event is dispatched when the sound has finished decoding (typically for mp3 files)
*/
2016-08-26 00:18:47 +00:00
onDecoded: Phaser.Signal;
onEndedHandler: () => void;
2016-06-17 11:46:47 +00:00
/**
* The onFadeComplete event is dispatched when this sound finishes fading either in or out.
*/
2016-08-26 00:18:47 +00:00
onFadeComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onLoop event is dispatched when this sound loops during playback.
*/
2016-08-26 00:18:47 +00:00
onLoop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onMarkerComplete event is dispatched when a marker within this sound completes playback.
*/
2016-08-26 00:18:47 +00:00
onMarkerComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onMute event is dispatched when this sound is muted.
*/
2016-08-26 00:18:47 +00:00
onMute: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onPause event is dispatched when this sound is paused.
*/
2016-08-26 00:18:47 +00:00
onPause: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onPlay event is dispatched each time this sound is played.
*/
2016-08-26 00:18:47 +00:00
onPlay: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onResume event is dispatched when this sound is resumed from a paused state.
*/
2016-08-26 00:18:47 +00:00
onResume: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* The onStop event is dispatched when this sound stops playback.
*/
2016-08-26 00:18:47 +00:00
onStop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* if true when you play this sound it will always start from the beginning.
*/
2016-08-26 00:18:47 +00:00
override: boolean;
2016-06-17 11:46:47 +00:00
/**
* true if the sound is paused, otherwise false.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* The position the sound had reached when it was paused.
*/
2016-08-26 00:18:47 +00:00
pausedPosition: number;
2016-06-17 11:46:47 +00:00
/**
* The game time at which the sound was paused.
*/
2016-08-26 00:18:47 +00:00
pausedTime: number;
2016-06-17 11:46:47 +00:00
/**
* true if the sound file is pending playback
*/
2016-08-26 00:18:47 +00:00
pendingPlayback: boolean;
2016-06-17 11:46:47 +00:00
/**
* The position of the current sound marker.
*/
2016-08-26 00:18:47 +00:00
position: number;
2016-06-17 11:46:47 +00:00
/**
* The time the Sound starts at (typically 0 unless starting from a marker)
*/
2016-08-26 00:18:47 +00:00
startTime: number;
2016-06-17 11:46:47 +00:00
/**
* The time the sound stopped.
*/
2016-08-26 00:18:47 +00:00
stopTime: number;
2016-06-17 11:46:47 +00:00
/**
* The total duration of the sound in seconds.
*/
2016-08-26 00:18:47 +00:00
totalDuration: number;
2016-06-17 11:46:47 +00:00
/**
* true if the sound is being played via the Audio tag.
*/
2016-08-26 00:18:47 +00:00
usingAudioTag: boolean;
2016-06-17 11:46:47 +00:00
/**
* true if this sound is being played with Web Audio.
*/
2016-08-26 00:18:47 +00:00
usingWebAudio: boolean;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
volume: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addMarker(name: string, start: number, duration: number, volume?: number, loop?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
fadeIn(duration?: number, loop?: boolean, marker?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
fadeOut(duration?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fadeTo(duration?: number, volume?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
loopFull(volume?: number): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* Pauses the sound.
*/
2016-08-26 00:18:47 +00:00
pause(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
* @return This sound instance.
*/
2016-08-26 00:18:47 +00:00
play(marker?: string, position?: number, volume?: number, loop?: boolean, forceRestart?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* Removes a marker from the sound.
*
* @param name The key of the marker to remove.
*/
2016-08-26 00:18:47 +00:00
removeMarker(name: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
restart(marker: string, position: number, volume?: number, loop?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Resumes the sound.
*/
2016-08-26 00:18:47 +00:00
resume(): void;
2016-06-17 11:46:47 +00:00
/**
* Called automatically when this sound is unlocked.
*
* @param key The Phaser.Cache key of the sound file to check for decoding.
*/
2016-08-26 00:18:47 +00:00
soundHasUnlocked(key: string): void;
2016-06-17 11:46:47 +00:00
/**
* Stop playing this sound.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by Phaser.SoundManager.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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 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.
*/
2016-08-26 00:18:47 +00:00
class SoundManager {
2016-06-17 11:46:47 +00:00
/**
* 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 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* The number of audio channels to use in playback.
* Default: 32
*/
2016-08-26 00:18:47 +00:00
channels: number;
2016-06-17 11:46:47 +00:00
/**
* Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node.
* Default: true
*/
2016-08-26 00:18:47 +00:00
connectToMaster: boolean;
2016-06-17 11:46:47 +00:00
/**
* The AudioContext being used for playback.
*/
2016-08-26 00:18:47 +00:00
context: any;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the muted state of the SoundManager. This effects all sounds in the game.
*/
2016-08-26 00:18:47 +00:00
mute: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
muteOnPause: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
noAudio: boolean;
2016-06-17 11:46:47 +00:00
/**
* The event dispatched when a sound decodes (typically only for mp3 files)
*/
2016-08-26 00:18:47 +00:00
onSoundDecode: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched whenever the global volume changes. The new volume is passed as the only parameter to your callback.
*/
2016-08-26 00:18:47 +00:00
onVolumeChange: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* This signal is dispatched when the SoundManager is globally muted, either directly via game code or as a result of the game pausing.
*/
2016-08-26 00:18:47 +00:00
onMute: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onUnMute: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* true if the audio system is currently locked awaiting a touch event.
*/
2016-08-26 00:18:47 +00:00
touchLocked: boolean;
2016-06-17 11:46:47 +00:00
/**
* True the SoundManager and device are both using the Audio tag instead of Web Audio.
*/
2016-08-26 00:18:47 +00:00
usingAudioTag: boolean;
2016-06-17 11:46:47 +00:00
/**
* True the SoundManager and device are both using Web Audio.
*/
2016-08-26 00:18:47 +00:00
usingWebAudio: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
volume: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* Adds a new AudioSprite into the SoundManager.
*
* @param key Asset key for the sound.
* @return The new AudioSprite instance.
*/
2016-08-26 00:18:47 +00:00
addSprite(key: string): Phaser.AudioSprite;
2016-06-17 11:46:47 +00:00
/**
* Initialises the sound manager.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
decode(key: string, sound?: Phaser.Sound): void;
2016-06-17 11:46:47 +00:00
/**
* Stops all the sounds in the game, then destroys them and finally clears up any callbacks.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Pauses all the sounds in the game.
*/
2016-08-26 00:18:47 +00:00
pauseAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(key: string, volume?: number, loop?: boolean): Phaser.Sound;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
remove(sound: Phaser.Sound): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeByKey(key: string): number;
2016-06-17 11:46:47 +00:00
/**
* Resumes every sound in the game.
*/
2016-08-26 00:18:47 +00:00
resumeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setDecodedCallback(files: string[] | Phaser.Sound[], callback: Function, callbackContext: any): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the Input Manager touch callback to be SoundManager.unlock.
* Required for iOS audio device unlocking. Mostly just used internally.
*/
2016-08-26 00:18:47 +00:00
setTouchLock(): void;
2016-06-17 11:46:47 +00:00
/**
* Stops all the sounds in the game.
*/
2016-08-26 00:18:47 +00:00
stopAll(): void;
2016-06-17 11:46:47 +00:00
/**
* Enables the audio, usually after the first touch.
* @return True if the callback should be removed, otherwise false.
*/
2016-08-26 00:18:47 +00:00
unlock(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Updates every sound in the game, checks for audio unlock on mobile and monitors the decoding watch list.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Sprite extends PIXI.Sprite {
2016-06-17 11:46:47 +00:00
/**
* 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.
* @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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number);
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* The anchor sets the origin point of the texture.
* The default is 0,0 this means the texture's origin is the top left
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right corner
*/
2016-08-26 00:18:47 +00:00
anchor: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* `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.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The center x coordinate of the Game Object.
* This is the same as `(x - offsetX) + (width / 2)`.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* The center y coordinate of the Game Object.
* This is the same as `(y - offsetY) + (height / 2)`.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cropRect: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
2016-08-26 00:18:47 +00:00
customRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
deltaY: number;
2016-06-17 11:46:47 +00:00
/**
* Returns the delta z value. The difference between rotation now and in the previous frame. The delta value.
*/
2016-08-26 00:18:47 +00:00
deltaZ: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frame: string | number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frameName: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
health: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
2016-08-26 00:18:47 +00:00
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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 the millisecond equivalent of `game.time.physicsElapsed` each frame.
* When it reaches zero it will call the `kill` method.
*
* Very handy for particles, bullets, collectibles, or any other short-lived entity.
*/
2016-08-26 00:18:47 +00:00
lifespan: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
maxHealth: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
2016-08-26 00:18:47 +00:00
outOfBoundsKill: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
position: Phaser.Point;
physicsEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
scale: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleMin: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleMax: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* A canvas that contains the tinted version of the Sprite (in Canvas mode, WebGL doesn't populate this)
* Default: null
*/
2016-08-26 00:18:47 +00:00
tintedTexture: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* The callback that will apply any scale limiting to the worldTransform.
*/
2016-08-26 00:18:47 +00:00
transformCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The context under which `transformCallback` is called.
*/
2016-08-26 00:18:47 +00:00
transformCallbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the x axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* The position of the Game Object on the y axis relative to the local coordinates of the parent.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Brings this Game Object to the top of its parents display list.
* Visually this means it will render over the top of any old child in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
bringToTop(): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
crop(rect: Phaser.Rectangle, copy: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Adjust scaling limits, if set, to this Game Object.
*
* @param wt The updated worldTransform matrix.
*/
2016-08-26 00:18:47 +00:00
checkTransform(wt: PIXI.Matrix): void;
damage(amount: number): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* Destroys the Game Object. This removes it from its parent group, destroys the input, event and animation handlers if present
* and nulls its reference to `game`, freeing it up for garbage collection.
*
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
*
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
* @param destroyChildren Should every child of this object have its destroy method called as well? - Default: true
* @param destroyTexture Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
drawPolygon(): void;
heal(amount: number): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
kill(): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Moves this Game Object up one place in its parents 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.
*/
2016-08-26 00:18:47 +00:00
moveUp(): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
moveDown(): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* Internal method called by the World postUpdate cycle.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
* @return True if the Sprite was rendered, otherwise false.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
2016-08-26 00:18:47 +00:00
resetFrame(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
revive(health?: number): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Sends this Game Object to the bottom of its parents display list.
* Visually this means it will render below all other children in the same Group.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
sendToBack(): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrame(frame: Phaser.Frame): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateCrop(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class SpriteBatch extends Phaser.Group {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, parent: PIXI.DisplayObjectContainer, name?: string, addedToStage?: boolean);
2016-06-17 11:46:47 +00:00
/**
* Internal Phaser Type value.
*/
2016-08-26 00:18:47 +00:00
type: number;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Stage extends PIXI.DisplayObjectContainer {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The name of this object.
* Default: _stage_root
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
disableVisibilityChange: boolean;
2016-06-17 11:46:47 +00:00
/**
* If exists is true the Stage and all children are updated, otherwise it is skipped.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reset each frame, keeps a count of the total number of objects updated.
*/
2016-08-26 00:18:47 +00:00
currentRenderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000'
*/
2016-08-26 00:18:47 +00:00
backgroundColor: any;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* Parses a Game configuration object.
*
* @param config The configuration object to parse.
*/
2016-08-26 00:18:47 +00:00
parseConfig(config: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* This is called automatically after the State.update, but before particles or plugins update.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateTransform(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkVisibility(): void;
2016-06-17 11:46:47 +00:00
/**
* This method is called when the document visibility is changed.
*
* @param event Its type will be used to decide whether the game should be paused or not.
*/
2016-08-26 00:18:47 +00:00
visibilityChange(event: Event): void;
2016-06-17 11:46:47 +00:00
/**
* 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 transparent then calls to setBackgroundColor are ignored.
*
* @param color The color of the background.
*/
2016-08-26 00:18:47 +00:00
setBackgroundColor(backgroundColor: number | string): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys the Stage and removes event listeners.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
}
interface ResizeCallback {
(scale: ScaleManager, parentBounds: Rectangle): any;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class ScaleManager {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, width: number | string, height: number | string);
2016-06-17 11:46:47 +00:00
/**
* A scale mode that stretches content to fill all available space - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
2016-08-26 00:18:47 +00:00
static EXACT_FIT: number;
2016-06-17 11:46:47 +00:00
/**
* A scale mode that prevents any scaling - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
2016-08-26 00:18:47 +00:00
static NO_SCALE: number;
2016-06-17 11:46:47 +00:00
/**
* A scale mode that shows the entire game while maintaining proportions - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
2016-08-26 00:18:47 +00:00
static SHOW_ALL: number;
2016-06-17 11:46:47 +00:00
/**
* A scale mode that causes the Game size to change - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
2016-08-26 00:18:47 +00:00
static RESIZE: number;
2016-06-17 11:46:47 +00:00
/**
* A scale mode that allows a custom scale factor - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
2016-08-26 00:18:47 +00:00
static USER_SCALE: number;
2016-06-17 11:46:47 +00:00
/**
* The aspect ratio of the scaled Display canvas.
*/
2016-08-26 00:18:47 +00:00
aspectRatio: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bounds: Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
boundingParent: HTMLElement;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
compatibility: {
canExpandParent: boolean;
clickTrampoline: string;
forceMinimumDocumentHeight: boolean;
noMargins: boolean;
scrollTo: Point;
supportsFullScreen: boolean;
};
2016-06-17 11:46:47 +00:00
/**
* Returns the current scale mode - for normal or fullscreen operation.
*
* See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed.
*/
2016-08-26 00:18:47 +00:00
currentScaleMode: number;
2016-06-17 11:46:47 +00:00
/**
* Provides access to some cross-device DOM functions.
*/
2016-08-26 00:18:47 +00:00
dom: Phaser.DOM;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
enterIncorrectOrientation: Signal;
2016-06-17 11:46:47 +00:00
/**
* The native browser events from Fullscreen API changes.
*/
2016-08-26 00:18:47 +00:00
event: any;
2016-06-17 11:46:47 +00:00
/**
* If true, the game should only run in a landscape orientation.
* Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*/
2016-08-26 00:18:47 +00:00
forceLandscape: boolean;
2016-06-17 11:46:47 +00:00
/**
* If true, the game should only run in a portrait
* Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*/
2016-08-26 00:18:47 +00:00
forcePortrait: boolean;
2016-06-17 11:46:47 +00:00
/**
* The scaling method used by the ScaleManager when in fullscreen.
*
* See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed.
*/
2016-08-26 00:18:47 +00:00
fullScreenScaleMode: number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
fullScreenTarget: HTMLElement;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* _EXPERIMENTAL:_ A responsive grid on which you can align game objects.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Target height (in pixels) of the Display canvas.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
incorrectOrientation: boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the browser is in fullscreen mode, otherwise false.
*/
2016-08-26 00:18:47 +00:00
isFullScreen: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isGameLandscape: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isGamePortrait: boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the screen orientation is in portrait mode.
*/
2016-08-26 00:18:47 +00:00
isPortrait: boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns true if the screen orientation is in landscape mode.
*/
2016-08-26 00:18:47 +00:00
isLandscape: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
leaveIncorrectOrientation: Signal;
2016-06-17 11:46:47 +00:00
/**
* The Display canvas is aligned by adjusting the margins; the last margins are stored here.
*/
2016-08-26 00:18:47 +00:00
margin: { left: number; top: number; right: number; bottom: number; x: number; y: number; };
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
maxHeight: number;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
maxWidth: number;
2016-06-17 11:46:47 +00:00
/**
* Minimum height the canvas should be scaled to (in pixels).
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
2016-08-26 00:18:47 +00:00
minHeight: number;
2016-06-17 11:46:47 +00:00
/**
* Minimum width the canvas should be scaled to (in pixels).
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
2016-08-26 00:18:47 +00:00
minWidth: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offset: Point;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
onFullScreenInit: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onFullScreenChange: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
onFullScreenError: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onOrientationChange: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
onSizeChange: Signal;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
pageAlignHorizontally: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
pageAlignVertically: boolean;
2016-06-17 11:46:47 +00:00
/**
* The _original_ DOM element for the parent of the Display canvas.
* This may be different in fullscreen - see {@link Phaser.ScaleManager#createFullScreenTarget createFullScreenTarget}.
*
* This should only be changed after moving the Game canvas to a different DOM parent.
*/
2016-08-26 00:18:47 +00:00
parentNode: HTMLElement;
2016-06-17 11:46:47 +00:00
/**
* If the parent container of the Game canvas is the browser window itself (i.e. document.body),
* rather than another div, this should set to `true`.
*
* The {@link Phaser.ScaleManager#parentNode parentNode} property is generally ignored while this is in effect.
*/
2016-08-26 00:18:47 +00:00
parentIsWindow: boolean;
2016-06-17 11:46:47 +00:00
/**
* The scale of the game in relation to its parent container.
*/
2016-08-26 00:18:47 +00:00
parentScaleFactor: Point;
2016-06-17 11:46:47 +00:00
/**
* The _current_ scale factor based on the game dimensions vs. the scaled dimensions.
*/
2016-08-26 00:18:47 +00:00
scaleFactor: Point;
2016-06-17 11:46:47 +00:00
/**
* The _current_ inversed scale factor. The displayed dimensions divided by the game dimensions.
*/
2016-08-26 00:18:47 +00:00
scaleFactorInversed: Point;
2016-06-17 11:46:47 +00:00
/**
* The scaling method used by the ScaleManager when not in fullscreen.
*
* <dl>
* <dt>{@link Phaser.ScaleManager.NO_SCALE}</dt>
* <dd>
* 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.
* </dd>
* <dt>{@link Phaser.ScaleManager.EXACT_FIT}</dt>
* <dd>
* 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.
* </dd>
* <dt>{@link Phaser.ScaleManager.SHOW_ALL}</dt>
* <dd>
* Show the entire game display area while _maintaining_ the original aspect ratio.
* </dd>
* <dt>{@link Phaser.ScaleManager.RESIZE}</dt>
* <dd>
* 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.
* <p>
* Any manually set Game size (see {@link Phaser.ScaleManager#setGameSize setGameSize}) is ignored while in effect.
* </dd>
* <dt>{@link Phaser.ScaleManager.USER_SCALE}</dt>
* <dd>
* The game Display is scaled according to the user-specified scale set by {@link Phaser.ScaleManager#setUserScale setUserScale}.
* <p>
* This scale can be adjusted in the {@link Phaser.ScaleManager#setResizeCallback resize callback}
* for flexible custom-sizing needs.
* </dd>
* </dl>
*/
2016-08-26 00:18:47 +00:00
scaleMode: number;
2016-06-17 11:46:47 +00:00
/**
* The _last known_ orientation of the screen, as defined in the Window Screen Web API.
* See {@link Phaser.DOM.getScreenOrientation} for possible values.
*/
2016-08-26 00:18:47 +00:00
screenOrientation: string;
2016-06-17 11:46:47 +00:00
/**
* The aspect ratio of the original game dimensions.
*/
2016-08-26 00:18:47 +00:00
sourceAspectRatio: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
trackParentInterval: number;
2016-06-17 11:46:47 +00:00
/**
* Target width (in pixels) of the Display canvas.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* 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":""}
*/
2016-08-26 00:18:47 +00:00
windowConstraints: {
bottom: string;
right: string;
};
2016-06-17 11:46:47 +00:00
/**
* Start the ScaleManager.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createFullScreenTarget(): HTMLDivElement;
2016-06-17 11:46:47 +00:00
/**
* Destroys the ScaleManager and removes any event listeners.
* This should probably only be called when the game is destroyed.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
forceOrientation(forceLandscape: boolean, forcePortrait?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)
* @return The established parent bounds.
*/
2016-08-26 00:18:47 +00:00
getParentBounds(target?: Rectangle): Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Load configuration settings.
*
* @param config The game configuration object.
*/
2016-08-26 00:18:47 +00:00
parseConfig(config: any): void;
2016-06-17 11:46:47 +00:00
/**
* The ScaleManager.preUpdate is called automatically by the core Game loop.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Update method while paused.
*/
2016-08-26 00:18:47 +00:00
pauseUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
refresh(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setGameSize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the callback that will be invoked before sizing calculations.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
setResizeCallback(callback: ResizeCallback, context: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*
* @param hScale Horizontal scaling factor.
* @param vScale Vertical scaling factor.
* @param hTrim Horizontal trim, applied after scaling.
* @param vTrim Vertical trim, applied after scaling.
*/
2016-08-26 00:18:47 +00:00
setUserScale(hScale: number, vScale: number, hTrim?: number, vTrim?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setMinMax(minWidth: number, minHeight: number, maxWidth?: number, maxHeight?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setupScale(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setupScale(width: string, height: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleSprite(sprite: Sprite, width?: number, height?: number, letterBox?: boolean): Sprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
scaleSprite(sprite: Image, width?: number, height?: number, letterBox?: boolean): Sprite;
2016-06-17 11:46:47 +00:00
/**
* Start the browsers fullscreen mode - this _must_ be called from a user input Pointer or Mouse event.
*
* The Fullscreen API must be 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.
*
* @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.
* @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.)
*/
2016-08-26 00:18:47 +00:00
startFullScreen(antialias?: boolean, allowTrampoline?: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Stops / exits fullscreen mode, if active.
* @return Returns true if the browser supports fullscreen mode and fullscreen mode will be exited.
*/
2016-08-26 00:18:47 +00:00
stopFullScreen(): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class DOM {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static visualBounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static layoutBounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* The size of the document / Layout viewport.
*
* This incorrectly reports the dimensions in IE.
*
* The properties change dynamically.
*/
2016-08-26 00:18:47 +00:00
static documentBounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
static calibrate(coords: any, cushion?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getAspectRatio(object: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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)
*/
2016-08-26 00:18:47 +00:00
static getScreenOrientation(primaryFallback?: string): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getBounds(element: any, cushion?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static getOffset(element: any, point?: Point): Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static inLayoutViewport(element: any, cushion?: number): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class State {
2016-06-17 11:46:47 +00:00
/**
* A reference to the GameObjectFactory which can be used to add new objects to the World.
*/
2016-08-26 00:18:47 +00:00
add: Phaser.GameObjectFactory;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game cache which contains any loaded or generated assets, such as images, sound and more.
*/
2016-08-26 00:18:47 +00:00
cache: Phaser.Cache;
2016-06-17 11:46:47 +00:00
/**
* A handy reference to World.camera.
*/
2016-08-26 00:18:47 +00:00
camera: Phaser.Camera;
2016-06-17 11:46:47 +00:00
/**
* This is a reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Input Manager.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.Input;
2016-06-17 11:46:47 +00:00
/**
* The string based identifier given to the State when added into the State Manager.
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Loader, which you mostly use in the preload method of your state to load external assets.
*/
2016-08-26 00:18:47 +00:00
load: Phaser.Loader;
2016-06-17 11:46:47 +00:00
/**
* A reference to the GameObjectCreator which can be used to make new objects.
*/
2016-08-26 00:18:47 +00:00
make: Phaser.GameObjectCreator;
2016-06-17 11:46:47 +00:00
/**
* The Particle Manager. It is called during the core gameloop and updates any Particle Emitters it has created.
*/
2016-08-26 00:18:47 +00:00
particles: Phaser.Particles;
2016-06-17 11:46:47 +00:00
/**
* A reference to the physics manager which looks after the different physics systems available within Phaser.
*/
2016-08-26 00:18:47 +00:00
physics: Phaser.Physics;
2016-06-17 11:46:47 +00:00
/**
* A reference to the seeded and repeatable random data generator.
*/
2016-08-26 00:18:47 +00:00
rnd: Phaser.RandomDataGenerator;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Scale Manager which controls the way the game scales on different displays.
*/
2016-08-26 00:18:47 +00:00
scale: Phaser.ScaleManager;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Sound Manager which can create, play and stop sounds, as well as adjust global volume.
*/
2016-08-26 00:18:47 +00:00
sound: Phaser.SoundManager;
2016-06-17 11:46:47 +00:00
/**
* A reference to the Stage.
*/
2016-08-26 00:18:47 +00:00
stage: Phaser.Stage;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game clock and timed events system.
*/
2016-08-26 00:18:47 +00:00
time: Phaser.Time;
2016-06-17 11:46:47 +00:00
/**
* A reference to the tween manager.
*/
2016-08-26 00:18:47 +00:00
tweens: Phaser.TweenManager;
2016-06-17 11:46:47 +00:00
/**
* A reference to the game world. All objects live in the Game World and its size is not bound by the display resolution.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.World;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
create(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
init(...args: any[]): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
loadRender(): void;
2016-06-17 11:46:47 +00:00
/**
* loadUpdate is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.
*/
2016-08-26 00:18:47 +00:00
loadUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* This method will be called if the core game loop is paused.
*/
2016-08-26 00:18:47 +00:00
paused(): void;
2016-06-17 11:46:47 +00:00
/**
* pauseUpdate is called while the game is paused instead of preUpdate, update and postUpdate.
*/
2016-08-26 00:18:47 +00:00
pauseUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
preload(): void;
2016-06-17 11:46:47 +00:00
/**
* The preRender method is called after all Game Objects have been updated, but before any rendering takes place.
*/
2016-08-26 00:18:47 +00:00
preRender(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
render(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resize(): void;
2016-06-17 11:46:47 +00:00
/**
* This method will be called when the core game loop resumes from a paused state.
*/
2016-08-26 00:18:47 +00:00
resumed(): void;
2016-06-17 11:46:47 +00:00
/**
* This method will be called when the State is shutdown (i.e. you switch to another state from this one).
*/
2016-08-26 00:18:47 +00:00
shutdown(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
interface IStateCycle {
preUpdate(): void;
update(): void;
render(): void;
postRender(): void;
destroy(): void;
}
2016-06-17 11:46:47 +00:00
/**
* The State Manager is responsible for loading, setting up and switching game states.
*/
2016-08-26 00:18:47 +00:00
class StateManager {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, pendingState?: Phaser.State);
2016-06-17 11:46:47 +00:00
/**
* True if the current state has had its `create` method run (if it has one, if not this is true by default).
*/
2016-08-26 00:18:47 +00:00
created: boolean;
2016-06-17 11:46:47 +00:00
/**
* The current active State object.
*/
2016-08-26 00:18:47 +00:00
current: string;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* This is called when the state preload has finished and creation begins.
*/
2016-08-26 00:18:47 +00:00
onCreateCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the state is set as the active state.
*/
2016-08-26 00:18:47 +00:00
onInitCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the State is rendered during the preload phase.
*/
2016-08-26 00:18:47 +00:00
onLoadRenderCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the State is updated during the preload phase.
*/
2016-08-26 00:18:47 +00:00
onLoadUpdateCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the game is paused.
*/
2016-08-26 00:18:47 +00:00
onPausedCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called every frame while the game is paused.
*/
2016-08-26 00:18:47 +00:00
onPauseUpdateCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the state starts to load assets.
*/
2016-08-26 00:18:47 +00:00
onPreloadCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onPreRenderCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called post-render. It doesn't happen during preload (see onLoadRenderCallback).
*/
2016-08-26 00:18:47 +00:00
onRenderCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the game is resumed from a paused state.
*/
2016-08-26 00:18:47 +00:00
onResumedCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called if ScaleManager.scalemode is RESIZE and a resize event occurs. It's passed the new width and height.
*/
2016-08-26 00:18:47 +00:00
onResizeCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the state is shut down (i.e. swapped to another state).
*/
2016-08-26 00:18:47 +00:00
onShutDownCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* This is called when the state is updated, every game loop. It doesn't happen during preload (@see onLoadUpdateCallback).
*/
2016-08-26 00:18:47 +00:00
onUpdateCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The object containing Phaser.States.
*/
2016-08-26 00:18:47 +00:00
states: any;
2016-06-17 11:46:47 +00:00
/**
* 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 (such as preload and create) are called, and *after* the previous states 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.
*/
2016-08-26 00:18:47 +00:00
onStateChange: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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 either a Phaser.State object (or an object that extends it), a plain JavaScript object or a function.
* If a function is given a new state object will be created by calling it.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
add(key: string, state: any, autoStart?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkState(key: string): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
clearCurrentState(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Gets the current State.
*/
2016-08-26 00:18:47 +00:00
getCurrentState(): Phaser.State;
2016-06-17 11:46:47 +00:00
/**
* Links game properties to the State given by the key.
*
* @param key State key.
*/
2016-08-26 00:18:47 +00:00
link(key: string): void;
loadComplete(): void;
2016-06-17 11:46:47 +00:00
/**
*
*
* @param elapsedTime The time elapsed since the last update.
*/
2016-08-26 00:18:47 +00:00
preRender(elapsedTime: number): void;
2016-06-17 11:46:47 +00:00
/**
* preUpdate is called right at the start of the game loop. It is responsible for changing to a new state that was requested previously.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
render(): void;
2016-06-17 11:46:47 +00:00
/**
* Delete the given state.
*
* @param key A unique key you use to reference this state, i.e. "MainMenu", "Level1".
*/
2016-08-26 00:18:47 +00:00
remove(key: string): void;
resume(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
restart(clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void;
resize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
start(key: string, clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void;
update(): void;
2016-06-17 11:46:47 +00:00
/**
* Nulls all State level Phaser properties, including a reference to Game.
*
* @param key State key.
*/
2016-08-26 00:18:47 +00:00
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;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Text extends Phaser.Sprite {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, text: string, style?: PhaserTextStyle);
static fontPropertiesCanvas: any;
static fontPropertiesContext: any;
static fontPropertiesCache: any;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
align: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoRound: boolean;
2016-06-17 11:46:47 +00:00
/**
* Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'.
*/
2016-08-26 00:18:47 +00:00
boundsAlignH: string;
2016-06-17 11:46:47 +00:00
/**
* Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'.
*/
2016-08-26 00:18:47 +00:00
boundsAlignV: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The canvas element that the text is rendered.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* An array of the color values as specified by {@link Phaser.Text#addColor addColor}.
*/
2016-08-26 00:18:47 +00:00
colors: string[];
2016-06-17 11:46:47 +00:00
/**
* The context of the canvas element that the text is rendered to.
*/
2016-08-26 00:18:47 +00:00
context: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cssFont: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
*/
2016-08-26 00:18:47 +00:00
fill: any;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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'`.
*/
2016-08-26 00:18:47 +00:00
font: string;
2016-06-17 11:46:47 +00:00
/**
* 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'`).
*/
2016-08-26 00:18:47 +00:00
fontSize: number | string;
2016-06-17 11:46:47 +00:00
/**
* The style of the font: 'normal', 'italic', 'oblique'
*/
2016-08-26 00:18:47 +00:00
fontStyle: string;
2016-06-17 11:46:47 +00:00
/**
* An array of the font styles values as specified by {@link Phaser.Text#addFontStyle addFontStyle}.
*/
2016-08-26 00:18:47 +00:00
fontStyles: string[];
2016-06-17 11:46:47 +00:00
/**
* The variant the font: 'normal', 'small-caps'
*/
2016-08-26 00:18:47 +00:00
fontVariant: string;
2016-06-17 11:46:47 +00:00
/**
* 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}.
*/
2016-08-26 00:18:47 +00:00
fontWeight: string | number;
2016-06-17 11:46:47 +00:00
/**
* An array of the font weights values as specified by {@link Phaser.Text#addFontWeight addFontWeight}.
*/
2016-08-26 00:18:47 +00:00
fontWeights: (string | number)[];
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Additional spacing (in pixels) between each line of text if multi-line.
*/
2016-08-26 00:18:47 +00:00
lineSpacing: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
padding: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
2016-08-26 00:18:47 +00:00
previousRotation: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resolution: number;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
shadowBlur: number;
2016-06-17 11:46:47 +00:00
/**
* The color of the shadow, as given in CSS rgba format. Set the alpha component to 0 to disable the shadow.
*/
2016-08-26 00:18:47 +00:00
shadowColor: string;
2016-06-17 11:46:47 +00:00
/**
* Sets if the drop shadow is applied to the Text fill.
*/
2016-08-26 00:18:47 +00:00
shadowFill: boolean;
2016-06-17 11:46:47 +00:00
/**
* The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
*/
2016-08-26 00:18:47 +00:00
shadowOffsetX: number;
2016-06-17 11:46:47 +00:00
/**
* The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
*/
2016-08-26 00:18:47 +00:00
shadowOffsetY: number;
2016-06-17 11:46:47 +00:00
/**
* Sets if the drop shadow is applied to the Text stroke.
*/
2016-08-26 00:18:47 +00:00
shadowStroke: boolean;
2016-06-17 11:46:47 +00:00
/**
* A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'.
*/
2016-08-26 00:18:47 +00:00
stroke: string;
2016-06-17 11:46:47 +00:00
/**
* An array of the stroke color values as specified by {@link Phaser.Text#addStrokeColor addStrokeColor}.
*/
2016-08-26 00:18:47 +00:00
strokeColors: string[];
2016-06-17 11:46:47 +00:00
/**
* A number that represents the thickness of the stroke. Default is 0 (no stroke)
*/
2016-08-26 00:18:47 +00:00
strokeThickness: number;
scale: Phaser.Point;
tab: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
tabs: number | number[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text: string;
2016-06-17 11:46:47 +00:00
/**
* The textBounds property allows you to specify a rectangular region upon which text alignment is based.
* See `Text.setTextBounds` for more details.
*/
2016-08-26 00:18:47 +00:00
textBounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
useAdvancedWrap: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* Indicates if word wrap should be used.
*/
2016-08-26 00:18:47 +00:00
wordWrap: boolean;
2016-06-17 11:46:47 +00:00
/**
* The width at which text will wrap.
*/
2016-08-26 00:18:47 +00:00
wordWrapWidth: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addColor(color: string, position: number): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addFontStyle(style: string, position: number): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addFontWeight(weight: string, position: number): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addStrokeColor(color: string, position: number): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* Clears any text fill or stroke colors that were set by `addColor` or `addStrokeColor`.
* @return This Text instance.
*/
2016-08-26 00:18:47 +00:00
clearColors(): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* Clears any text styles or weights font that were set by `addFontStyle` or `addFontWeight`.
* @return This Text instance.
*/
2016-08-26 00:18:47 +00:00
clearFontValues(): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* Converts individual font components (see `fontToComponents`) to a short CSS font string.
*
* @param components Font components.
*/
2016-08-26 00:18:47 +00:00
componentsToFont(components: any): string;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Converting a short CSS-font string into the relevant components.
*
* @param font a CSS font string
*/
2016-08-26 00:18:47 +00:00
fontToComponents(font: string): any;
2016-06-17 11:46:47 +00:00
/**
* Internal method called by the World postUpdate cycle.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
parseList(list: any[]): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
precalculateWordWrap(text: string): string[];
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderTabLine(line: string, x: number, y: number, fill?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setShadow(x?: number, y?: number, color?: any, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setStyle(style?: PhaserTextStyle, update?: boolean): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
2016-07-01 15:57:13 +00:00
* 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.
*
2016-06-17 11:46:47 +00:00
* @param text The text to be displayed. Set to an empty string to clear text that is already present.
2016-07-01 15:57:13 +00:00
* @param immediate Update the texture used by this Text object immediately (true) or automatically during the next render loop (false).
2016-06-17 11:46:47 +00:00
* @return This Text instance.
*/
2016-08-26 00:18:47 +00:00
setText(text: string, immediate?: boolean): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTextBounds(x?: number, y?: number, width?: number, height?: number): Phaser.Text;
2016-06-17 11:46:47 +00:00
/**
* Override this function to handle any special update requirements.
*/
2016-08-26 00:18:47 +00:00
update(): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the internal `style.font` if it now differs according to generation from components.
*
* @param components Font components.
*/
2016-08-26 00:18:47 +00:00
updateFont(components: any): void;
2016-06-17 11:46:47 +00:00
/**
* Updates a line of text, applying fill and stroke per-character colors or style and weight per-character font if applicable.
*/
2016-08-26 00:18:47 +00:00
updateLine(text: string, x?: number, y?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateShadow(state?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Updates the texture based on the canvas dimensions.
*/
2016-08-26 00:18:47 +00:00
updateTexture(): void;
}
2016-06-17 11:46:47 +00:00
/**
* A Tile is a representation of a single tile within the Tilemap.
*/
2016-08-26 00:18:47 +00:00
class Tile {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(layer: any, index: number, x: number, y: Number, width: number, height: number);
2016-06-17 11:46:47 +00:00
/**
* The alpha value at which this tile is drawn to the canvas.
*/
2016-08-26 00:18:47 +00:00
alpha: number;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
callback: Function;
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* The width of the tile in pixels.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the tile in pixels.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* True if this tile can collide on any of its faces or has a collision callback set.
*/
2016-08-26 00:18:47 +00:00
canCollide: boolean;
2016-06-17 11:46:47 +00:00
/**
* Indicating collide with any object on the bottom.
*/
2016-08-26 00:18:47 +00:00
collideDown: boolean;
2016-06-17 11:46:47 +00:00
/**
* Indicating collide with any object on the left.
*/
2016-08-26 00:18:47 +00:00
collideLeft: boolean;
collideNone: boolean;
2016-06-17 11:46:47 +00:00
/**
* Indicating collide with any object on the right.
*/
2016-08-26 00:18:47 +00:00
collideRight: boolean;
2016-06-17 11:46:47 +00:00
/**
* Tile collision callback.
*/
2016-08-26 00:18:47 +00:00
collisionCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* The context in which the collision callback will be called.
*/
2016-08-26 00:18:47 +00:00
collisionCallbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* True if this tile can collide on any of its faces.
*/
2016-08-26 00:18:47 +00:00
collides: boolean;
2016-06-17 11:46:47 +00:00
/**
* Indicating collide with any object on the top.
*/
2016-08-26 00:18:47 +00:00
collideUp: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the bottom of this tile an interesting edge?
*/
2016-08-26 00:18:47 +00:00
faceBottom: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the left of this tile an interesting edge?
*/
2016-08-26 00:18:47 +00:00
faceLeft: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the right of this tile an interesting edge?
*/
2016-08-26 00:18:47 +00:00
faceRight: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is the top of this tile an interesting edge?
*/
2016-08-26 00:18:47 +00:00
faceTop: boolean;
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The height of the tile in pixels.
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The index of this tile within the map data corresponding to the tileset, or -1 if this represents a blank/null tile.
*/
2016-08-26 00:18:47 +00:00
index: number;
2016-06-17 11:46:47 +00:00
/**
* The layer in the Tilemap data that this tile belongs to.
*/
2016-08-26 00:18:47 +00:00
layer: any;
2016-06-17 11:46:47 +00:00
/**
* The x value in pixels.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* Tile specific properties.
*/
2016-08-26 00:18:47 +00:00
properties: any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the x and width properties.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* Has this tile been walked / turned into a poly?
*/
2016-08-26 00:18:47 +00:00
scanned: boolean;
2016-06-17 11:46:47 +00:00
/**
* The y value.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the tile in pixels.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The x map coordinate of this tile.
*/
2016-08-26 00:18:47 +00:00
worldX: number;
2016-06-17 11:46:47 +00:00
/**
* The y map coordinate of this tile.
*/
2016-08-26 00:18:47 +00:00
worldY: number;
2016-06-17 11:46:47 +00:00
/**
* The x map coordinate of this tile.
*/
2016-08-26 00:18:47 +00:00
x: number;
2016-06-17 11:46:47 +00:00
/**
* The y map coordinate of this tile.
*/
2016-08-26 00:18:47 +00:00
y: number;
2016-06-17 11:46:47 +00:00
/**
* Copies the tile data and properties from the given tile to this tile.
*
* @param tile The tile to copy from.
*/
2016-08-26 00:18:47 +00:00
copy(tile: Phaser.Tile): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
containsPoint(x: number, y: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Clean up memory.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
intersects(x: number, y: number, right: number, bottom: number): boolean;
isInterested(collides: boolean, faces: boolean): boolean;
2016-06-17 11:46:47 +00:00
/**
* Reset collision status flags.
*/
2016-08-26 00:18:47 +00:00
resetCollision(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setCollision(left: boolean, right: boolean, up: boolean, down: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setCollisionCallback(callback: Function, context: any): void;
}
2016-06-17 11:46:47 +00:00
/**
* Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
2016-08-26 00:18:47 +00:00
*
* Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
*
2016-06-17 11:46:47 +00:00
* 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.
*/
2016-08-26 00:18:47 +00:00
class Tilemap {
2016-06-17 11:46:47 +00:00
/**
* Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
2016-08-26 00:18:47 +00:00
*
* Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
*
2016-06-17 11:46:47 +00:00
* 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
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* An array of collision data (polylines, etc).
*/
2016-08-26 00:18:47 +00:00
collision: any[];
2016-06-17 11:46:47 +00:00
/**
* An array of tile indexes that collide.
*/
2016-08-26 00:18:47 +00:00
collideIndexes: any[];
2016-06-17 11:46:47 +00:00
/**
* The current layer.
*/
2016-08-26 00:18:47 +00:00
currentLayer: number;
2016-06-17 11:46:47 +00:00
/**
* Map data used for debug values only.
*/
2016-08-26 00:18:47 +00:00
debugMap: any[];
/**
* If set then console.log is used to dump out useful layer creation debug data.
*/
enableDebug: boolean;
2016-06-17 11:46:47 +00:00
/**
* The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
*/
2016-08-26 00:18:47 +00:00
format: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The height of the map (in tiles).
*/
2016-08-26 00:18:47 +00:00
height: number;
2016-06-17 11:46:47 +00:00
/**
* The height of the map in pixels based on height * tileHeight.
*/
2016-08-26 00:18:47 +00:00
heightInPixels: number;
2016-06-17 11:46:47 +00:00
/**
* An array of Tiled Image Layers.
*/
2016-08-26 00:18:47 +00:00
images: any[];
2016-06-17 11:46:47 +00:00
/**
* An array of Image Collections.
*/
2016-08-26 00:18:47 +00:00
imagecollections: ImageCollection[];
2016-06-17 11:46:47 +00:00
/**
* The key of this map data in the Phaser.Cache.
*/
2016-08-26 00:18:47 +00:00
key: string;
2016-06-17 11:46:47 +00:00
/**
* The current layer object.
*/
2016-08-26 00:18:47 +00:00
layer: Phaser.TilemapLayer[];
2016-06-17 11:46:47 +00:00
/**
* An array of Tilemap layer data.
*/
2016-08-26 00:18:47 +00:00
layers: any[];
2016-06-17 11:46:47 +00:00
/**
* An array of Tiled Object Layers.
*/
2016-08-26 00:18:47 +00:00
objects: any[];
2016-06-17 11:46:47 +00:00
/**
* The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
*/
2016-08-26 00:18:47 +00:00
orientation: string;
2016-06-17 11:46:47 +00:00
/**
* Map specific properties as specified in Tiled.
*/
2016-08-26 00:18:47 +00:00
properties: any;
rayStepRate: number;
2016-06-17 11:46:47 +00:00
/**
* The base height of the tiles in the map (in pixels).
*/
2016-08-26 00:18:47 +00:00
tileHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The super array of Tiles.
*/
2016-08-26 00:18:47 +00:00
tiles: Phaser.Tile[];
2016-06-17 11:46:47 +00:00
/**
* An array of Tilesets.
*/
2016-08-26 00:18:47 +00:00
tilesets: Phaser.Tileset[];
2016-06-17 11:46:47 +00:00
/**
* The base width of the tiles in the map (in pixels).
*/
2016-08-26 00:18:47 +00:00
tileWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The version of the map data (as specified in Tiled, usually 1).
*/
2016-08-26 00:18:47 +00:00
version: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the map (in tiles).
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* The width of the map in pixels based on width * tileWidth.
*/
2016-08-26 00:18:47 +00:00
widthInPixels: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
addTilesetImage(tileset: string, key?: string | Phaser.BitmapData, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, gid?: number): Phaser.Tileset;
2016-06-17 11:46:47 +00:00
/**
* Internal function.
*
* @param layer The index of the TilemapLayer to operate on.
*/
2016-08-26 00:18:47 +00:00
calculateFaces(layer: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
copy(x: number, y: number, width: number, height: number, layer?: any): Phaser.Tile[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
create(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createBlankLayer(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer;
2016-06-17 11:46:47 +00:00
/**
* Creates a Sprite for every object matching the given gid in the map data. 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.
*
* @param name The name of the Object Group to create Sprites from.
* @param gid The layer array index value, or if a string is given the layer name within the map data.
* @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
*/
2016-08-26 00:18:47 +00:00
createFromObjects(name: string, gid: number, key: string, frame?: any, exists?: boolean, autoCull?: boolean, group?: Phaser.Group, CustomClass?: any, adjustY?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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 `null` to not change.
* @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.
*/
2016-08-26 00:18:47 +00:00
createFromTiles(tiles: any, replacements: any, key: string, layer?: any, group?: Phaser.Group, properties?: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
createLayer(layer: any, width?: number, height?: number, group?: Phaser.Group): Phaser.TilemapLayer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Dumps the tilemap data out to the console.
*/
2016-08-26 00:18:47 +00:00
dump(): void;
2016-06-17 11:46:47 +00:00
/**
* Fills the given area with the specified tile.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
fill(index: number, x: number, y: number, width: number, height: number, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
forEach(callback: Function, context: any, x: number, y: Number, width: number, height: number, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getImageIndex(name: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getIndex(location: any[], name: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getLayer(layer: any): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getLayerIndex(name: string): number;
getObjectIndex(name: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTile(x: number, y: number, layer?: any, nonNull?: boolean): Phaser.Tile;
getRayCastTiles(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, line: Phaser.Line, stepRate?: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
getTiles(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number, y: number, width: number, height: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
getTileX(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number): number;
getTileXY(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, x: number, y: number, point: Phaser.Point): Phaser.Point;
getTileY(layer: Phaser.TilemapLayer|Phaser.TilemapLayerGL, y: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTileAbove(layer: number, x: number, y: number): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTileBelow(layer: number, x: number, y: number): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTileLeft(layer: number, x: number, y: number): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTileRight(layer: number, x: number, y: number): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTilesetIndex(name: string): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
getTileWorldXY(x: number, y: number, tileWidth?: number, tileHeight?: number, layer?: number | string | Phaser.TilemapLayer, nonNull?: boolean): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
hasTile(x: number, y: number, layer: Phaser.TilemapLayer): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
paste(x: number, y: number, tileblock: Phaser.Tile[], layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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 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.
*/
2016-08-26 00:18:47 +00:00
putTile(tile: any, x: number, y: number, layer?: any): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
putTileWorldXY(tile: any, x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* Randomises a set of tiles in a given area.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
random(x: number, y: number, width: number, height: number, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* Removes all layers from this tile map.
*/
2016-08-26 00:18:47 +00:00
removeAllLayers(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeTile(x: number, y: number, layer?: any): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
removeTileWorldXY(x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* Scans the given area for tiles with an index matching `source` and updates their index to match `dest`.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
replace(source: number, dest: number, x: number, y: number, width: number, height: number, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* Searches the entire map layer for the first tile matching the given index, then returns that Phaser.Tile object.
* If no match is found it returns null.
* The search starts from the top-left tile and continues horizontally until it hits the end of the row, then it drops down to the next column.
* If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to the top-left.
*
* @param index The tile index value to search for.
* @param skip The number of times to skip a matching tile before returning.
* @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left.
* @param layer The layer to get the tile from.
* @return The first (or n skipped) tile with the matching index.
*/
2016-08-26 00:18:47 +00:00
searchTileIndex(index: number, skip?: number, reverse?: boolean, layer?: any): Phaser.Tile;
2016-06-17 11:46:47 +00:00
/**
* Sets collision 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).
*
* @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
*/
2016-08-26 00:18:47 +00:00
setCollision(indexes: any, collides?: boolean, layer?: any, recalculate?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setCollisionBetween(start: number, stop: number, collides?: boolean, layer?: any, recalculate?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setCollisionByExclusion(indexes: any[], collides?: boolean, layer?: any, recalculate?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setCollisionByIndex(index: number, collides?: boolean, layer?: number, recalculate?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the current layer to the given index.
*
* @param layer The layer to set as current.
*/
2016-08-26 00:18:47 +00:00
setLayer(layer: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setPreventRecalculate(value: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Sets a global collision callback for the given tile index within the layer. This will affect all tiles on this layer that have the same index.
* If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.
* If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
*
* @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for.
* @param callback The callback that will be invoked when the tile is collided with.
* @param callbackContext The context under which the callback is called.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
*/
2016-08-26 00:18:47 +00:00
setTileIndexCallback(indexes: any, callback: Function, callbackContext: any, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* @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.
* @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.
*/
2016-08-26 00:18:47 +00:00
setTileLocationCallback(x: number, y: number, width: number, height: number, callback: Function, callbackContext: any, layer?: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setTileSize(tileWidth: number, tileHeight: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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!
*
* @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.
*/
2016-08-26 00:18:47 +00:00
shuffle(x: number, y: number, width: number, height: number, layer: any): void;
2016-06-17 11:46:47 +00:00
/**
* Scans the given area for tiles with an index matching tileA and swaps them with tileB.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
swap(tileA: number, tileB: number, x: number, y: number, width: number, height: number, layer?: any): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class TilemapLayer extends Phaser.Sprite {
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* The canvas to which this TilemapLayer draws.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
collisionHeight: number;
collisionWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The 2d context of the canvas.
*/
2016-08-26 00:18:47 +00:00
context: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* Enable an additional "debug rendering" pass to display collision information.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
debugAlpha: number;
debugCallbackColor: string;
debugColor: string;
2016-06-17 11:46:47 +00:00
/**
* Settings used for debugging and diagnostics.
*/
2016-08-26 00:18:47 +00:00
debugSettings: { missingImageFill: string; debuggedTileOverfill: string; forceFullRedraw: boolean; debugAlpha: number; facingEdgeStroke: string; collidingTileOverfill: string; };
2016-06-17 11:46:47 +00:00
/**
* If true tiles will be force rendered, even if such is not believed to be required.
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* Controls if the core game loop and physics update this game object or not.
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The index of this layer within the Tilemap.
*/
2016-08-26 00:18:47 +00:00
index: number;
2016-06-17 11:46:47 +00:00
/**
* The layer object within the Tilemap that this layer represents.
*/
2016-08-26 00:18:47 +00:00
layer: Phaser.TilemapLayer;
2016-06-17 11:46:47 +00:00
/**
* The Tilemap to which this layer is bound.
*/
2016-08-26 00:18:47 +00:00
map: Phaser.Tilemap;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
2016-06-17 11:46:47 +00:00
/**
* Settings that control standard (non-diagnostic) rendering.
* Default: {"enableScrollDelta":false,"overdrawRatio":0.2,"copyCanvas":null}
*/
2016-08-26 00:18:47 +00:00
renderSettings: { enableScrollDelta: boolean; overdrawRatio: number; copyCanvas: any; };
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
scrollFactorX: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
scrollFactorY: number;
scrollX: number;
scrollY: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
* Default: Phaser.TILEMAPLAYER
*/
2016-08-26 00:18:47 +00:00
type: number;
wrap: boolean;
2016-06-17 11:46:47 +00:00
/**
* Destroys this TilemapLayer.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.postUpdate. Handles cache updates.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Renders the tiles to the layer canvas and pushes to the display.
*/
2016-08-26 00:18:47 +00:00
render(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
resize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Sets the world size to match the size of this layer.
*/
2016-08-26 00:18:47 +00:00
resizeWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resetTilesetCache(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
setScale(xScale?: number, yScale?: number): void;
updateMax(): void;
}
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;
}
2016-06-17 11:46:47 +00:00
/**
* Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap.
*/
2016-08-26 00:18:47 +00:00
class TilemapParser {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static INSERT_NULL: boolean;
2016-06-17 11:46:47 +00:00
/**
* Returns an empty map data object.
* @return Generated map data.
*/
2016-08-26 00:18:47 +00:00
static getEmptyData(tileWidth?: number, tileHeight?: number, width?: number, height?: number): any;
2016-06-17 11:46:47 +00:00
/**
2016-08-26 00:18:47 +00:00
* Parse tilemap data from the cache and creates data for a Tilemap object.
2016-06-17 11:46:47 +00:00
*
* @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.
*/
2016-08-26 00:18:47 +00:00
static parse(game: Phaser.Game, key: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static parseCSV(key: string, data: string, tileWidth?: number, tileHeight?: number): any;
2016-06-17 11:46:47 +00:00
/**
* Parses a Tiled JSON file into valid map data.
*
* @param json The JSON map data.
* @return Generated and parsed map data.
*/
2016-08-26 00:18:47 +00:00
static parseJSON(json: any): any;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Tileset {
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: any);
2016-06-17 11:46:47 +00:00
/**
* The number of tile columns in the tileset.
*/
2016-08-26 00:18:47 +00:00
columns: number;
2016-06-17 11:46:47 +00:00
/**
* The Tiled firstgid value.
* This is the starting index of the first tile index this Tileset contains.
*/
2016-08-26 00:18:47 +00:00
firstgid: number;
2016-06-17 11:46:47 +00:00
/**
* The cached image that contains the individual tiles. Use {@link Phaser.Tileset.setImage setImage} to set.
*/
2016-08-26 00:18:47 +00:00
image: any;
lastgid: number;
2016-06-17 11:46:47 +00:00
/**
* The name of the Tileset.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* Tileset-specific properties that are typically defined in the Tiled editor.
*/
2016-08-26 00:18:47 +00:00
properties: any;
2016-06-17 11:46:47 +00:00
/**
* The number of tile rows in the the tileset.
*/
2016-08-26 00:18:47 +00:00
rows: number;
2016-06-17 11:46:47 +00:00
/**
* The height of each tile (in pixels).
*/
2016-08-26 00:18:47 +00:00
tileHeight: number;
2016-06-17 11:46:47 +00:00
/**
* The margin around the tiles in the sheet (in pixels).
* Use `setSpacing` to change.
*/
2016-08-26 00:18:47 +00:00
tileMargin: number;
2016-06-17 11:46:47 +00:00
/**
* The spacing between each tile in the sheet (in pixels).
* Use `setSpacing` to change.
*/
2016-08-26 00:18:47 +00:00
tileSpacing: number;
2016-06-17 11:46:47 +00:00
/**
* The width of each tile (in pixels).
*/
2016-08-26 00:18:47 +00:00
tileWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The total number of tiles in the tileset.
*/
2016-08-26 00:18:47 +00:00
total: number;
2016-06-17 11:46:47 +00:00
/**
* Returns true if and only if this tileset contains the given tile index.
* @return True if this tileset contains the given index.
*/
2016-08-26 00:18:47 +00:00
containsTileIndex(tileIndex: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
draw(context: CanvasRenderingContext2D, x: number, y: number, index: number): void;
drawGl(glBatch: any[], x: number, y: number, index: number, alpha: number, flippedVal: number): void;
2016-06-17 11:46:47 +00:00
/**
* Set the image associated with this Tileset and update the tile data.
*
* @param image The image that contains the tiles.
*/
2016-08-26 00:18:47 +00:00
setImage(image: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
setSpacing(margin?: number, spacing?: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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
2016-08-26 00:18:47 +00:00
* 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
2016-06-17 11:46:47 +00:00
* 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.
*/
2016-08-26 00:18:47 +00:00
class TileSprite extends PIXI.TilingSprite {
2016-06-17 11:46:47 +00:00
/**
* 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
2016-08-26 00:18:47 +00:00
* 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
2016-06-17 11:46:47 +00:00
* 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.
* @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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, x: number, y: number, width: number, height: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number);
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
alive: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
angle: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
animations: Phaser.AnimationManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoCull: boolean;
2016-06-17 11:46:47 +00:00
/**
* `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.
*/
2016-08-26 00:18:47 +00:00
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
2016-06-17 11:46:47 +00:00
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
2016-08-26 00:18:47 +00:00
bottom: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
cameraOffset: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
checkWorldBounds: boolean;
2016-06-17 11:46:47 +00:00
/**
* The components this Game Object has installed.
*/
2016-08-26 00:18:47 +00:00
components: any;
2016-06-17 11:46:47 +00:00
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
2016-08-26 00:18:47 +00:00
customRender: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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: {}
*/
2016-08-26 00:18:47 +00:00
data: any;
2016-06-17 11:46:47 +00:00
/**
* A debug flag designed for use with `Game.enableStep`.
*/
2016-08-26 00:18:47 +00:00
debug: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
destroyPhase: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Events;
2016-06-17 11:46:47 +00:00
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops.
* Default: true
*/
2016-08-26 00:18:47 +00:00
exists: boolean;
2016-06-17 11:46:47 +00:00
/**
* A Game Object that is "fixed" to the camera uses its x/y coordinates as offsets from the top left of the camera during rendering.
*
* 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.
*
* The offsets are stored in the `cameraOffset` property.
*
* 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.
*/
2016-08-26 00:18:47 +00:00
fixedToCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frame: string | number;
2016-06-17 11:46:47 +00:00
/**
* 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`.
*/
2016-08-26 00:18:47 +00:00
frameName: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fresh: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
inCamera: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
input: Phaser.InputHandler;
2016-06-17 11:46:47 +00:00
/**
* 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.
2016-07-01 15:57:13 +00:00
*
* 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.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
inputEnabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
2016-08-26 00:18:47 +00:00
inWorld: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
2016-06-17 11:46:47 +00:00
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
2016-08-26 00:18:47 +00:00
left: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
name: string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetX: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
offsetY: number;
2016-06-17 11:46:47 +00:00
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
2016-08-26 00:18:47 +00:00
outOfBoundsKill: boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
pendingDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The const physics body type of this object.
*/
2016-08-26 00:18:47 +00:00
physicsType: number;
position: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
smoothed: boolean;
2016-06-17 11:46:47 +00:00
/**
* The position the Game Object was located in the previous frame.
*/
2016-08-26 00:18:47 +00:00
previousPosition: Phaser.Point;
previousRoation: number;
2016-06-17 11:46:47 +00:00
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
2016-08-26 00:18:47 +00:00
right: number;
2016-06-17 11:46:47 +00:00
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
2016-08-26 00:18:47 +00:00
top: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
renderOrderID: number;
2016-06-17 11:46:47 +00:00
/**
* The const type of this object.
*/
2016-08-26 00:18:47 +00:00
type: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
world: Phaser.Point;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
z: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
autoScroll(x: number, y: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
destroy(destroyChildren?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
2016-06-17 11:46:47 +00:00
/**
* Internal method called by the World postUpdate cycle.
*/
2016-08-26 00:18:47 +00:00
postUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* Automatically called by World.preUpdate.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reset(x: number, y: number, health?: number): Phaser.TileSprite;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
resizeFrame(parent: any, width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
2016-08-26 00:18:47 +00:00
resetFrame(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
setFrame(frame: Phaser.Frame): void;
2016-06-17 11:46:47 +00:00
/**
* Stops an automatically scrolling TileSprite.
*/
2016-08-26 00:18:47 +00:00
stopScroll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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:
*
* - ***Game time*** always runs at the speed of time in real life.
*
* Unlike wall-clock time, *game time stops when Phaser is paused*.
*
* Game time is used for {@link Phaser.Timer timer events}.
*
* - ***Physics time*** represents the amount of time given to physics calculations.
*
* *When {@link Phaser.Time#slowMotion slowMotion} is in effect physics time runs slower than game time.*
* Like game time, physics time stops when Phaser is paused.
*
* Physics time is used for physics calculations and {@link Phaser.Tween tweens}.
*
* - {@link https://en.wikipedia.org/wiki/Wall-clock_time ***Wall-clock time***} represents the duration between two events in real life time.
*
* This time is independent of Phaser and always progresses, regardless of if Phaser is paused.
*/
2016-08-26 00:18:47 +00:00
class Time {
2016-06-17 11:46:47 +00:00
/**
* 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:
*
* - ***Game time*** always runs at the speed of time in real life.
*
* Unlike wall-clock time, *game time stops when Phaser is paused*.
*
* Game time is used for {@link Phaser.Timer timer events}.
*
* - ***Physics time*** represents the amount of time given to physics calculations.
*
* *When {@link Phaser.Time#slowMotion slowMotion} is in effect physics time runs slower than game time.*
* Like game time, physics time stops when Phaser is paused.
*
* Physics time is used for physics calculations and {@link Phaser.Tween tweens}.
*
* - {@link https://en.wikipedia.org/wiki/Wall-clock_time ***Wall-clock time***} represents the duration between two events in real life time.
*
* This time is independent of Phaser and always progresses, regardless of if Phaser is paused.
*
* @param game A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* If true then advanced profiling, including the fps rate, fps min/max, suggestedFps and msMin/msMax are updated.
*/
2016-08-26 00:18:47 +00:00
advancedTiming: boolean;
2016-06-17 11:46:47 +00:00
/**
* The desired frame rate of the game.
*
* This is used is used to calculate the physic / logic multiplier and how to apply catch-up logic updates. The desired frame rate of the game. Defaults to 60.
*/
2016-08-26 00:18:47 +00:00
desiredFps: number;
2016-06-17 11:46:47 +00:00
/**
* The desiredFps multiplier as used by Game.update.
*/
2016-08-26 00:18:47 +00:00
desiredFpsMult: number;
2016-06-17 11:46:47 +00:00
/**
* Elapsed time since the last time update, in milliseconds, based on `now`.
*
* This value _may_ include time that the game is paused/inactive.
*
* _Note:_ This is updated only once per game loop - even if multiple logic update steps are done.
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
*/
2016-08-26 00:18:47 +00:00
elapsed: number;
2016-06-17 11:46:47 +00:00
/**
* A {@link Phaser.Timer} object bound to the master clock (this Time object) which events can be added to.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.Timer;
2016-06-17 11:46:47 +00:00
/**
* 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.
*
* _Note:_ This is updated once per game loop - even if multiple logic update steps are done.
* Use {@link Phaser.Timer#physicsTime physicsTime} as a basis of game/logic calculations instead.
*/
2016-08-26 00:18:47 +00:00
elapsedMS: number;
2016-06-17 11:46:47 +00:00
/**
* Advanced timing result: Frames per second.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
*/
2016-08-26 00:18:47 +00:00
fps: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fpsMax: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
fpsMin: number;
2016-06-17 11:46:47 +00:00
/**
* Advanced timing result: The number of render frames record in the last second.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
*/
2016-08-26 00:18:47 +00:00
frames: number;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
lastTime: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
msMax: number;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
msMin: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
now: number;
pausedTime: number;
2016-06-17 11:46:47 +00:00
/**
* Records how long the game was last paused, in milliseconds.
* (This is not updated until the game is resumed.)
*/
2016-08-26 00:18:47 +00:00
pauseDuration: number;
2016-06-17 11:46:47 +00:00
/**
* The physics update delta, in fractional seconds.
*
* This should be used as an applicable multiplier by all logic update steps (eg. `preUpdate/postUpdate/update`)
* to ensure consistent game timing. Game/logic timing can drift from real-world time if the system
* is unable to consistently maintain the desired FPS.
*
* With fixed-step updates this is normally equivalent to `1.0 / desiredFps`.
*/
2016-08-26 00:18:47 +00:00
physicsElapsed: number;
2016-06-17 11:46:47 +00:00
/**
* The physics update delta, in milliseconds - equivalent to `physicsElapsed * 1000`.
*/
2016-08-26 00:18:47 +00:00
physicsElapsedMS: number;
2016-06-17 11:46:47 +00:00
/**
* The `now` when the previous update occurred.
*/
2016-08-26 00:18:47 +00:00
prevTime: number;
2016-06-17 11:46:47 +00:00
/**
* Scaling factor to make the game move smoothly in slow motion
* - 1.0 = normal speed
* - 2.0 = half speed
* Default: 1
*/
2016-08-26 00:18:47 +00:00
slowMotion: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
suggestedFps: number;
2016-06-17 11:46:47 +00:00
/**
* The `Date.now()` value when the time was last updated.
*/
2016-08-26 00:18:47 +00:00
time: number;
2016-06-17 11:46:47 +00:00
/**
* The time when the next call is expected when using setTimer to control the update loop
*/
2016-08-26 00:18:47 +00:00
timeExpected: number;
2016-06-17 11:46:47 +00:00
/**
* The value that setTimeout needs to work out when to next update
*/
2016-08-26 00:18:47 +00:00
timeToCall: number;
2016-06-17 11:46:47 +00:00
/**
* Adds an existing Phaser.Timer object to the Timer pool.
*
* @param timer An existing Phaser.Timer object.
* @return The given Phaser.Timer object.
*/
2016-08-26 00:18:47 +00:00
add(timer: Phaser.Timer): Phaser.Timer;
2016-06-17 11:46:47 +00:00
/**
* Called automatically by Phaser.Game after boot. Should not be called directly.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
create(autoDestroy?: boolean): Phaser.Timer;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
elapsedSecondsSince(since: number): number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
elapsedSince(since: number): number;
2016-06-17 11:46:47 +00:00
/**
* Remove all Timer objects, regardless of their state and clears all Timers from the {@link Phaser.Time#events events} timer.
*/
2016-08-26 00:18:47 +00:00
removeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* Resets the private _started value to now and removes all currently running Timers.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
totalElapsedSeconds(): number;
2016-06-17 11:46:47 +00:00
/**
* Updates the game clock and if enabled the advanced timing data. This is called automatically by Phaser.Game.
*
* @param time The current relative timestamp; see {@link Phaser.Time#now now}.
*/
2016-08-26 00:18:47 +00:00
update(time: number): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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 real life time, adjusted for game pause durations.
* That is, *timer events are based on elapsed {@link Phaser.Time game time}* and do *not* take physics time or slow motion into account.
*/
2016-08-26 00:18:47 +00:00
class Timer {
2016-06-17 11:46:47 +00:00
/**
* 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 real life time, adjusted for game pause durations.
* That is, *timer events are based on elapsed {@link Phaser.Time game time}* and do *not* take physics time or slow motion into account.
*
* @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
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game, autoDestroy?: boolean);
2016-06-17 11:46:47 +00:00
/**
* Number of milliseconds in half a second.
*/
2016-08-26 00:18:47 +00:00
static HALF: number;
2016-06-17 11:46:47 +00:00
/**
* Number of milliseconds in a minute.
*/
2016-08-26 00:18:47 +00:00
static MINUTE: number;
2016-06-17 11:46:47 +00:00
/**
* Number of milliseconds in a quarter of a second.
*/
2016-08-26 00:18:47 +00:00
static QUARTER: number;
2016-06-17 11:46:47 +00:00
/**
* Number of milliseconds in a second.
*/
2016-08-26 00:18:47 +00:00
static SECOND: number;
2016-06-17 11:46:47 +00:00
/**
* If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events).
*/
2016-08-26 00:18:47 +00:00
autoDestroy: boolean;
2016-06-17 11:46:47 +00:00
/**
* The duration in ms remaining until the next event will occur.
*/
2016-08-26 00:18:47 +00:00
duration: number;
2016-06-17 11:46:47 +00:00
/**
* An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it.
*/
2016-08-26 00:18:47 +00:00
events: Phaser.TimerEvent[];
2016-06-17 11:46:47 +00:00
/**
* An expired Timer is one in which all of its events have been dispatched and none are pending.
*/
2016-08-26 00:18:47 +00:00
expired: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The number of pending events in the queue.
*/
2016-08-26 00:18:47 +00:00
length: number;
2016-06-17 11:46:47 +00:00
/**
* The duration in milliseconds that this Timer has been running for.
*/
2016-08-26 00:18:47 +00:00
ms: number;
2016-06-17 11:46:47 +00:00
/**
* The time at which the next event will occur.
*/
2016-08-26 00:18:47 +00:00
next: number;
2016-06-17 11:46:47 +00:00
/**
* The time the next tick will occur.
*/
2016-08-26 00:18:47 +00:00
nextTick: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
running: boolean;
2016-06-17 11:46:47 +00:00
/**
* The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing.
*/
2016-08-26 00:18:47 +00:00
paused: boolean;
2016-06-17 11:46:47 +00:00
/**
* The duration in seconds that this Timer has been running for.
*/
2016-08-26 00:18:47 +00:00
seconds: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
2016-06-17 11:46:47 +00:00
/**
* Clears any events from the Timer which have pendingDelete set to true and then resets the private _len and _i values.
*/
2016-08-26 00:18:47 +00:00
clearPendingEvents(): void;
2016-06-17 11:46:47 +00:00
/**
* Destroys this Timer. Any pending Events are not dispatched.
* The onComplete callbacks won't be called.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
loop(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
2016-06-17 11:46:47 +00:00
/**
* Orders the events on this Timer so they are in tick order.
* This is called automatically when new events are created.
*/
2016-08-26 00:18:47 +00:00
order(): void;
2016-06-17 11:46:47 +00:00
/**
* Pauses the Timer and all events in the queue.
*/
2016-08-26 00:18:47 +00:00
pause(): void;
2016-06-17 11:46:47 +00:00
/**
* Removes a pending TimerEvent from the queue.
*
* @param event The event to remove from the queue.
*/
2016-08-26 00:18:47 +00:00
remove(event: Phaser.TimerEvent): boolean;
2016-06-17 11:46:47 +00:00
/**
* Removes all Events from this Timer and all callbacks linked to onComplete, but leaves the Timer running.
* The onComplete callbacks won't be called.
*/
2016-08-26 00:18:47 +00:00
removeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
repeat(delay: number, repeatCount: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
2016-06-17 11:46:47 +00:00
/**
* Resumes the Timer and updates all pending events.
*/
2016-08-26 00:18:47 +00:00
resume(): void;
2016-06-17 11:46:47 +00:00
/**
* Sort handler used by Phaser.Timer.order.
*/
2016-08-26 00:18:47 +00:00
sortHandler(a: any, b: any): number;
2016-06-17 11:46:47 +00:00
/**
* Starts this Timer running.
*
* @param delay The number of milliseconds, in {@link Phaser.Time game time}, that should elapse before the Timer will start.
*/
2016-08-26 00:18:47 +00:00
start(startDelay?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
stop(clearEvents?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(time: number): boolean;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class TimerEvent {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(timer: Phaser.Timer, delay: number, tick: number, repeatCount: number, loop: boolean, callback: Function, callbackContext: any, ...args: any[]);
2016-06-17 11:46:47 +00:00
/**
* Additional arguments to be passed to the callback.
*/
2016-08-26 00:18:47 +00:00
args: any[];
2016-06-17 11:46:47 +00:00
/**
* The callback that will be called when the TimerEvent occurs.
*/
2016-08-26 00:18:47 +00:00
callback: Function;
2016-06-17 11:46:47 +00:00
/**
* The context in which the callback will be called.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* The delay in ms at which this TimerEvent fires.
*/
2016-08-26 00:18:47 +00:00
delay: number;
2016-06-17 11:46:47 +00:00
/**
* True if this TimerEvent loops, otherwise false.
*/
2016-08-26 00:18:47 +00:00
loop: boolean;
2016-06-17 11:46:47 +00:00
/**
* A flag that controls if the TimerEvent is pending deletion.
*/
2016-08-26 00:18:47 +00:00
pendingDelete: boolean;
2016-06-17 11:46:47 +00:00
/**
* If this TimerEvent repeats it will do so this many times.
*/
2016-08-26 00:18:47 +00:00
repeatCount: number;
2016-06-17 11:46:47 +00:00
/**
* The tick is the next game clock time that this event will fire at.
*/
2016-08-26 00:18:47 +00:00
tick: number;
2016-06-17 11:46:47 +00:00
/**
* The Timer object that this TimerEvent belongs to.
*/
2016-08-26 00:18:47 +00:00
timer: Phaser.Timer;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Touch {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* The context under which callbacks are called.
*/
2016-08-26 00:18:47 +00:00
callbackContext: any;
2016-06-17 11:46:47 +00:00
/**
* Touch events will only be processed if enabled.
* Default: true
*/
2016-08-26 00:18:47 +00:00
enabled: boolean;
2016-06-17 11:46:47 +00:00
/**
* The browser touch DOM event. Will be set to null if no touch event has ever been received.
*/
2016-08-26 00:18:47 +00:00
event: any;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* If true the TouchEvent will have prevent.default called on it.
* Default: true
*/
2016-08-26 00:18:47 +00:00
preventDefault: boolean;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchCancel event.
*/
2016-08-26 00:18:47 +00:00
touchCancelCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchEnd event.
*/
2016-08-26 00:18:47 +00:00
touchEndCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchEnter event.
*/
2016-08-26 00:18:47 +00:00
touchEnterCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchLeave event.
*/
2016-08-26 00:18:47 +00:00
touchLeaveCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchMove event.
*/
2016-08-26 00:18:47 +00:00
touchMoveCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* A callback that can be fired on a touchStart event.
*/
2016-08-26 00:18:47 +00:00
touchStartCallback: Function;
2016-06-17 11:46:47 +00:00
/**
* An array of callbacks that will be fired every time a native touch start or touch end event is received from the browser.
* This is used internally to handle audio and video unlocking on mobile devices.
* To add a callback to this array please use `Touch.addTouchLockCallback`.
*/
2016-08-26 00:18:47 +00:00
touchLockCallbacks: Function[];
2016-06-17 11:46:47 +00:00
/**
* Adds a callback that is fired when a browser touchstart or touchend event is received.
*
* This is used internally to handle audio and video unlocking on mobile devices.
*
* If the callback returns 'true' then the callback is automatically deleted once invoked.
*
* The callback is added to the Phaser.Touch.touchLockCallbacks array and should be removed with Phaser.Touch.removeTouchLockCallback.
*
* @param callback The callback that will be called when a touchstart event is received.
* @param context The context in which the callback will be called.
* @param onEnd Will the callback fire on a touchstart (default) or touchend event?
*/
2016-08-26 00:18:47 +00:00
addTouchLockCallback(callback: Function, context?: any, onEnd?: Function): void;
2016-06-17 11:46:47 +00:00
/**
* Removes the callback at the defined index from the Phaser.Touch.touchLockCallbacks array
*
* @param callback The callback to be removed.
* @param context The context in which the callback exists.
* @return True if the callback was deleted, otherwise false.
*/
2016-08-26 00:18:47 +00:00
removeTouchLockCallback(callback: Function, context?: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* Consumes all touchmove events on the document (only enable this if you know you need it!).
*/
2016-08-26 00:18:47 +00:00
consumeTouchMove(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onTouchCancel(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* The handler for the touchend events.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
2016-08-26 00:18:47 +00:00
onTouchEnd(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onTouchEnter(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onTouchLeave(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* The handler for the touchmove events.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
2016-08-26 00:18:47 +00:00
onTouchMove(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onTouchStart(event: any): void;
2016-06-17 11:46:47 +00:00
/**
* Starts the event listeners running.
*/
2016-08-26 00:18:47 +00:00
start(): void;
2016-06-17 11:46:47 +00:00
/**
* Stop the event listeners.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class Tween {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(target: any, game: Phaser.Game, manager: Phaser.TweenManager);
2016-06-17 11:46:47 +00:00
/**
* If this Tween is chained to another this holds a reference to it.
*/
2016-08-26 00:18:47 +00:00
chainedTween: Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* The current Tween child being run.
*/
2016-08-26 00:18:47 +00:00
current: number;
2016-06-17 11:46:47 +00:00
/**
* Is this Tween frame or time based? A frame based tween will use the physics elapsed timer when updating. This means
* it will retain the same consistent frame rate, regardless of the speed of the device. The duration value given should
* be given in frames.
*
* If the Tween uses a time based update (which is the default) then the duration is given in milliseconds.
* In this situation a 2000ms tween will last exactly 2 seconds, regardless of the device and how many visual updates the tween
* has actually been through. For very short tweens you may wish to experiment with a frame based update instead.
*
* The default value is whatever you've set in TweenManager.frameBased.
*/
2016-08-26 00:18:47 +00:00
frameBased: boolean;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isRunning: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is this Tween paused or not?
*/
2016-08-26 00:18:47 +00:00
isPaused: boolean;
2016-06-17 11:46:47 +00:00
/**
* Reference to the TweenManager responsible for updating this Tween.
*/
2016-08-26 00:18:47 +00:00
manager: Phaser.TweenManager;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onChildComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onComplete: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onLoop: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onRepeat: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
onStart: Phaser.Signal;
2016-06-17 11:46:47 +00:00
/**
* True if this Tween is ready to be deleted by the TweenManager.
*/
2016-08-26 00:18:47 +00:00
pendingDelete: boolean;
2016-06-17 11:46:47 +00:00
/**
* Target property cache used when building the child data values.
*/
2016-08-26 00:18:47 +00:00
properties: any;
2016-06-17 11:46:47 +00:00
/**
* If the Tween and any child tweens are set to repeat this contains the current repeat count.
*/
2016-08-26 00:18:47 +00:00
repeatCounter: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
reverse: boolean;
2016-06-17 11:46:47 +00:00
/**
* The target object, such as a Phaser.Sprite or property like Phaser.Sprite.scale.
*/
2016-08-26 00:18:47 +00:00
target: any;
2016-06-17 11:46:47 +00:00
/**
* An Array of TweenData objects that comprise the different parts of this Tween.
*/
2016-08-26 00:18:47 +00:00
timeline: Phaser.TweenData[];
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
timeScale: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the total duration of this Tween, including all child tweens, in milliseconds.
*/
2016-08-26 00:18:47 +00:00
totalDuration: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
chain(...args: any[]): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
delay(duration: number, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
easing(ease: Function, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
easing(ease: string, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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. Or if `Tween.frameBased` is true this represents the number of frames that should elapse. - 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.
*/
2016-08-26 00:18:47 +00:00
from(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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. Or if `Tween.frameBased` is true this represents the number of frames that should elapse. - 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.
*/
2016-08-26 00:18:47 +00:00
from(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
generateData(frameRate?: number, data?: any): any[];
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
interpolation(interpolation: Function, context?: any, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
loop(value?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Sets a callback to be fired each time this tween updates.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
onUpdateCallback(callback: Function, callbackContext?: any): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Pauses the tween. Resume playback with Tween.resume.
*/
2016-08-26 00:18:47 +00:00
pause(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
repeat(total: number, repeatDelay?: number, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
repeatDelay(duration: number, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
repeatAll(total?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Resumes a paused tween.
*/
2016-08-26 00:18:47 +00:00
resume(): void;
2016-06-17 11:46:47 +00:00
/**
* Starts the tween running. Can also be called by the autoStart parameter of `Tween.to` or `Tween.from`.
* This sets the `Tween.isRunning` property to `true` and dispatches a `Tween.onStart` signal.
* If the Tween has a delay set then nothing will start tweening until the delay has expired.
*
* @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.
*/
2016-08-26 00:18:47 +00:00
start(index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Stops the tween if running and flags it for deletion from the TweenManager.
* If called directly the `Tween.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 Tween.pause instead.
*
* @param complete Set to `true` to dispatch the Tween.onComplete signal.
* @return This tween. Useful for method chaining.
*/
2016-08-26 00:18:47 +00:00
stop(complete?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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. Or if `Tween.frameBased` is true this represents the number of frames that should elapse. - 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.
*/
2016-08-26 00:18:47 +00:00
to(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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. Or if `Tween.frameBased` is true this represents the number of frames that should elapse. - 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.
*/
2016-08-26 00:18:47 +00:00
to(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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).
*/
2016-08-26 00:18:47 +00:00
update(time: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
updateTweenData(property: string, value: number | Function, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
yoyo(enable: boolean, yoyoDelay?: number, index?: number): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
yoyoDelay(duration: number, index?: number): Phaser.Tween;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class TweenData {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(parent: Phaser.Tween);
static COMPLETE: number;
static LOOPED: number;
static PENDING: number;
static RUNNING: number;
2016-06-17 11:46:47 +00:00
/**
* The amount to delay by until the Tween starts (in ms). Only applies to the start, use repeatDelay to handle repeats.
*/
2016-08-26 00:18:47 +00:00
delay: number;
2016-06-17 11:46:47 +00:00
/**
* Current time value.
*/
2016-08-26 00:18:47 +00:00
dt: number;
2016-06-17 11:46:47 +00:00
/**
* The duration of the tween in ms.
* Default: 1000
*/
2016-08-26 00:18:47 +00:00
duration: number;
2016-06-17 11:46:47 +00:00
/**
* The easing function used for the Tween.
* Default: Phaser.Easing.Default
*/
2016-08-26 00:18:47 +00:00
easingFunction: Function;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* When a Tween is yoyoing this value holds if it's currently playing forwards (false) or in reverse (true).
*/
2016-08-26 00:18:47 +00:00
inReverse: boolean;
2016-06-17 11:46:47 +00:00
/**
* True if the Tween will use interpolation (i.e. is an Array to Array tween)
*/
2016-08-26 00:18:47 +00:00
interpolate: boolean;
interpolateFunctionContext: Phaser.Math;
2016-06-17 11:46:47 +00:00
/**
* The interpolation function context used for the Tween.
* Default: Phaser.Math
*/
2016-08-26 00:18:47 +00:00
interpolationContext: Phaser.Math;
2016-06-17 11:46:47 +00:00
/**
* The interpolation function used for the Tween.
* Default: Phaser.Math.linearInterpolation
*/
2016-08-26 00:18:47 +00:00
interpolationFunction: Function;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
isRunning: boolean;
2016-06-17 11:46:47 +00:00
/**
* Is this a from tween or a to tween?
*/
2016-08-26 00:18:47 +00:00
isFrom: boolean;
2016-06-17 11:46:47 +00:00
/**
* The Tween which owns this TweenData.
*/
2016-08-26 00:18:47 +00:00
parent: Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* A value between 0 and 1 that represents how far through the duration this tween is.
*/
2016-08-26 00:18:47 +00:00
percent: number;
2016-06-17 11:46:47 +00:00
/**
* If the Tween is set to repeat this contains the current repeat count.
*/
2016-08-26 00:18:47 +00:00
repeatCounter: number;
2016-06-17 11:46:47 +00:00
/**
* The time the Tween started or null if it hasn't yet started.
*/
2016-08-26 00:18:47 +00:00
startTime: number;
2016-06-17 11:46:47 +00:00
/**
* The current calculated value.
*/
2016-08-26 00:18:47 +00:00
value: number;
2016-06-17 11:46:47 +00:00
/**
* True if the Tween is set to yoyo, otherwise false.
*/
2016-08-26 00:18:47 +00:00
yoyo: boolean;
2016-06-17 11:46:47 +00:00
/**
* The amount of time in ms between yoyos of this tween.
*/
2016-08-26 00:18:47 +00:00
yoyoDelay: number;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
from(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
generateData(frameRate?: number): any[];
2016-06-17 11:46:47 +00:00
/**
* Checks if this Tween is meant to repeat or yoyo and handles doing so.
* @return Either Phaser.TweenData.LOOPED or Phaser.TweenData.COMPLETE.
*/
2016-08-26 00:18:47 +00:00
repeat(): number;
2016-06-17 11:46:47 +00:00
/**
* Starts the Tween running.
* @return This Tween object.
*/
2016-08-26 00:18:47 +00:00
start(): Phaser.TweenData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
to(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
update(time: number): number;
}
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
class TweenManager {
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* Are all newly created Tweens frame or time based? A frame based tween will use the physics elapsed timer when updating. This means
* it will retain the same consistent frame rate, regardless of the speed of the device. The duration value given should
* be given in frames.
*
* If the Tween uses a time based update (which is the default) then the duration is given in milliseconds.
* In this situation a 2000ms tween will last exactly 2 seconds, regardless of the device and how many visual updates the tween
* has actually been through. For very short tweens you may wish to experiment with a frame based update instead.
*/
2016-08-26 00:18:47 +00:00
frameBased: boolean;
2016-06-17 11:46:47 +00:00
/**
* Local reference to game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
add(tween: Phaser.Tween): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
create(object: any): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Get all the tween objects in an array.
* @return Array with all tween objects.
*/
2016-08-26 00:18:47 +00:00
getAll(): Phaser.Tween[];
2016-06-17 11:46:47 +00:00
/**
* Checks to see if a particular Sprite is currently being tweened.
*
* @param object The object to check for tweens against.
* @return Returns true if the object is currently being tweened, false if not.
*/
2016-08-26 00:18:47 +00:00
isTweening(object: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* Remove a tween from this manager.
*
* @param tween The tween object you want to remove.
*/
2016-08-26 00:18:47 +00:00
remove(tween: Phaser.Tween): Phaser.Tween;
2016-06-17 11:46:47 +00:00
/**
* Remove all tweens running and in the queue. Doesn't call any of the tween onComplete events.
*/
2016-08-26 00:18:47 +00:00
removeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
removeFrom(obj: any, children?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Resumes all currently paused tweens.
*/
2016-08-26 00:18:47 +00:00
resumeAll(): void;
2016-06-17 11:46:47 +00:00
/**
* Update all the tween objects you added to this manager.
* @return Return false if there's no tween to update, otherwise return true.
*/
2016-08-26 00:18:47 +00:00
update(): boolean;
2016-06-17 11:46:47 +00:00
/**
* Pauses all currently running tweens.
*/
2016-08-26 00:18:47 +00:00
pauseAll(): void;
}
class Utils {
2016-06-17 11:46:47 +00:00
/**
* Gets an objects property by string.
*
* @param obj The object to traverse.
* @param prop The property whose value will be returned.
* @return the value of the property or null if property isn't found .
*/
2016-08-26 00:18:47 +00:00
static getProperty(obj: any, prop: string): any;
2016-06-17 11:46:47 +00:00
/**
* Sets an objects property by string.
*
* @param obj The object to traverse
* @param prop The property whose value will be changed
* @return The object on which the property was set.
*/
2016-08-26 00:18:47 +00:00
static setProperty(obj: any, prop: string, value: any): any;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static chanceRoll(chance: number): boolean;
2016-06-17 11:46:47 +00:00
/**
* Choose between one of two values randomly.
*
* @param choice1
* @param choice2
* @return The randomly selected choice
*/
2016-08-26 00:18:47 +00:00
static randomChoice(choice1: string | number, choice2: any): any;
2016-07-01 15:57:13 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static reverseString(string: string): string;
2016-06-17 11:46:47 +00:00
/**
* Get a unit dimension from a string.
*
* @param size The size to parse.
* @param dimension The window dimension to check.
* @return The parsed dimension.
*/
2016-08-26 00:18:47 +00:00
static parseDimension(size: any, dimension: number): number;
2016-06-17 11:46:47 +00:00
/**
2016-07-01 15:57:13 +00:00
* 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**`
2016-06-17 11:46:47 +00:00
*
2016-07-01 15:57:13 +00:00
* @param str The target string. `toString()` will be called on the string, which means you can also pass in common data types like numbers.
2016-06-17 11:46:47 +00:00
* @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
2016-07-01 15:57:13 +00:00
* @return The padded string.
2016-06-17 11:46:47 +00:00
*/
2016-08-26 00:18:47 +00:00
static pad(str: string, len?: number, pad?: string, dir?: number): string;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static isPlainObject(object: any): boolean;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static extend(deep: boolean, target: any, ...args: any[]): any;
2016-06-17 11:46:47 +00:00
/**
* 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?
*/
2016-08-26 00:18:47 +00:00
static mixinPrototype(target: any, mixin: any, replace?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
static mixin<T>(from: T, to: any): T;
}
module Utils {
2016-06-17 11:46:47 +00:00
/**
* A collection of methods for displaying debug information about game objects.
2016-07-01 15:57:13 +00:00
*
* If your game is running in Canvas mode, then you should invoke all of the Debug methods from
* your games `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.
*
2016-06-17 11:46:47 +00:00
* 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!
*/
2016-08-26 00:18:47 +00:00
class Debug {
2016-06-17 11:46:47 +00:00
/**
* A collection of methods for displaying debug information about game objects.
2016-07-01 15:57:13 +00:00
*
* If your game is running in Canvas mode, then you should invoke all of the Debug methods from
* your games `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.
*
2016-06-17 11:46:47 +00:00
* 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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* In WebGL mode this BitmapData contains a copy of the debug canvas.
*/
2016-08-26 00:18:47 +00:00
bmd: Phaser.BitmapData;
2016-06-17 11:46:47 +00:00
/**
* The canvas to which Debug calls draws.
*/
2016-08-26 00:18:47 +00:00
canvas: HTMLCanvasElement;
2016-06-17 11:46:47 +00:00
/**
* The spacing between columns.
*/
2016-08-26 00:18:47 +00:00
columnWidth: number;
2016-06-17 11:46:47 +00:00
/**
* The 2d context of the canvas.
*/
2016-08-26 00:18:47 +00:00
context: CanvasRenderingContext2D;
2016-06-17 11:46:47 +00:00
/**
* The alpha of the Debug context, set before all debug information is rendered to it.
* Default: 1
*/
2016-08-26 00:18:47 +00:00
currentAlpha: number;
2016-06-17 11:46:47 +00:00
/**
* The current X position the debug information will be rendered at.
*/
2016-08-26 00:18:47 +00:00
currentX: number;
2016-06-17 11:46:47 +00:00
/**
* The current Y position the debug information will be rendered at.
*/
2016-08-26 00:18:47 +00:00
currentY: number;
2016-06-17 11:46:47 +00:00
/**
* Does the canvas need re-rendering?
*/
2016-08-26 00:18:47 +00:00
dirty: boolean;
2016-06-17 11:46:47 +00:00
/**
* The font that the debug information is rendered in.
* Default: '14px Courier'
*/
2016-08-26 00:18:47 +00:00
font: string;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* The line height between the debug text.
*/
2016-08-26 00:18:47 +00:00
lineHeight: number;
2016-06-17 11:46:47 +00:00
/**
* Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
*/
2016-08-26 00:18:47 +00:00
renderShadow: boolean;
2016-06-17 11:46:47 +00:00
/**
* If debugging in WebGL mode we need this.
*/
2016-08-26 00:18:47 +00:00
sprite: Phaser.Image;
AStar(astar: Phaser.Plugin.AStar, x: number, y: number, showVisited: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method that boots the debug displayer.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
body(sprite: Phaser.Sprite, color?: string, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
bodyInfo(sprite: Phaser.Sprite, x: number, y: Number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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 sprite The sprite whos body will be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(0,255,0)'
*/
2016-08-26 00:18:47 +00:00
box2dBody(body: Phaser.Sprite, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
box2dWorld(): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
cameraInfo(camera: Phaser.Camera, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* Destroy this object.
*/
2016-08-26 00:18:47 +00:00
destroy(): void;
2016-06-17 11:46:47 +00:00
/**
* Renders a Phaser geometry object including Rectangle, Circle, 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. If 0 no type will be forced, otherwise 1 = Rectangle, 2 = Circle, 3 = Point and 4 = Line.
*/
2016-08-26 00:18:47 +00:00
geom(object: any, color?: string, fiiled?: boolean, forceType?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
inputInfo(x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
lineInfo(line: Phaser.Line, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
key(key: Phaser.Key, x?: number, y?: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method that outputs a single line of text split over as many columns as needed, one per parameter.
*/
2016-08-26 00:18:47 +00:00
line(...args: string[]): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method that clears the canvas (if a Sprite) ready for a new debug session.
*/
2016-08-26 00:18:47 +00:00
preUpdate(): void;
2016-06-17 11:46:47 +00:00
/**
* 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 'size' to render the pixel at. - Default: 2
*/
2016-08-26 00:18:47 +00:00
pixel(x: number, y: number, color?: string, size?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Renders the Pointer.circle object onto the stage in green if down or red 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 down. - Default: 'rgba(0,255,0,0.5)'
* @param upColor The color the circle is rendered in if up (and hideIfUp is false). - Default: 'rgba(255,0,0,0.5)'
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
2016-08-26 00:18:47 +00:00
pointer(pointer: Phaser.Pointer, hideIfUp?: boolean, downColor?: string, upColor?: string, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* Visually renders a QuadTree to the display.
*
* @param quadtree The quadtree to render.
* @param color The color of the lines in the quadtree.
*/
2016-08-26 00:18:47 +00:00
quadTree(quadtree: Phaser.QuadTree, color?: string): void;
rectangle(object: Phaser.Rectangle, color?: string, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* Clears the Debug canvas.
*/
2016-08-26 00:18:47 +00:00
reset(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
ropeSegments(rope: Phaser.Rope, color?: number, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
soundInfo(sound: Phaser.Sound, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
spriteBounds(sprite: any, color?: string, filled?: boolean): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
spriteCoords(sprite: any, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
spriteInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
spriteInputInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
start(x?: number, y?: number, color?: string, columnWidth?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Internal method that stops the debug output.
*/
2016-08-26 00:18:47 +00:00
stop(): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
text(text: string, x: number, y: number, color?: string, font?: string): void;
2016-06-17 11:46:47 +00:00
/**
* 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)'
*/
2016-08-26 00:18:47 +00:00
timer(timer: Phaser.Timer, x: number, y: number, color?: string): void;
}
}
class Weapon extends Phaser.Plugin {
constructor(game: Phaser.Game, parent: Phaser.PluginManager);
static KILL_NEVER: number;
static KILL_LIFESPAN: number;
static KILL_DISTANCE: number;
static KILL_WEAPON_BOUNDS: number;
static KILL_CAMERA_BOUNDS: number;
static KILL_WORLD_BOUNDS: number;
static KILL_STATIC_BOUNDS: number;
autoExpandBulletsGroup: boolean;
autofire: boolean;
bounds: Phaser.Rectangle;
bulletAngleOffset: number;
bulletAngleVariance: number;
bulletAnimation: string;
bulletClass: any;
bulletCollideWorldBounds: boolean;
bulletFrame: string;
bulletFrameCycle: boolean;
bulletFrameRandom: boolean;
bulletFrames: any[];
bulletGravity: Phaser.Point;
bulletInheritSpriteSpeed: boolean;
bulletKey: string;
bulletKillDistance: number;
bulletKillType: number;
bulletLifespan: number;
bulletRotateToVelocity: boolean;
bullets: Phaser.Group;
bulletSpeed: number;
bulletSpeedVariance: number;
bulletWorldWrap: boolean;
bulletWorldWrapPadding: number;
fireAngle: number;
fireFrom: Phaser.Rectangle;
fireLimit: number;
fireRate: number;
fireRateVariance: number;
onFire: Phaser.Signal;
onFireLimit: Phaser.Signal;
onKill: Phaser.Signal;
shots: number;
trackedPointer: Phaser.Pointer;
trackedSprite: any;
trackOffset: Phaser.Point;
trackRotation: boolean;
x: number;
y: number;
addBulletAnimation(name: string, frames?: number[] | string[], frameRate?: number, loop?: boolean, useNumericIndex?: boolean): Phaser.Weapon;
createBullets(quantity?: number, key?: any, frame?: any, group?: Phaser.Group): Phaser.Weapon;
debug(x?: number, y?: number, debugBodies?: boolean): void;
destroy(): void;
fire(from?: any, x?: number, y?: number): Phaser.Bullet;
fireAtPointer(pointer: Phaser.Pointer): Phaser.Bullet;
fireAtSprite(sprite: Phaser.Sprite): Phaser.Bullet;
fireAtXY(x: number, y: number): Phaser.Bullet;
forEach(callback: any, callbackContext: any): Phaser.Weapon;
killAll(): Phaser.Weapon;
pauseAll(): Phaser.Weapon;
resetShots(newLimit?: number): Phaser.Weapon;
resumeAll(): Phaser.Weapon;
setBulletBodyOffset(width: number, height: number, offsetX?: number, offsetY?: number): Phaser.Weapon;
setBulletFrames(min: number, max: number, cycle?: boolean, random?: boolean): Phaser.Weapon;
trackPointer(pointer: Phaser.Pointer, offsetX?: number, offsetY?: number): Phaser.Weapon;
trackSprite(sprite: Phaser.Sprite, offsetX?: number, offsetY?: number, trackRotation?: boolean): Phaser.Weapon;
}
2016-06-17 11:46:47 +00:00
/**
* "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.
*/
2016-08-26 00:18:47 +00:00
class World extends Phaser.Group {
2016-06-17 11:46:47 +00:00
/**
* "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.
*/
2016-08-26 00:18:47 +00:00
constructor(game: Phaser.Game);
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
bounds: Phaser.Rectangle;
2016-06-17 11:46:47 +00:00
/**
* Camera instance.
*/
2016-08-26 00:18:47 +00:00
camera: Phaser.Camera;
2016-06-17 11:46:47 +00:00
/**
* Gets the X position corresponding to the center point of the world.
*/
2016-08-26 00:18:47 +00:00
centerX: number;
2016-06-17 11:46:47 +00:00
/**
* Gets the Y position corresponding to the center point of the world.
*/
2016-08-26 00:18:47 +00:00
centerY: number;
2016-06-17 11:46:47 +00:00
/**
* A reference to the currently running Game.
*/
2016-08-26 00:18:47 +00:00
game: Phaser.Game;
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
2016-08-26 00:18:47 +00:00
height: number;
isPaused: boolean;
2016-06-17 11:46:47 +00:00
/**
* Gets a random integer which is lesser than or equal to the current width of the game world.
*/
2016-08-26 00:18:47 +00:00
randomX: number;
2016-06-17 11:46:47 +00:00
/**
* Gets a random integer which is lesser than or equal to the current height of the game world.
*/
2016-08-26 00:18:47 +00:00
randomY: number;
stats: {
skipped: number;
ignored: number;
checked: number;
};
2016-06-17 11:46:47 +00:00
/**
* Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
2016-08-26 00:18:47 +00:00
width: number;
2016-06-17 11:46:47 +00:00
/**
* Initialises the game world.
*/
2016-08-26 00:18:47 +00:00
boot(): void;
getObjectsUnderPointer(pointer: Phaser.Pointer, group: Phaser.Group, callback?: Function, callbackContext?: any): Phaser.Sprite;
2016-06-17 11:46:47 +00:00
/**
* Updates the size of this world. Note that this doesn't modify the world x/y coordinates, just the width and height.
*
* @param width New width of the game world in pixels.
* @param height New height of the game world in pixels.
*/
2016-08-26 00:18:47 +00:00
resize(width: number, height: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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.
*/
2016-08-26 00:18:47 +00:00
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;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
sort(group: Phaser.Group, sortDirection?: number): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
sort(key?: string, order?: number): void;
2016-06-17 11:46:47 +00:00
/**
* Destroyer of worlds.
*/
2016-08-26 00:18:47 +00:00
shutdown(): void;
2016-06-17 11:46:47 +00:00
/**
* 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
*/
2016-08-26 00:18:47 +00:00
wrap(sprite: any, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void;
}
}