(constraint: T): T;
/**
* Removes a Contact Material from the world.
*
* @param material The Contact Material to be removed from the World.
* @return The Contact Material that was removed.
*/
removeContactMaterial(material: Phaser.Physics.P2.ContactMaterial): Phaser.Physics.P2.ContactMaterial;
/**
* Removes a Spring from the world.
*
* @param spring The Spring to remove from the World.
* @return The Spring that was removed.
*/
removeSpring(spring: Phaser.Physics.P2.Spring): Phaser.Physics.P2.Spring;
/**
* Called by Phaser.Physics when a State swap occurs.
* Starts the begin and end Contact listeners again.
*/
reset(): void;
/**
* Resumes a paused P2 World.
*/
resume(): void;
/**
* Sets the bounds of the Physics world to match the given world pixel dimensions.
* You can optionally set which 'walls' to create: left, right, top or bottom.
* If none of the walls are given it will default to use the walls settings it had previously.
* I.e. if you previously told it to not have the left or right walls, and you then adjust the world size
* the newly created bounds will also not have the left and right walls.
* Explicitly state them in the parameters to override this.
*
* @param x The x coordinate of the top-left corner of the bounds.
* @param y The y coordinate of the top-left corner of the bounds.
* @param width The width of the bounds.
* @param height The height of the bounds.
* @param left If true will create the left bounds wall. - Default: true
* @param right If true will create the right bounds wall. - Default: true
* @param top If true will create the top bounds wall. - Default: true
* @param bottom If true will create the bottom bounds wall. - Default: true
* @param setCollisionGroup If true the Bounds will be set to use its own Collision Group. - Default: true
*/
setBounds(x: number, y: number, width: number, height: number, left?: Boolean, right?: boolean, top?: boolean, bottom?: boolean, setCollisionGroup?: boolean): void;
setBoundsToWorld(left?: boolean, right?: boolean, top?: boolean, bottom?: boolean, setCollisionGroup?: boolean): void;
setCollisionGroup(object: any, group: Phaser.Physics.P2.CollisionGroup): void;
/**
* Impact event handling is disabled by default. Enable it before any impact events will be dispatched.
* In a busy world hundreds of impact events can be generated every step, so only enable this if you cannot do what you need via beginContact or collision masks.
*
* @param state Set to true to enable impact events, or false to disable.
*/
setImpactEvents(state: boolean): void;
/**
* Sets the given Material against all Shapes owned by all the Bodies in the given array.
*
* @param material The Material to be applied to the given Bodies.
* @param bodies An Array of Body objects that the given Material will be set on.
*/
setMaterial(material: Phaser.Physics.P2.Material, bodies?: Phaser.Physics.P2.Body[]): void;
/**
* Sets a callback to be fired after the Broadphase has collected collision pairs in the world.
* Just because a pair exists it doesn't mean they *will* collide, just that they potentially could do.
* If your calback returns `false` the pair will be removed from the narrowphase. This will stop them testing for collision this step.
* Returning `true` from the callback will ensure they are checked in the narrowphase.
*
* @param callback The callback that will receive the postBroadphase event data. It must return a boolean. Set to null to disable an existing callback.
* @param context The context under which the callback will be fired.
*/
setPostBroadphaseCallback(callback: Function, context: any): void;
setWorldMaterial(material: Phaser.Physics.P2.Material, left?: boolean, right?: boolean, top?: boolean, bottom?: boolean): void;
/**
* Converts the current world into a JSON object.
* @return A JSON representation of the world.
*/
toJSON(): any;
/**
* Internal P2 update loop.
*/
update(): void;
/**
* By default the World will be set to collide everything with everything. The bounds of the world is a Body with 4 shapes, one for each face.
* If you start to use your own collision groups then your objects will no longer collide with the bounds.
* To fix this you need to adjust the bounds to use its own collision group first BEFORE changing your Sprites collision group.
*
* @param setCollisionGroup If true the Bounds will be set to use its own Collision Group. - Default: true
*/
updateBoundsCollisionGroup(setCollisionGroup?: boolean): void;
}
module P2 {
/**
* The Physics Body is typically linked to a single Sprite and defines properties that determine how the physics body is simulated.
* These properties affect how the body reacts to forces, what forces it generates on itself (to simulate friction), and how it reacts to collisions in the scene.
* In most cases, the properties are used to simulate physical effects. Each body also has its own property values that determine exactly how it reacts to forces and collisions in the scene.
* By default a single Rectangle shape is added to the Body that matches the dimensions of the parent Sprite. See addShape, removeShape, clearShapes to add extra shapes around the Body.
* Note: When bound to a Sprite to avoid single-pixel jitters on mobile devices we strongly recommend using Sprite sizes that are even on both axis, i.e. 128x128 not 127x127.
* Note: When a game object is given a P2 body it has its anchor x/y set to 0.5, so it becomes centered.
*/
class Body {
/**
* Dynamic body. Dynamic bodies body can move and respond to collisions and forces.
*/
static DYNAMIC: number;
/**
* Static body. Static bodies do not move, and they do not respond to forces or collision.
*/
static STATIC: number;
/**
* Kinematic body. Kinematic bodies only moves according to its .velocity, and does not respond to collisions or force.
*/
static KINEMATIC: number;
/**
* The Physics Body is typically linked to a single Sprite and defines properties that determine how the physics body is simulated.
* These properties affect how the body reacts to forces, what forces it generates on itself (to simulate friction), and how it reacts to collisions in the scene.
* In most cases, the properties are used to simulate physical effects. Each body also has its own property values that determine exactly how it reacts to forces and collisions in the scene.
* By default a single Rectangle shape is added to the Body that matches the dimensions of the parent Sprite. See addShape, removeShape, clearShapes to add extra shapes around the Body.
* Note: When bound to a Sprite to avoid single-pixel jitters on mobile devices we strongly recommend using Sprite sizes that are even on both axis, i.e. 128x128 not 127x127.
* Note: When a game object is given a P2 body it has its anchor x/y set to 0.5, so it becomes centered.
*
* @param game Game reference to the currently running game.
* @param sprite The Sprite object this physics body belongs to.
* @param x The x coordinate of this Body.
* @param y The y coordinate of this Body.
* @param mass The default mass of this Body (0 = static). - Default: 1
*/
constructor(game: Phaser.Game, sprite?: Phaser.Sprite, x?: number, y?: number, mass?: number);
/**
* -
*/
allowSleep: boolean;
/**
* The angle of the Body in degrees from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement Body.angle = 450 is the same as Body.angle = 90.
* If you wish to work in radians instead of degrees use the property Body.rotation instead. Working in radians is faster as it doesn't have to convert values. The angle of this Body in degrees.
*/
angle: number;
/**
* Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second. The angular damping acting acting on the body.
*/
angularDamping: number;
/**
* The angular force acting on the body.
*/
angularForce: number;
/**
* The angular velocity of the body.
*/
angularVelocity: number;
/**
* Array of CollisionGroups that this Bodies shapes collide with.
*/
collidesWith: Phaser.Physics.P2.CollisionGroup[];
/**
* A Body can be set to collide against the World bounds automatically if this is set to true. Otherwise it will leave the World.
* Note that this only applies if your World has bounds! The response to the collision should be managed via CollisionMaterials.
* Also note that when you set this it will only affect Body shapes that already exist. If you then add further shapes to your Body
* after setting this it will *not* proactively set them to collide with the bounds. Should the Body collide with the World bounds?
* Default: true
*/
collideWorldBounds: boolean;
/**
* Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second. The linear damping acting on the body in the velocity direction.
*/
damping: number;
/**
* The p2 Body data.
*/
data: p2.Body;
/**
* Enable or disable debug drawing of this body
*/
debug: boolean;
/**
* Reference to the debug body.
*/
debugBody: Phaser.Physics.P2.BodyDebug;
/**
* Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static.
*/
dynamic: boolean;
/**
* -
*/
fixedRotation: boolean;
/**
* The force applied to the body.
*/
force: Phaser.Physics.P2.InversePointProxy;
/**
* Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static.
*/
kinematic: boolean;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* A locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented.
*/
gravity: Phaser.Point;
/**
* The Body ID. Each Body that has been added to the World has a unique ID.
*/
id: number;
/**
* The inertia of the body around the Z axis..
*/
inertia: number;
/**
* The mass of the body.
*/
mass: number;
/**
* The type of motion this body has. Should be one of: Body.STATIC (the body does not move), Body.DYNAMIC (body can move and respond to collisions) and Body.KINEMATIC (only moves according to its .velocity).
*/
motionState: number;
/**
* The offset of the Physics Body from the Sprite x/y position.
*/
offset: Phaser.Point;
/**
* Dispatched when a first contact is created between shapes in two bodies.
* This event is fired during the step, so collision has already taken place.
*
* The event will be sent 5 arguments in this order:
*
* The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world.
* The p2.Body this Body is in contact with.
* The Shape from this body that caused the contact.
* The Shape from the contact body.
* The Contact Equation data array.
*/
onBeginContact: Phaser.Signal;
/**
* Dispatched when contact ends between shapes in two bodies.
* This event is fired during the step, so collision has already taken place.
*
* The event will be sent 4 arguments in this order:
*
* The Phaser.Physics.P2.Body it is in contact with. *This might be null* if the Body was created directly in the p2 world.
* The p2.Body this Body has ended contact with.
* The Shape from this body that caused the original contact.
* The Shape from the contact body.
*/
onEndContact: Phaser.Signal;
/**
* The angle of the Body in radians.
* If you wish to work in degrees instead of radians use the Body.angle property instead. Working in radians is faster as it doesn't have to convert values. The angle of this Body in radians.
*/
rotation: number;
/**
* To avoid deleting this body during a physics step, and causing all kinds of problems, set removeNextStep to true to have it removed in the next preUpdate.
*/
removeNextStep: boolean;
/**
* Reference to the parent Sprite.
*/
sprite: Phaser.Sprite;
/**
* .
*/
sleepSpeedLimit: number;
/**
* Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic.
*/
static: boolean;
/**
* The type of physics system this body belongs to.
*/
type: number;
/**
* The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.
*/
velocity: Phaser.Physics.P2.InversePointProxy;
/**
* Local reference to the P2 World.
*/
world: Phaser.Physics.P2;
/**
* The x coordinate of this Body.
*/
x: number;
/**
* The y coordinate of this Body.
*/
y: number;
/**
* Adds this physics body to the world.
*/
addToWorld(): void;
/**
* Adds a Capsule shape to this Body.
* You can control the offset from the center of the body and the rotation.
*
* @param length The distance between the end points in pixels.
* @param radius Radius of the capsule in pixels.
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Capsule shape that was added to the Body.
*/
addCapsule(length: number, radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Capsule;
/**
* Adds a Circle shape to this Body. You can control the offset from the center of the body and the rotation.
*
* @param radius The radius of this circle (in pixels)
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Circle shape that was added to the Body.
*/
addCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle;
/**
* Add a polygon fixture. This is used during #loadPolygon.
*
* @param fixtureData The data for the fixture. It contains: isSensor, filter (collision) and the actual polygon shapes.
* @return An array containing the generated shapes for the given polygon.
*/
addFixture(fixtureData: string): p2.Shape[];
/**
* Adds a Line shape to this Body.
* The line shape is along the x direction, and stretches from [-length/2, 0] to [length/2,0].
* You can control the offset from the center of the body and the rotation.
*
* @param length The length of this line (in pixels)
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Line shape that was added to the Body.
*/
addLine(length: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Line;
/**
* Adds a Particle shape to this Body. You can control the offset from the center of the body and the rotation.
*
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Particle shape that was added to the Body.
*/
addParticle(offsetX?: number, offsetY?: number, rotation?: number): p2.Particle;
/**
* Reads a polygon shape path, and assembles convex shapes from that and puts them at proper offset points. The shape must be simple and without holes.
* This function expects the x.y values to be given in pixels. If you want to provide them at p2 world scales then call Body.data.fromPolygon directly.
*
* @param options An object containing the build options:
* @param options.optimalDecomp Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices.
* @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself.
* @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points.
* @param points An array of 2d vectors that form the convex or concave polygon.
* Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...],
* or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers.
* @return True on success, else false.
*/
addPolygon(options: { optimalDecomp?: boolean; skipSimpleCheck?: boolean; removeCollinearPoints?: boolean; }, points: number[][]): boolean;
/**
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
* The shape data format is based on the output of the
* {@link https://github.com/photonstorm/phaser/tree/master/resources/PhysicsEditor%20Exporter|custom phaser exporter} for
* {@link https://www.codeandweb.com/physicseditor|PhysicsEditor}
*
* @param key The key of the Physics Data file as stored in Game.Cache.
* @param object The key of the object within the Physics data file that you wish to load the shape data from.
* @return A list of created fixtures to be used with Phaser.Physics.P2.FixtureList
*/
addPhaserPolygon(key: string, object: string): Phaser.Physics.P2.FixtureList;
/**
* Adds a Plane shape to this Body. The plane is facing in the Y direction. You can control the offset from the center of the body and the rotation.
*
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Plane shape that was added to the Body.
*/
addPlane(offsetX?: number, offsetY?: number, rotation?: number): p2.Plane;
/**
* Adds a Rectangle shape to this Body. You can control the offset from the center of the body and the rotation.
*
* @param width The width of the rectangle in pixels.
* @param height The height of the rectangle in pixels.
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The shape that was added to the Body.
*/
addRectangle(width: number, height: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle;
/**
* Add a shape to the body. You can pass a local transform when adding a shape, so that the shape gets an offset and an angle relative to the body center of mass.
* Will automatically update the mass properties and bounding radius.
* If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates.
*
* @param shape The shape to add to the body.
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The shape that was added to the body.
*/
addShape(shape: p2.Shape, offsetX?: number, offsetY?: number, rotation?: number): p2.Shape;
/**
* Moves the shape offsets so their center of mass becomes the body center of mass.
*/
adjustCenterOfMass(): void;
/**
* Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details.
*
* @param dt Current time step.
*/
applyDamping(dt: number): void;
/**
* Apply force to a world point.
*
* This could for example be a point on the RigidBody surface. Applying force
* this way will add to Body.force and Body.angularForce.
*
* @param force The force vector to add.
* @param worldX The world x point to apply the force on.
* @param worldY The world y point to apply the force on.
*/
applyForce(force: number[], worldX: number, worldY: number): void;
/**
* Apply impulse to a point relative to the body.
* This could for example be a point on the Body surface. An impulse is a force added to a body during a short
* period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.
*
* @param impulse The impulse vector to add, oriented in world space.
* @param worldX A point relative to the body in world space. If not given, it is set to zero and all of the impulse will be exerted on the center of mass.
* @param worldY A point relative to the body in world space. If not given, it is set to zero and all of the impulse will be exerted on the center of mass.
*/
applyImpulse(impulse: number[], worldX: number, worldY: number): void;
/**
* Apply impulse to a point local to the body.
*
* This could for example be a point on the Body surface. An impulse is a force added to a body during a short
* period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity.
*
* @param impulse The impulse vector to add, oriented in local space.
* @param localX A local point on the body.
* @param localY A local point on the body.
*/
applyImpulseLocal(impulse: number[], localX: number, localY: number): void;
/**
* Clears the collision data from the shapes in this Body. Optionally clears Group and/or Mask.
*
* @param clearGroup Clear the collisionGroup value from the shape/s? - Default: true
* @param clearMask Clear the collisionMask value from the shape/s? - Default: true
* @param shape An optional Shape. If not provided the collision data will be cleared from all Shapes in this Body.
*/
clearCollision(clearGroup?: boolean, cleanMask?: boolean, shape?: p2.Shape): void;
/**
* Removes all Shapes from this Body.
*/
clearShapes(): void;
/**
* Adds the given CollisionGroup, or array of CollisionGroups, to the list of groups that this body will collide with and updates the collision masks.
*
* @param group The Collision Group or Array of Collision Groups that this Bodies shapes will collide with.
* @param callback Optional callback that will be triggered when this Body impacts with the given Group.
* @param callbackContext The context under which the callback will be called.
* @param shape An optional Shape. If not provided the collision mask will be added to all Shapes in this Body.
*/
collides(group: any, callback?: Function, callbackContext?: any, shape?: p2.Shape): void;
/**
* Sets a callback to be fired any time a shape in this Body impacts with a shape in the given Body. The impact test is performed against body.id values.
* The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body.
* Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening.
* It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate.
*
* @param object The object to send impact events for.
* @param callback The callback to fire on impact. Set to null to clear a previously set callback.
* @param callbackContext The context under which the callback will fire.
*/
createBodyCallback(object: any, callback: Function, callbackContext: any): void;
/**
* Sets a callback to be fired any time this Body impacts with the given Group. The impact test is performed against shape.collisionGroup values.
* The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body.
* This callback will only fire if this Body has been assigned a collision group.
* Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening.
* It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate.
*
* @param group The Group to send impact events for.
* @param callback The callback to fire on impact. Set to null to clear a previously set callback.
* @param callbackContext The context under which the callback will fire.
*/
createGroupCallback(group: Phaser.Physics.P2.CollisionGroup, callback: Function, callbackContext: any): void;
/**
* Destroys this Body and all references it holds to other objects.
*/
destroy(): void;
/**
* Gets the collision bitmask from the groups this body collides with.
* @return The bitmask.
*/
getCollisionMask(): number;
/**
* Gets the velocity of a point in the body.
*
* @param result A vector to store the result in.
* @param relativePoint A world oriented vector, indicating the position of the point to get the velocity from.
* @return The result vector.
*/
getVelocityAtPoint(result: number[], relativePoint: number[]): number[];
/**
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
*
* As well as reading the data from the Cache you can also pass `null` as the first argument and a
* physics data object as the second. When doing this you must ensure the structure of the object is correct in advance.
*
* For more details see the format of the Lime / Corona Physics Editor export.
*
* @param key The key of the Physics Data file as stored in Game.Cache. Alternatively set to `null` and pass the
* data as the 2nd argument.
* @param object The key of the object within the Physics data file that you wish to load the shape data from,
* or if key is null pass the actual physics data object itself as this parameter.
* @param scale Optionally resize the loaded polygon. - Default: 1
* @return True on success, else false.
*/
loadPolygon(key: string, object: string, scale ?: number): boolean;
/**
* Moves the Body backwards based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move backwards.
*/
moveBackward(speed: number): void;
/**
* If this Body is dynamic then this will move it down by setting its y velocity to the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move down, in pixels per second.
*/
moveDown(speed: number): void;
/**
* Moves the Body forwards based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move forwards.
*/
moveForward(speed: number): void;
/**
* If this Body is dynamic then this will move it to the left by setting its x velocity to the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move to the left, in pixels per second.
*/
moveLeft(speed: number): void;
/**
* If this Body is dynamic then this will move it to the right by setting its x velocity to the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move to the right, in pixels per second.
*/
moveRight(speed: number): void;
/**
* If this Body is dynamic then this will move it up by setting its y velocity to the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move up, in pixels per second.
*/
moveUp(speed: number): void;
/**
* Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
*/
preUpdate(): void;
/**
* Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.
*/
postUpdate(): void;
/**
* Removes the given CollisionGroup, or array of CollisionGroups, from the list of groups that this body will collide with and updates the collision masks.
*
* @param group The Collision Group or Array of Collision Groups that this Bodies shapes should not collide with anymore.
* @param clearCallback Clear the callback that will be triggered when this Body impacts with the given Group? - Default: true
* @param shape An optional Shape. If not provided the updated collision mask will be added to all Shapes in this Body.
*/
removeCollisionGroup(group: any, clearCallback?: boolean, shape?: p2.Shape): void;
/**
* Removes this physics body from the world.
*/
removeFromWorld(): void;
/**
* Remove a shape from the body. Will automatically update the mass properties and bounding radius.
*
* @param shape The shape to remove from the body.
* @return True if the shape was found and removed, else false.
*/
removeShape(shape: p2.Shape): boolean;
/**
* Applies a force to the Body that causes it to 'thrust' backwards (in reverse), based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should reverse.
*/
reverse(speed: number): void;
/**
* This will rotate the Body by the given speed to the left (counter-clockwise).
*
* @param speed The speed at which it should rotate.
*/
rotateLeft(speed: number): void;
/**
* This will rotate the Body by the given speed to the left (clockwise).
*
* @param speed The speed at which it should rotate.
*/
rotateRight(speed: number): void;
/**
* Resets the Body force, velocity (linear and angular) and rotation. Optionally resets damping and mass.
*
* @param x The new x position of the Body.
* @param y The new x position of the Body.
* @param resetDamping Resets the linear and angular damping.
* @param resetMass Sets the Body mass back to 1.
*/
reset(x: number, y: number, resetDamping?: boolean, resetMass?: boolean): void;
/**
* Updates the debug draw if any body shapes change.
*/
shapeChanged(): void;
/**
* Clears any previously set shapes. Then creates a new Circle shape and adds it to this Body.
* If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates.
*
* @param radius The radius of this circle (in pixels)
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
*/
setCircle(radius: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Circle;
/**
* Sets the given CollisionGroup to be the collision group for all shapes in this Body, unless a shape is specified.
* This also resets the collisionMask.
*
* @param group The Collision Group that this Bodies shapes will use.
* @param shape An optional Shape. If not provided the collision group will be added to all Shapes in this Body.
*/
setCollisionGroup(group: Phaser.Physics.P2.CollisionGroup, shape?: p2.Shape): void;
/**
* Clears any previously set shapes. The creates a new Rectangle shape at the given size and offset, and adds it to this Body.
* If you wish to create a Rectangle to match the size of a Sprite or Image see Body.setRectangleFromSprite.
* If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates.
*
* @param width The width of the rectangle in pixels. - Default: 16
* @param height The height of the rectangle in pixels. - Default: 16
* @param offsetX Local horizontal offset of the shape relative to the body center of mass.
* @param offsetY Local vertical offset of the shape relative to the body center of mass.
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians.
* @return The Rectangle shape that was added to the Body.
*/
setRectangle(width?: number, height?: number, offsetX?: number, offsetY?: number, rotation?: number): p2.Rectangle;
/**
* Clears any previously set shapes.
* Then creates a Rectangle shape sized to match the dimensions and orientation of the Sprite given.
* If no Sprite is given it defaults to using the parent of this Body.
* If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates.
*
* @param sprite The Sprite on which the Rectangle will get its dimensions.
* @return The Rectangle shape that was added to the Body.
*/
setRectangleFromSprite(sprite: any): p2.Rectangle;
/**
* Adds the given Material to all Shapes that belong to this Body.
* If you only wish to apply it to a specific Shape in this Body then provide that as the 2nd parameter.
*
* @param material The Material that will be applied.
* @param shape An optional Shape. If not provided the Material will be added to all Shapes in this Body.
*/
setMaterial(material: Phaser.Physics.P2.Material, shape?: p2.Shape): void;
/**
* Sets the Body damping and angularDamping to zero.
*/
setZeroDamping(): void;
/**
* Sets the force on the body to zero.
*/
setZeroForce(): void;
/**
* If this Body is dynamic then this will zero its angular velocity.
*/
setZeroRotation(): void;
/**
* If this Body is dynamic then this will zero its velocity on both axis.
*/
setZeroVelocity(): void;
/**
* Transform a world point to local body frame.
*
* @param out The vector to store the result in.
* @param worldPoint The input world vector.
*/
toLocalFrame(out: number[], worldPoint: number[]): void;
/**
* Applies a force to the Body that causes it to 'thrust' forwards, based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should thrust.
*/
thrust(speed: number): void;
/**
* Applies a force to the Body that causes it to 'thrust' to the left, based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move to the left.
*/
thrustLeft(speed: number): void;
/**
* Applies a force to the Body that causes it to 'thrust' to the right, based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @param speed The speed at which it should move to the right.
*/
thrustRight(speed: number): void;
/**
* Transform a local point to world frame.
*
* @param out The vector to store the result in.
* @param localPoint The input local vector.
*/
toWorldFrame(out: number[], localPoint: number[]): void;
/**
* Updates the collisionMask.
*
* @param shape An optional Shape. If not provided the collision group will be added to all Shapes in this Body.
*/
updateCollisionMask(shape?: p2.Shape): void;
}
/**
* Draws a P2 Body to a Graphics instance for visual debugging.
* Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead.
* So use sparingly and rarely (if ever) in production code.
*
* Also be aware that the Debug body is only updated when the Sprite it is connected to changes position. If you
* manipulate the sprite in any other way (such as moving it to another Group or bringToTop, etc) then you will
* need to manually adjust its BodyDebug as well.
*/
class BodyDebug extends Phaser.Group {
/**
* Draws a P2 Body to a Graphics instance for visual debugging.
* Needless to say, for every body you enable debug drawing on, you are adding processor and graphical overhead.
* So use sparingly and rarely (if ever) in production code.
*
* Also be aware that the Debug body is only updated when the Sprite it is connected to changes position. If you
* manipulate the sprite in any other way (such as moving it to another Group or bringToTop, etc) then you will
* need to manually adjust its BodyDebug as well.
*
* @param game Game reference to the currently running game.
* @param body The P2 Body to display debug data for.
* @param settings Settings object.
*/
/**
* The alpha value of the group container.
*/
constructor(game: Phaser.Game, body: Phaser.Physics.P2.Body, settings: { pixelsPerLengthUnit?: number; debugPolygons?: boolean; lineWidth?: number; alpha?: number; });
/**
* The P2 Body to display debug data for.
*/
body: Phaser.Physics.P2.Body;
/**
* The canvas to render the debug info to.
*/
canvas: Phaser.Graphics;
/**
* Pixels per Length Unit.
*/
ppu: number;
/**
* Core update.
*/
updateSpriteTransform(): void;
/**
* Draws the P2 shapes to the Graphics object.
*/
draw(): void;
}
/**
* Collision Group
*/
class CollisionGroup {
/**
* Collision Group
*
* @param bitmask The CollisionGroup bitmask.
*/
constructor(bitmask: number);
/**
* The CollisionGroup bitmask.
*/
mask: number;
}
/**
* Defines a physics material
*/
class ContactMaterial extends p2.ContactMaterial {
}
/**
* A constraint that tries to keep the distance between two bodies constant.
*/
class DistanceConstraint extends p2.DistanceConstraint {
/**
* A constraint that tries to keep the distance between two bodies constant.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param bodyB Second connected body.
* @param distance The distance to keep between the bodies.
* @param localAnchorA The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0].
* @param localAnchorB The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0].
* @param maxForce Maximum force to apply. - Default: Number.MAX_VALUE
*/
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, distance: number, maxForce: number);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
/**
* Allow to access a list of created fixture (coming from Body#addPhaserPolygon)
* which itself parse the input from PhysicsEditor with the custom phaser exporter.
* You can access fixtures of a Body by a group index or even by providing a fixture Key.
* You can set the fixture key and also the group index for a fixture in PhysicsEditor.
* This gives you the power to create a complex body built of many fixtures and modify them
* during runtime (to remove parts, set masks, categories & sensor properties)
*/
class FixtureList {
/**
* Allow to access a list of created fixture (coming from Body#addPhaserPolygon)
* which itself parse the input from PhysicsEditor with the custom phaser exporter.
* You can access fixtures of a Body by a group index or even by providing a fixture Key.
* You can set the fixture key and also the group index for a fixture in PhysicsEditor.
* This gives you the power to create a complex body built of many fixtures and modify them
* during runtime (to remove parts, set masks, categories & sensor properties)
*
* @param list A list of fixtures (from Phaser.Physics.P2.Body#addPhaserPolygon)
*/
constructor(list: any[]);
/**
* A helper to flatten arrays. This is very useful as the fixtures are nested from time to time due to the way P2 creates and splits polygons.
*
* @param array The array to flatten. Notice: This will happen recursive not shallow.
*/
flatten(array: any[]): any[];
/**
* Accessor to get either a list of specified fixtures by key or the whole fixture list
*
* @param keys A list of fixture keys
*/
getFixtures(keys: string): any[];
/**
* Accessor to get either a single fixture by its key.
*
* @param key The key of the fixture.
*/
getFixtureByKey(key: string): any[];
/**
* Accessor to get a group of fixtures by its group index.
*
* @param groupID The group index.
*/
getGroup(groupID: number): any[];
init(): void;
/**
* Parser for the output of Phaser.Physics.P2.Body#addPhaserPolygon
*/
parse(): void;
/**
*
*
* @param bit The bit to set as the collision group.
* @param fixtureKey Only apply to the fixture with the given key.
*/
setCategory(bit: number, fictureKey: string): void;
/**
*
*
* @param bit The bit to set as the collision mask
* @param fixtureKey Only apply to the fixture with the given key
*/
setMask(bit: number, fixtureKey: string): void;
/**
*
*
* @param material The contact material for a fixture
* @param fixtureKey Only apply to the fixture with the given key
*/
setMaterial(material: any, fixtureKey: string): void;
/**
*
*
* @param value sensor true or false
* @param fixtureKey Only apply to the fixture with the given key
*/
setSensor(value: boolean, fixtureKey: string): void;
}
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
class GearConstraint extends p2.GearConstraint {
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param bodyB Second connected body.
* @param angle The relative angle
* @param ratio The gear ratio. - Default: 1
*/
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, angle?: number, ratio?: number);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
/**
* A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set.
*/
class InversePointProxy {
/**
* A InversePointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays but inverses the values on set.
*
* @param world A reference to the P2 World.
* @param destination The object to bind to.
*/
constructor(world: Phaser.Physics.P2, destination: any);
/**
* The x property of this InversePointProxy get and set in pixels.
*/
x: number;
/**
* The y property of this InversePointProxy get and set in pixels.
*/
y: number;
/**
* The x property of this InversePointProxy get and set in meters.
*/
mx: number;
/**
* The y property of this InversePointProxy get and set in meters.
*/
my: number;
}
/**
* Locks the relative position between two bodies.
*/
class LockConstraint extends p2.LockConstraint {
/**
* Locks the relative position between two bodies.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param bodyB Second connected body.
* @param offset The offset of bodyB in bodyA's frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param angle The angle of bodyB in bodyA's frame.
* @param maxForce The maximum force that should be applied to constrain the bodies.
*/
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, offset?: number[], angle?: number, maxForce?: number);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*/
class Material extends p2.Material {
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*
* @param name The user defined name given to this Material.
*/
constructor(name: string);
/**
* The user defined name given to this Material.
*/
name: string;
}
/**
* A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays.
*/
class PointProxy {
/**
* A PointProxy is an internal class that allows for direct getter/setter style property access to Arrays and TypedArrays.
*
* @param world A reference to the P2 World.
* @param destination The object to bind to.
*/
constructor(world: Phaser.Physics.P2, destination: any);
/**
* The x property of this PointProxy get and set in pixels.
*/
x: number;
/**
* The y property of this PointProxy get and set in pixels.
*/
y: number;
/**
* The x property of this PointProxy get and set in meters.
*/
mx: number;
/**
* The x property of this PointProxy get and set in meters.
*/
my: number;
}
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
class PrismaticConstraint extends p2.PrismaticConstraint {
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param bodyB Second connected body.
* @param lockRotation If set to false, bodyB will be free to rotate around its anchor point. - Default: true
* @param anchorA Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param anchorB Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param axis An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param maxForce The maximum force that should be applied to constrain the bodies.
*/
constructor(world: Phaser.Physics.P2, bodyA?: Phaser.Physics.P2.Body, bodyB?: Phaser.Physics.P2.Body, lockRotation?: boolean, anchorA?: number[], anchorB?: number[], axis?: number[], maxForce?: number);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
* The pivot points are given in world (pixel) coordinates.
*/
class RevoluteConstraint extends p2.RevoluteConstraint {
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
* The pivot points are given in world (pixel) coordinates.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param pivotA The point relative to the center of mass of bodyA which bodyA is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param bodyB Second connected body.
* @param pivotB The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param maxForce The maximum force that should be applied to constrain the bodies.
* @param worldPivot A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
*/
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, pivotA: number[], bodyB: Phaser.Physics.P2.Body, pivotB: number[], maxForce?: number);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
/**
* Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
*/
class Spring {
/**
* Creates a linear spring, connecting two bodies. A spring can have a resting length, a stiffness and damping.
*
* @param world A reference to the P2 World.
* @param bodyA First connected body.
* @param bodyB Second connected body.
* @param restLength Rest length of the spring. A number > 0. - Default: 1
* @param stiffness Stiffness of the spring. A number >= 0. - Default: 100
* @param damping Damping of the spring. A number >= 0. - Default: 1
* @param worldA Where to hook the spring to body A in world coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param worldB Where to hook the spring to body B in world coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param localA Where to hook the spring to body A in local body coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param localB Where to hook the spring to body B in local body coordinates. This value is an array with 2 elements matching x and y, i.e: [32, 32].
*/
constructor(world: Phaser.Physics.P2, bodyA: Phaser.Physics.P2.Body, bodyB: Phaser.Physics.P2.Body, restLength?: number, stiffness?: number, damping?: number, worldA?: number[], worldB?: number[], localA?: number[], localB?: number[]);
/**
* The actual p2 spring object.
*/
data: p2.LinearSpring;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Local reference to P2 World.
*/
world: Phaser.Physics.P2;
}
}
}
/**
* This is a base Plugin template to use for any Phaser plugin development.
*/
class Plugin implements IStateCycle {
/**
* 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.
*/
constructor(game: Phaser.Game, parent: Phaser.PluginManager);
/**
* A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
*/
active: boolean;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* A flag to indicate if this plugin has a postRender method.
*/
hasPostRender: boolean;
/**
* A flag to indicate if this plugin has a postUpdate method.
*/
hasPostUpdate: boolean;
/**
* A flag to indicate if this plugin has a preUpdate method.
*/
hasPreUpdate: boolean;
/**
* A flag to indicate if this plugin has a render method.
*/
hasRender: boolean;
/**
* A flag to indicate if this plugin has an update method.
*/
hasUpdate: boolean;
/**
* The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
parent: PIXI.DisplayObject;
/**
* A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
*/
visible: boolean;
/**
* Clear down this Plugin and null out references
*/
destroy(): void;
/**
* Post-render is called after the Game Renderer and State.render have run.
* It is only called if visible is set to true.
*/
postRender(): void;
/**
* Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
* It is only called if active is set to true.
*/
preUpdate(): void;
/**
* Render is called right after the Game Renderer completes, but before the State.render.
* It is only called if visible is set to true.
*/
render(): void;
/**
* Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
* It is only called if active is set to true.
*/
update(): void;
}
module Plugin {
class SaveCPU extends Phaser.Plugin {
renderOnFPS: number;
renderOnPointerChange: boolean;
forceRender(): void;
}
/**
* AStar is a phaser pathfinding plugin based on an A* kind of algorythm
* It works with the Phaser.Tilemap
*/
class AStar extends Phaser.Plugin {
static VERSION: string;
static COST_ORTHOGONAL: number;
static COST_DIAGONAL: number;
static DISTANCE_MANHATTAN: string;
static DISTANCE_EUCLIDIAN: string;
/**
* AStar is a phaser pathfinding plugin based on an A* kind of algorythm
* It works with the Phaser.Tilemap
*
* @param parent The object that owns this plugin, usually Phaser.PluginManager.
*/
constructor(parent: PIXI.DisplayObject);
/**
* The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
parent: PIXI.DisplayObject;
version: string;
/**
* Find a path between to tiles coordinates
*
* @param startPoint The start point x, y in tiles coordinates to search a path.
* @param goalPoint The goal point x, y in tiles coordinates that you trying to reach.
* @return The Phaser.Plugin.AStar.AStarPath that results
*/
findPath(startPoint: Phaser.Point, goalPoint: Phaser.Point): Phaser.Plugin.AStar.AStarPath;
isWalkable(x: number, y: number): boolean;
/**
* Sets the Phaser.Tilemap used to searchPath into.
*
* @param map the Phaser.Tilemap used to searchPath into. It must have a tileset with tile porperties to know if tiles are walkable or not.
* @param layerName The name of the layer that handle tiles.
* @param tilesetName The name of the tileset that have walkable properties.
* @return The Phaser.Plugin.AStar itself.
*/
setAStarMap(map: Phaser.Tilemap, layerName: string, tilesetName: string): Phaser.Plugin.AStar;
}
module AStar {
/**
* AStarNode is an object that stores AStar value. Each tile have an AStarNode in their properties
*/
class AStarNode {
/**
* AStarNode is an object that stores AStar value. Each tile have an AStarNode in their properties
*
* @param x The x coordinate of the tile.
* @param y The y coordinate of the tile.
* @param isWalkable Is this tile is walkable?
*/
constructor(x: number, y: number, isWalkable: boolean);
/**
* The x coordinate of the tile.
*/
x: number;
/**
* The y coordinate of the tile.
*/
y: number;
/**
* The total travel cost from the start point. Sum of COST_ORTHOGONAL and COST_DIAGONAL
*/
g: number;
/**
* The remaing distance as the crow flies between this node and the goal.
*/
h: number;
/**
* The weight. Sum of g + h.
*/
f: number;
/**
* Where do we come from? It's an AStarNode reference needed to reconstruct a path backwards (from goal to start point)
*/
parent: Phaser.Plugin.AStar.AStarNode;
/**
* The cost to travel to this node, COST_ORTHOGONAL or COST_DIAGONAL
*/
travelCost: number;
/**
* Is this node is walkable?
*/
walkable: boolean;
}
interface AStarNodeArray {
x: number;
y: number;
}
/**
* AStarPath is an object that stores a searchPath result.
*/
class AStarPath {
/**
* AStarPath is an object that stores a searchPath result.
*
* @param nodes An array of nodes coordinates sorted backward from goal to start point.
* @param start The start AStarNode used for the searchPath.
* @param goal The goal AStarNode used for the searchPath.
*/
constructor(nodes?: AStarNodeArray[], start?: Phaser.Plugin.AStar.AStarNode, goal?: Phaser.Plugin.AStar.AStarNode);
/**
* Array of AstarNodes x, y coordiantes that are the path solution from goal to start point.
*/
nodes: AStarNodeArray[];
/**
* Reference to the start point used by findPath.
*/
start: Phaser.Plugin.AStar.AStarNode;
/**
* Reference to the goal point used by findPath.
*/
goal: Phaser.Plugin.AStar.AStarNode;
/**
* Array of AStarNodes that the findPath algorythm has visited. Used for debug only.
*/
visited: Phaser.Plugin.AStar.AStarNode[];
}
}
/**
* A collection of methods useful for manipulating and comparing colors.
*/
class ColorHarmony extends Phaser.Plugin {
/**
* Returns an Analogous Color Harmony for the given color.
* An Analogous harmony are hues adjacent to each other on the color wheel
* Values returned in 0xAARRGGBB format with Alpha set to 255.
*
* @param color The color to base the harmony on.
* @param threshold Control how adjacent the colors will be (default +- 30 degrees)
* @return Object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color)
*/
getAnalogousHarmony(color: number, threshold?: number): any;
/**
* Returns a Complementary Color Harmony for the given color.
* A complementary hue is one directly opposite the color given on the color wheel
* Value returned in 0xAARRGGBB format with Alpha set to 255.
*
* @param color The color to base the harmony on.
* @return 0xAARRGGBB format color value.
*/
getComplementHarmony(color: number): number;
/**
* Returns an Split Complement Color Harmony for the given color.
* A Split Complement harmony are the two hues on either side of the color's Complement
* Values returned in 0xAARRGGBB format with Alpha set to 255.
*
* @param color The color to base the harmony on
* @param threshold Control how adjacent the colors will be to the Complement (default +- 30 degrees)
* @return An object containing 3 properties: color1 (the original color), color2 (the warmer analogous color) and color3 (the colder analogous color)
*/
getSplitComplementHarmony(color: number, threshold: number): any;
/**
* Returns a Triadic Color Harmony for the given color.
* A Triadic harmony are 3 hues equidistant from each other on the color wheel
* Values returned in 0xAARRGGBB format with Alpha set to 255.
*
* @param color The color to base the harmony on.
* @return An Object containing 3 properties: color1 (the original color), color2 and color3 (the equidistant colors)
*/
getTriadicHarmony(color: number): any;
}
/**
* Phaser - Display - CSS3Filters
*
* Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas).
*/
class CSS3Filters extends Phaser.Plugin {
/**
* Phaser - Display - CSS3Filters
*
* Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas).
*/
constructor(parent: PIXI.DisplayObject);
blur: number;
brightness: number;
contrast: number;
grayscale: number;
hueRotate: number;
invert: number;
opacity: number;
saturate: number;
sepia: number;
}
/**
* Creates an object that is placed within a layer of a Phaser.Tilemap and can be moved around and rotated using the direction commands.
*/
class TilemapWalker extends Phaser.Plugin {
/**
* Creates an object that is placed within a layer of a Phaser.Tilemap and can be moved around and rotated using the direction commands.
*
* @param game Game reference to the currently running game.
* @param map A reference to the Tilemap this TilemapWalker belongs to.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @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)
*/
constructor(game: Phaser.Game, map: Phaser.Tilemap, layer?: any, x?: number, y?: number);
/**
* Does the TilemapWalker collide with the tiles in the map set for collision? If so it cannot move through them.
* Default: true
*/
collides: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* An array containing a history of movements through the map.
*/
history: boolean;
/**
* The direction the location marker is facing. You can rotate it using the turn and face methods.
*/
facing: number;
/**
* A reference to the Tilemap this TilemapWalker belongs to.
*/
map: Phaser.Tilemap;
/**
* The current marker location. You can move the marker with the movement methods.
*/
location: Phaser.Point;
/**
* The current layer of the location marker.
*/
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;
}
/**
* A Sample Plugin demonstrating how to hook into the Phaser plugin system.
*/
class SamplePlugin extends Phaser.Plugin {
/**
* A Sample Plugin demonstrating how to hook into the Phaser plugin system.
*/
constructor(game: Phaser.Game, parent: PIXI.DisplayObject);
/**
* Add a Sprite reference to this Plugin.
* All this plugin does is move the Sprite across the screen slowly.
*/
addSprite(sprite: Phaser.Sprite): void;
/**
* This is run when the plugins update during the core game loop.
*/
update(): void;
}
/**
* A Virtual Joystick
*/
class VirtualJoystick extends Phaser.Plugin {
/**
* A Virtual Joystick
*/
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;
/**
* Given the 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 sprite The Sprite to set the velocity on. The Sprite must have a physics body already set. The value will be set into Sprite.body.velocity.
* @param minSpeed The minimum speed the Sprite will move if the joystick is at its default (non-moved) position.
* @param maxSpeed The maximum speed the Sprite will move if the joystick is at its full extent. - Default: 100
* @return The Sprite object.
*/
setVelocity(sprite: Phaser.Sprite, minSpeed?: number, maxSpeed?: number): Phaser.Sprite;
startDrag(): void;
stopDrag(nub: Phaser.Sprite, pointer: Phaser.Pointer): void;
update(): void;
}
/**
* Provides access to the Webcam (if available)
*/
class Webcam extends Phaser.Plugin {
/**
* Provides access to the Webcam (if available)
*/
constructor(game: Phaser.Game, parent: PIXI.DisplayObject);
/**
* Is this Webcam plugin capturing a video stream or not?
*/
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;
}
/**
* Creates a new `Juicy` object.
*/
class Juicy extends Phaser.Plugin {
/**
* Creates a new `Juicy` object.
*
* @param game Current game instance.
*/
constructor(game: Phaser.Game);
/**
* Creates a 'Juicy.ScreenFlash' object
*
* @param color The color of the screen flash
*/
createScreenFlash(color?: string): Phaser.Plugin.Juicy.ScreenFlash;
/**
* Creates a 'Juicy.Trail' object
*
* @param length The length of the trail
* @param color The color of the trail
*/
createTrail(length?: number, color?: number): Phaser.Plugin.Juicy.Trail;
/**
* Creates the over scale effect on the given object
*
* @param object The object to over scale
* @param scale The scale amount to overscale by - Default: 1.5
* @param initialScale The initial scale of the object - Default: new Phaser.Point(1,1)
*/
overScale(object: Phaser.Sprite, scale?: number, initialScale?: Phaser.Point): void;
/**
* Creates the jelly effect on the given object
*
* @param object The object to gelatinize
* @param strength The strength of the effect - Default: 0.2
* @param delay The delay of the snap-back tween. 50ms are automaticallly added to whatever the delay amount is.
* @param initialScale The initial scale of the object - Default: new Phaser.Point(1,1)
*/
jelly(object: Phaser.Sprite, strength?: number, delay?: number, initialScale?: Phaser.Point): void;
/**
* Creates the mouse stretch effect on the given object
*
* @param object The object to mouse stretch
* @param strength The strength of the effect - Default: 0.5
* @param initialScale The initial scale of the object - Default: new Phaser.Point(1,1)
*/
mouseStretch(object: Phaser.Sprite, strength?: number, initialScale?: Phaser.Point): void;
/**
* Runs the core update function and causes screen shake and overscaling effects to occur if they are queued to do so.
*/
update(): void;
/**
* Begins the screen shake effect
*
* @param duration The duration of the screen shake - Default: 20
* @param strength The strength of the screen shake - Default: 20
*/
shake(duration?: number, strength?: number): void;
}
module Juicy {
/**
* Creates a new `Juicy.Trail` object.
*/
class Trail {
/**
* Creates a new `Juicy.Trail` object.
*
* @param game Current game instance.
* @param trailLength The length of the trail - Default: 100
* @param color The color of the trail - Default: 0xFFFFFF
*/
constructor(game: Phaser.Game, trailLength?: number, color?: number);
/**
* The target sprite whose movement we want to create the trail from
*/
target: Phaser.Sprite;
/**
* The number of segments to use to create the trail
*/
trailLength: number;
/**
* The width of the trail
*/
trailWidth: number;
/**
* Whether or not to taper the trail towards the end
*/
trailScaling: boolean;
/**
* The color of the trail
*/
trailColor: number;
/**
* Updates the Trail if a target is set
*/
update(): void;
/**
* Adds a segment to the segments list and culls the list if it is too long
*
* @param x The x position of the point
* @param y The y position of the point
*/
addSegment(x: number, y: number): void;
/**
* Creates and draws the triangle trail from segments
*
* @param offsetX The x position of the object
* @param offsetY The y position of the object
*/
redrawSegments(offsetX: number, offsetY: number): void;
}
/**
* Creates a new `Juicy.ScreenFlash` object.
*/
class ScreenFlash {
/**
* Creates a new `Juicy.ScreenFlash` object.
*
* @param game Current game instance.
* @param color The color to flash the screen. - Default: 'white'
*/
constructor(game: Phaser.Game, color?: string);
/**
* Flashes the screen
*
* @param maxAlpha The maximum alpha to flash the screen to - Default: 1
* @param duration The duration of the flash in milliseconds - Default: 100
*/
flash(maxAlpha?: number, duration?: number): void;
}
}
}
interface PluginConstructorOf {
new (...parameters: any[]): T;
}
/**
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
*/
class PluginManager implements IStateCycle {
/**
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* An array of all the plugins being managed by this PluginManager.
*/
plugins: Phaser.Plugin[];
/**
* Add a new Plugin into the PluginManager.
* The Plugin must have 2 properties: game and parent. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager.
*
* @param plugin The Plugin to add into the PluginManager. This can be a function or an existing object.
* @param args Additional arguments that will be passed to the Plugin.init method.
* @return The Plugin that was added to the manager.
*/
add(plugin: PluginConstructorOf, ...parameters: any[]): T;
/**
* Clear down this PluginManager, calls destroy on every plugin and nulls out references.
*/
destroy(): void;
/**
* Post-render is called after the Game Renderer and State.render have run.
* It only calls plugins who have visible=true.
*/
postRender(): void;
/**
* PostUpdate is the last thing to be called before the world render.
* In particular, it is called after the world postUpdate, which means the camera has been adjusted.
* It only calls plugins who have active=true.
*/
postUpdate(): void;
/**
* Pre-update is called at the very start of the update cycle, before any other subsystems have been updated (including Physics).
* It only calls plugins who have active=true.
*/
preUpdate(): void;
/**
* Remove a Plugin from the PluginManager. It calls Plugin.destroy on the plugin before removing it from the manager.
*
* @param plugin The plugin to be removed.
* @param destroy Call destroy on the plugin that is removed? - Default: true
*/
remove(plugin: Phaser.Plugin, destroy?: boolean): void;
/**
* Remove all Plugins from the PluginManager. It calls Plugin.destroy on every plugin before removing it from the manager.
*/
removeAll(): void;
/**
* Render is called right after the Game Renderer completes, but before the State.render.
* It only calls plugins who have visible=true.
*/
render(): void;
/**
* Update is called after all the core subsystems (Input, Tweens, Sound, etc) and the State have updated, but before the render.
* It only calls plugins who have active=true.
*/
update(): void;
}
/**
* A Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
* The following code creates a point at (0,0):
* `var myPoint = new Phaser.Point();`
* You can also use them as 2D Vectors and you'll find different vector related methods in this class.
*/
class Point extends PIXI.Point {
/**
* A Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
* The following code creates a point at (0,0):
* `var myPoint = new Phaser.Point();`
* You can also use them as 2D Vectors and you'll find different vector related methods in this class.
*
* @param x The horizontal position of this Point.
* @param y The vertical position of this Point.
*/
constructor(x?: number, y?: number);
/**
* The x value of the point.
*/
x: number;
/**
* The y value of the point.
*/
y: number;
/**
* The const type of this object.
*/
type: number;
/**
* Adds the given x and y values to this Point.
*
* @param x The value to add to Point.x.
* @param y The value to add to Point.y.
* @return This Point object. Useful for chaining method calls.
*/
static add(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Subtracts the given x and y values from this Point.
*
* @param x The value to subtract from Point.x.
* @param y The value to subtract from Point.y.
* @return This Point object. Useful for chaining method calls.
*/
static subtract(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Multiplies Point.x and Point.y by the given x and y values. Sometimes known as `Scale`.
*
* @param x The value to multiply Point.x by.
* @param y The value to multiply Point.x by.
* @return This Point object. Useful for chaining method calls.
*/
static multiply(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Divides Point.x and Point.y by the given x and y values.
*
* @param x The value to divide Point.x by.
* @param y The value to divide Point.x by.
* @return This Point object. Useful for chaining method calls.
*/
static divide(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Determines whether the given objects x/y values are equal to this Point object.
*
* @param a The object to compare with this Point.
* @return A value of true if the x and y points are equal, otherwise false.
*/
static equals(a: Phaser.Point, b: Phaser.Point): boolean;
/**
* 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.
*/
static angle(a: Phaser.Point, b: Phaser.Point): number;
static angleSq(a: Phaser.Point, b: Phaser.Point): number;
/**
* Creates a negative Point.
*
* @param a The first Point object.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static negative(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Adds two 2D Points together and multiplies the result by the given scalar.
*
* @param a The first Point object.
* @param b The second Point object.
* @param s The scaling value.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static multiplyAdd(a: Phaser.Point, b: Phaser.Point, scale: number, out?: Phaser.Point): Phaser.Point;
/**
* Interpolates the two given Points, based on the `f` value (between 0 and 1) and returns a new Point.
*
* @param a The first Point object.
* @param b The second Point object.
* @param f The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static interpolate(a: Phaser.Point, b: Phaser.Point, alpha: number, out?: Phaser.Point): Phaser.Point;
/**
* Parses an object for x and/or y properties and returns a new Phaser.Point with matching values.
* If the object doesn't contain those properties a Point with x/y of zero will be returned.
*
* @param obj The object to parse.
* @param xProp The property used to set the Point.x value. - Default: 'x'
* @param yProp The property used to set the Point.y value. - Default: 'y'
* @return The new Point object.
*/
static parse(obj: any, xProp?: string, yProp?: string): Phaser.Point;
/**
* Make this Point perpendicular (90 degrees rotation)
* @return This Point object.
*/
static perp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Make this Point perpendicular (-90 degrees rotation)
* @return This Point object.
*/
static rperp(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
*
* @param dest The target object. Must have visible x and y properties that represent the center of the object.
* @param round Round the distance to the nearest integer (default false).
* @return The distance between this Point object and the destination Point object.
*/
static distance(a: any, b: any, round?: boolean): number;
/**
* Project two Points onto another Point.
*
* @param a The first Point object.
* @param b The second Point object.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static project(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Project two Points onto a Point of unit length.
*
* @param a The first Point object.
* @param b The second Point object.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static projectUnit(a: Phaser.Point, b: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Right-hand normalize (make unit length) this Point.
* @return This Point object.
*/
static normalRightHand(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Alters the Point object so that its length is 1, but it retains the same direction.
* @return This Point object.
*/
static normalize(a: Phaser.Point, out?: Phaser.Point): Phaser.Point;
/**
* Rotates this Point around the x/y coordinates given to the desired angle.
*
* @param x The x coordinate of the anchor point.
* @param y The y coordinate of the anchor point.
* @param angle The angle in radians (unless asDegrees is true) to rotate the Point to.
* @param asDegrees Is the given angle in radians (false) or degrees (true)?
* @param distance An optional distance constraint between the Point and the anchor.
* @return The modified point object.
*/
static rotate(a: Phaser.Point, x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point;
/**
* Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned.
*
* @param points The array of one or more points.
* @param out Optional Point to store the value in, if not supplied a new Point object will be created.
* @return The new Point object.
*/
static centroid(points: Phaser.Point[], out?: Phaser.Point): Phaser.Point;
/**
* Tests a Point or Point-like object.
* @return - True if the object has numeric x and y properties.
*/
static isPoint(obj: object): boolean;
/**
* Sets the `x` and `y` values of this Point object to the given values.
* If you omit the `y` value then the `x` value will be applied to both, for example:
* `Point.set(2)` is the same as `Point.set(2, 2)`
*
* Identical to {@link Phaser.Point#setTo setTo}.
*
* @param x The horizontal value of this point.
* @param y The vertical value of this point. If not given the x value will be used in its place.
* @return This Point object. Useful for chaining method calls.
*/
static set(obj: object, x: number, y: number): object;
/**
* Adds the given x and y values to this Point.
*
* @param x The value to add to Point.x.
* @param y The value to add to Point.y.
* @return This Point object. Useful for chaining method calls.
*/
add(x: number, y: number): Phaser.Point;
/**
* Returns the angle between this Point object and another object with public x and y properties.
*
* @param a The object to get the angle from this Point to.
* @param asDegrees Is the given angle in radians (false) or degrees (true)?
* @return The angle between the two objects.
*/
angle(a: Phaser.Point, asDegrees?: boolean): number;
angleSq(a: Phaser.Point): number;
/**
* Clamps this Point object values to be between the given min and max.
*
* @param min The minimum value to clamp this Point to.
* @param max The maximum value to clamp this Point to.
* @return This Point object.
*/
clamp(min: number, max: number): Phaser.Point;
/**
* Clamps the x value of this Point to be between the given min and max.
*
* @param min The minimum value to clamp this Point to.
* @param max The maximum value to clamp this Point to.
* @return This Point object.
*/
clampX(min: number, max: number): Phaser.Point;
/**
* Clamps the y value of this Point to be between the given min and max
*
* @param min The minimum value to clamp this Point to.
* @param max The maximum value to clamp this Point to.
* @return This Point object.
*/
clampY(min: number, max: number): Phaser.Point;
/**
* Creates a copy of the given Point.
*
* @param output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
* @return The new Point object.
*/
clone(output?: Phaser.Point): Phaser.Point;
/**
* Copies the x and y properties from any given object to this Point.
*
* @param source The object to copy from.
* @return This Point object.
*/
copyFrom(source: Phaser.Point): Phaser.Point;
/**
* Copies the x and y properties from this Point to any given object.
*
* @param dest The object to copy to.
* @return The dest object.
*/
copyTo(dest: T): T;
/**
* Math.ceil() both the x and y properties of this Point.
* @return This Point object.
*/
ceil(): Phaser.Point;
/**
* The cross product of this and another Point object.
*
* @param a The Point object to get the cross product combined with this Point.
* @return The result.
*/
cross(a: Phaser.Point): number;
/**
* Divides Point.x and Point.y by the given x and y values.
*
* @param x The value to divide Point.x by.
* @param y The value to divide Point.x by.
* @return This Point object. Useful for chaining method calls.
*/
divide(x: number, y: number): Phaser.Point;
/**
* Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
*
* @param dest The target object. Must have visible x and y properties that represent the center of the object.
* @param round Round the distance to the nearest integer (default false).
* @return The distance between this Point object and the destination Point object.
*/
distance(dest: Phaser.Point, round?: boolean): number;
/**
* The dot product of this and another Point object.
*
* @param a The Point object to get the dot product combined with this Point.
* @return The result.
*/
dot(a: Phaser.Point): number;
/**
* Determines whether the given objects x/y values are equal to this Point object.
*
* @param a The object to compare with this Point.
* @return A value of true if the x and y points are equal, otherwise false.
*/
equals(a: Phaser.Point): boolean;
/**
* Math.floor() both the x and y properties of this Point.
* @return This Point object.
*/
floor(): Phaser.Point;
/**
* Calculates the length of the Point object.
* @return The length of the Point.
*/
getMagnitude(): number;
/**
* Calculates the length squared of the Point object.
* @return The length ^ 2 of the Point.
*/
getMagnitudeSq(): number;
/**
* Inverts the x and y values of this Point
* @return This Point object.
*/
invert(): Phaser.Point;
/**
* Determine if this point is at 0,0.
* @return True if this Point is 0,0, otherwise false.
*/
isZero(): boolean;
/**
* Multiplies Point.x and Point.y by the given x and y values. Sometimes known as `Scale`.
*
* @param x The value to multiply Point.x by.
* @param y The value to multiply Point.x by.
* @return This Point object. Useful for chaining method calls.
*/
multiply(x: number, y: number): Phaser.Point;
/**
* Alters the Point object so that its length is 1, but it retains the same direction.
* @return This Point object.
*/
normalize(): Phaser.Point;
/**
* Right-hand normalize (make unit length) this Point.
* @return This Point object.
*/
normalRightHand(): Phaser.Point;
/**
* Make this Point perpendicular (90 degrees rotation)
* @return This Point object.
*/
perp(): Phaser.Point;
/**
* Make this Point perpendicular (-90 degrees rotation)
* @return This Point object.
*/
rperp(): Phaser.Point;
/**
* Rotates this Point around the x/y coordinates given to the desired angle.
*
* @param x The x coordinate of the anchor point.
* @param y The y coordinate of the anchor point.
* @param angle The angle in radians (unless asDegrees is true) to rotate the Point to.
* @param asDegrees Is the given angle in radians (false) or degrees (true)?
* @param distance An optional distance constraint between the Point and the anchor.
* @return The modified point object.
*/
rotate(x: number, y: number, angle: number, asDegrees?: boolean, distance?: number): Phaser.Point;
/**
* Sets the `x` and `y` values of this Point object to the given values.
* If you omit the `y` value then the `x` value will be applied to both, for example:
* `Point.set(2)` is the same as `Point.set(2, 2)`
*
* Identical to {@link Phaser.Point#setTo setTo}.
*
* @param x The horizontal value of this point.
* @param y The vertical value of this point. If not given the x value will be used in its place.
* @return This Point object. Useful for chaining method calls.
*/
set(x: number, y?: number): Phaser.Point;
/**
* Alters the length of the Point without changing the direction.
*
* @param magnitude The desired magnitude of the resulting Point.
* @return This Point object.
*/
setMagnitude(magnitude: number): Phaser.Point;
/**
* Sets the `x` and `y` values of this Point object to the given values.
* If you omit the `y` value then the `x` value will be applied to both, for example:
* `Point.setTo(2)` is the same as `Point.setTo(2, 2)`
*
* Identical to {@link Phaser.Point#set set}.
*
* @param x The horizontal value of this point.
* @param y The vertical value of this point. If not given the x value will be used in its place.
* @return This Point object. Useful for chaining method calls.
*/
setTo(x: number, y?: number): Phaser.Point;
/**
* Sets the `x` and `y` values of this Point object from a given polar coordinate.
*
* @param azimuth The angular coordinate, in radians (unless `asDegrees`).
* @param radius The radial coordinate (length). - Default: 1
* @param asDegrees True if `azimuth` is in degrees.
* @return This Point object. Useful for chaining method calls.
*/
setToPolar(azimuth: number, radius?: number, asDegrees?: boolean): Phaser.Point;
/**
* Subtracts the given x and y values from this Point.
*
* @param x The value to subtract from Point.x.
* @param y The value to subtract from Point.y.
* @return This Point object. Useful for chaining method calls.
*/
subtract(x: number, y: number): Phaser.Point;
/**
* Returns a string representation of this object.
* @return A string representation of the instance.
*/
toString(): string;
}
/**
* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
*/
class Pointer {
/**
* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
*
* @param game A reference to the currently running game.
* @param id The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
* @param pointerMode The operational mode of this pointer, eg. CURSOR or TOUCH. - Default: (CURSOR|CONTACT)
*/
constructor(game: Phaser.Game, id: number, pointerMode?: number);
/**
* No buttons at all.
*/
static NO_BUTTON: number;
/**
* The Left Mouse button, or in PointerEvent devices a Touch contact or Pen contact.
*/
static LEFT_BUTTON: number;
/**
* The Right Mouse button, or in PointerEvent devices a Pen contact with a barrel button.
*/
static RIGHT_BUTTON: number;
/**
* The Middle Mouse button.
*/
static MIDDLE_BUTTON: number;
/**
* The X1 button. This is typically the mouse Back button, but is often reconfigured.
* On Linux (GTK) this is unsupported. On Windows if advanced pointer software (such as IntelliPoint) is installed this doesn't register.
*/
static BACK_BUTTON: number;
/**
* The X2 button. This is typically the mouse Forward button, but is often reconfigured.
* On Linux (GTK) this is unsupported. On Windows if advanced pointer software (such as IntelliPoint) is installed this doesn't register.
*/
static FORWARD_BUTTON: number;
/**
* The Eraser pen button on PointerEvent supported devices only.
*/
static ERASER_BUTTON: number;
/**
* An active pointer is one that is currently pressed down on the display. A Mouse is always active.
*/
active: boolean;
/**
* If this Pointer is a Mouse or Pen / Stylus then you can access its X1 (back) button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*
* Please see the DeviceButton docs for details on browser button limitations.
*/
backButton: Phaser.DeviceButton;
/**
* The button property of the most recent DOM event when this Pointer is started.
* You should not rely on this value for accurate button detection, instead use the Pointer properties
* `leftButton`, `rightButton`, `middleButton` and so on.
*/
button: any;
/**
* A Phaser.Circle that is centered on the x/y coordinates of this pointer, useful for hit detection.
* The Circle size is 44px (Apples recommended "finger tip" size).
*/
circle: Phaser.Circle;
/**
* The horizontal coordinate of the Pointer within the application's client area at which the event occurred (as opposed to the coordinates within the page).
*/
clientX: number;
/**
* The vertical coordinate of the Pointer within the application's client area at which the event occurred (as opposed to the coordinates within the page).
*/
clientY: number;
/**
* A dirty pointer needs to re-poll any interactive objects it may have been over, regardless if it has moved or not.
*/
dirty: boolean;
/**
* How long the Pointer has been depressed on the touchscreen or *any* of the mouse buttons have been held down.
* If not currently down it returns -1.
* If you need to test a specific mouse or pen button then access the buttons directly, i.e. `Pointer.rightButton.duration`.
*/
duration: number;
/**
* If this Pointer is a Pen / Stylus then you can access its eraser button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*
* Please see the DeviceButton docs for details on browser button limitations.
*/
eraserButton: Phaser.DeviceButton;
/**
* A Pointer object that exists is allowed to be checked for physics collisions and overlaps.
* Default: true
*/
exists: boolean;
forceOut: boolean;
/**
* If this Pointer is a Mouse or Pen / Stylus then you can access its X2 (forward) button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*
* Please see the DeviceButton docs for details on browser button limitations.
*/
forwardButton: Phaser.DeviceButton;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
justReleasePreventsOver: boolean | number;
/**
* The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
*/
id: number;
/**
* The identifier property of the Pointer as set by the DOM event when this Pointer is started.
*/
identifier: number;
/**
* This array is erased and re-populated every time this Pointer is updated. It contains references to all
* of the Game Objects that were considered as being valid for processing by this Pointer, this frame. To be
* valid they must have suitable a `priorityID`, be Input enabled, visible and actually have the Pointer over
* them. You can check the contents of this array in events such as `onInputDown`, but beware it is reset
* every frame.
* Default: []
*/
interactiveCandidates: Phaser.InputHandler[];
/**
* If the Pointer is touching the touchscreen, or *any* mouse or pen button is held down, isDown is set to true.
* If you need to check a specific mouse or pen button then use the button properties, i.e. Pointer.rightButton.isDown.
*/
isDown: boolean;
/**
* If the Pointer is a mouse or pen / stylus this is true, otherwise false.
*/
isMouse: boolean;
/**
* If the Pointer is not touching the touchscreen, or *all* mouse or pen buttons are up, isUp is set to true.
* If you need to check a specific mouse or pen button then use the button properties, i.e. Pointer.rightButton.isUp.
* Default: true
*/
isUp: boolean;
/**
* If this Pointer is a Mouse or Pen / Stylus then you can access its left button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*/
leftButton: Phaser.DeviceButton;
/**
* If this Pointer is a Mouse or Pen / Stylus then you can access its middle button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*
* Please see the DeviceButton docs for details on browser button limitations.
*/
middleButton: Phaser.DeviceButton;
/**
* The horizontal processed relative movement of the Pointer in pixels since last event.
*/
movementX: number;
/**
* The vertical processed relative movement of the Pointer in pixels since last event.
*/
movementY: number;
/**
* The number of milliseconds since the last click or touch event.
*/
msSinceLastClick: number;
/**
* The horizontal coordinate of the Pointer relative to whole document.
*/
pageX: number;
/**
* The vertical coordinate of the Pointer relative to whole document.
*/
pageY: number;
/**
* The pointerId property of the Pointer as set by the DOM event when this Pointer is started. The browser can and will recycle this value.
*/
pointerId: number;
/**
* The operational mode of this pointer.
*/
pointerMode: number;
/**
* A Phaser.Point object containing the current x/y values of the pointer on the display.
*/
position: Phaser.Point;
/**
* A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display.
*/
positionDown: Phaser.Point;
/**
* A Phaser.Point object containing the x/y values of the pointer when it was last released.
*/
positionUp: Phaser.Point;
/**
* A timestamp representing when the Pointer was last tapped or clicked.
*/
previousTapTime: number;
/**
* The horizontal raw relative movement of the Pointer in pixels since last event.
*/
rawMovementX: number;
/**
* The vertical raw relative movement of the Pointer in pixels since last event.
*/
rawMovementY: number;
/**
* If this Pointer is a Mouse or Pen / Stylus then you can access its right button directly through this property.
*
* The DeviceButton has its own properties such as `isDown`, `duration` and methods like `justReleased` for more fine-grained
* button control.
*
* Please see the DeviceButton docs for details on browser button limitations.
*/
rightButton: Phaser.DeviceButton;
/**
* The horizontal coordinate of the Pointer relative to the screen.
*/
screenX: number;
/**
* The vertical coordinate of the Pointer relative to the screen.
*/
screenY: number;
/**
* The target property of the Pointer as set by the DOM event when this Pointer is started.
*/
target: any;
/**
* The Game Object this Pointer is currently over / touching / dragging.
*/
targetObject: any;
/**
* A timestamp representing when the Pointer first touched the touchscreen.
*/
timeDown: number;
/**
* A timestamp representing when the Pointer left the touchscreen.
*/
timeUp: number;
/**
* The total number of times this Pointer has been touched to the touchscreen.
*/
totalTouches: number;
/**
* The const type of this object.
*/
type: number;
/**
* true if the Pointer is over the game canvas, otherwise false.
*/
withinGame: boolean;
/**
* Gets the X value of this Pointer in world coordinates based on the world camera.
*/
worldX: number;
/**
* Gets the Y value of this Pointer in world coordinates based on the world camera.
*/
worldY: number;
/**
* The horizontal coordinate of the Pointer. This value is automatically scaled based on the game scale.
*/
x: number;
/**
* The vertical coordinate of the Pointer. This value is automatically scaled based on the game scale.
*/
y: number;
/**
* Add a click trampoline to this pointer.
*
* A click trampoline is a callback that is run on the DOM 'click' event; this is primarily
* needed with certain browsers (ie. IE11) which restrict some actions like requestFullscreen
* to the DOM 'click' event and rejects it for 'pointer*' and 'mouse*' events.
*
* This is used internally by the ScaleManager; click trampoline usage is uncommon.
* Click trampolines can only be added to pointers that are currently down.
*
* @param name The name of the trampoline; must be unique among active trampolines in this pointer.
* @param callback Callback to run/trampoline.
* @param callbackContext Context of the callback.
* @param callbackArgs Additional callback args, if any. Supplied as an array.
*/
addClickTrampoline(name: string, callback: Function, callbackContext: any, ...callbackArgs: any[]): void;
/**
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate.
* Note that calling justPressed doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid.
* If you wish to check if the Pointer was pressed down just once then see the Sprite.events.onInputDown event.
*
* @param duration The time to check against. If none given it will use InputManager.justPressedRate.
* @return true if the Pointer was pressed down within the duration given.
*/
justPressed(duration?: number): boolean;
/**
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate.
* Note that calling justReleased doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid.
* If you wish to check if the Pointer was released just once then see the Sprite.events.onInputUp event.
*
* @param duration The time to check against. If none given it will use InputManager.justReleasedRate.
* @return true if the Pointer was released within the duration given.
*/
justReleased(duration?: number): boolean;
/**
* Called when the Pointer leaves the target area.
*
* @param event The event passed up from the input handler.
*/
leave(event: any): void;
/**
* Called when the Pointer is moved.
*
* @param event The event passed up from the input handler.
* @param fromClick Was this called from the click event?
*/
move(event: any, fromClick?: boolean): void;
/**
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
*/
reset(): void;
/**
* Resets the states of all the button booleans.
*/
resetButtons(): void;
/**
* Resets the movementX and movementY properties. Use in your update handler after retrieving the values.
*/
resetMovement(): void;
/**
* Called when the Pointer is pressed onto the touchscreen.
*
* @param event The DOM event from the browser.
*/
start(event: any): void;
/**
* Called when the Pointer leaves the touchscreen.
*
* @param event The event passed up from the input handler.
*/
stop(event: any): void;
/**
* This will change the `Pointer.targetObject` object to be the one provided.
*
* This allows you to have fine-grained control over which object the Pointer is targeting.
*
* Note that even if you set a new Target here, it is still able to be replaced by any other valid
* target during the next Pointer update.
*
* @param newTarget The new target for this Pointer. Note this is an `InputHandler`, so don't pass a Sprite, instead pass `sprite.input` to it.
* @param silent If true the new target AND the old one will NOT dispatch their `onInputOver` or `onInputOut` events.
*/
swapTarget(newTarget: Phaser.InputHandler, silent?: boolean): void;
/**
* Called by the Input Manager.
*/
update(): void;
/**
* Called when the event.buttons property changes from zero.
* Contains a button bitmask.
*
* @param event The DOM event.
*/
updateButtons(event: MouseEvent): void;
}
/**
* Creates a new Polygon.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*/
class Polygon {
/**
* Creates a new Polygon.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* @param points The points to set.
*/
constructor(points: Phaser.Point[] | number[]);
/**
* Creates a new Polygon.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* @param points The points to set.
*/
constructor(...points: Phaser.Point[]);
/**
* Creates a new Polygon.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* @param points The points to set.
*/
constructor(...points: number[]);
/**
* The area of this Polygon.
*/
area: number;
/**
* Has this Polygon been flattened by a call to `Polygon.flatten` ?
*/
flattened: boolean;
/**
* 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.
*/
points: number[] | Phaser.Point[];
/**
* The base object type.
*/
type: number;
/**
* Creates a copy of the given Polygon.
* This is a deep clone, the resulting copy contains new Phaser.Point objects
*
* @param output The polygon to update. If not specified a new polygon will be created. - Default: (new Polygon)
* @return The cloned (`output`) polygon object.
*/
clone(output: Phaser.Polygon): Phaser.Polygon;
/**
* Checks whether the x and y coordinates are contained within this polygon.
*
* @param x The X value of the coordinate to test.
* @param y The Y value of the coordinate to test.
* @return True if the coordinates are within this polygon, otherwise false.
*/
contains(x: number, y: number): boolean;
/**
* Flattens this Polygon so the points are a sequence of numbers.
* Any Point objects found are removed and replaced with two numbers.
* Also sets the Polygon.flattened property to `true`.
* @return This Polygon object
*/
flatten(): Phaser.Polygon;
/**
* Sets this Polygon to the given points.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* `setTo` may also be called without any arguments to remove all points.
*
* @param points The points to set.
* @return This Polygon object
*/
setTo(points: Phaser.Point[] | number[]): void;
/**
* Sets this Polygon to the given points.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* `setTo` may also be called without any arguments to remove all points.
*
* @param points The points to set.
* @return This Polygon object
*/
setTo(...points: Phaser.Point[]): void;
/**
* Sets this Polygon to the given points.
*
* The points can be set from a variety of formats:
*
* - An array of Point objects: `[new Phaser.Point(x1, y1), ...]`
* - An array of objects with public x/y properties: `[obj1, obj2, ...]`
* - An array of paired numbers that represent point coordinates: `[x1,y1, x2,y2, ...]`
* - An array of arrays with two elements representing x/y coordinates: `[[x1, y1], [x2, y2], ...]`
* - As separate Point arguments: `setTo(new Phaser.Point(x1, y1), ...)`
* - As separate objects with public x/y properties arguments: `setTo(obj1, obj2, ...)`
* - As separate arguments representing point coordinates: `setTo(x1,y1, x2,y2, ...)`
*
* `setTo` may also be called without any arguments to remove all points.
*
* @param points The points to set.
* @return This Polygon object
*/
setTo(...points: number[]): void;
/**
* Export the points as an array of flat numbers, following the sequence [ x,y, x,y, x,y ]
*
* @param output The array to append the points to. If not specified a new array will be created.
* @return The flattened array.
*/
toNumberArray(output?: number[]): number[];
}
/**
* A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts.
* However I've tweaked it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result.
* Original version at https://github.com/timohausmann/quadtree-js/
*/
class QuadTree {
/**
* A QuadTree implementation. The original code was a conversion of the Java code posted to GameDevTuts.
* However I've tweaked it massively to add node indexing, removed lots of temp. var creation and significantly increased performance as a result.
* Original version at https://github.com/timohausmann/quadtree-js/
*
* @param x The top left coordinate of the quadtree.
* @param y The top left coordinate of the quadtree.
* @param width The width of the quadtree in pixels.
* @param height The height of the quadtree in pixels.
* @param maxObjects The maximum number of objects per node. - Default: 10
* @param maxLevels The maximum number of levels to iterate to. - Default: 4
* @param level Which level is this?
*/
constructor(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number);
/**
* Object that contains the quadtree bounds.
*/
bounds: {
x: number;
y: number;
width: number;
height: number;
subWidth: number;
subHeight: number;
right: number;
bottom: number;
};
/**
* The current level.
*/
level: number;
/**
* The maximum number of objects per node.
* Default: 10
*/
maxObjects: number;
/**
* The maximum number of levels to break down to.
* Default: 4
*/
maxLevels: number;
/**
* Array of quadtree children.
*/
objects: any[];
/**
* Array of associated child nodes.
*/
nodes: any[];
/**
* Clear the quadtree.
*/
clear(): void;
/**
* Determine which node the object belongs to.
*
* @param rect The bounds in which to check.
* @return index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node.
*/
getIndex(rect: any): number;
/**
* Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.
*
* @param body The Body object to insert into the quadtree. Can be any object so long as it exposes x, y, right and bottom properties.
*/
insert(body: any): void;
/**
* Populates this quadtree with the children of the given Group. In order to be added the child must exist and have a body property.
*
* @param group The Group to add to the quadtree.
*/
populate(group: Phaser.Group): void;
/**
* Handler for the populate method.
*
* @param sprite The Sprite to check.
*/
populateHandler(sprite: Phaser.Sprite): void;
/**
* Resets the QuadTree.
*
* @param x The top left coordinate of the quadtree.
* @param y The top left coordinate of the quadtree.
* @param width The width of the quadtree in pixels.
* @param height The height of the quadtree in pixels.
* @param maxObjects The maximum number of objects per node. - Default: 10
* @param maxLevels The maximum number of levels to iterate to. - Default: 4
* @param level Which level is this?
*/
reset(x: number, y: number, width: number, height: number, maxObject?: number, maxLevels?: number, level?: number): void;
/**
* Return all objects that could collide with the given Sprite or Rectangle.
*
* @param source The source object to check the QuadTree against. Either a Sprite or Rectangle.
* @return - Array with all detected objects.
*/
retrieve(source: any): any[];
/**
* Split the node into 4 subnodes
*/
split(): void;
}
/**
* An extremely useful repeatable random data generator.
*
* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense.
*
* The random number genererator is based on the Alea PRNG, but is modified.
* - https://github.com/coverslide/node-alea
* - https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
* - http://baagoe.org/en/wiki/Better_random_numbers_for_javascript (original, perm. 404)
*/
class RandomDataGenerator {
/**
* An extremely useful repeatable random data generator.
*
* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense.
*
* The random number genererator is based on the Alea PRNG, but is modified.
* - https://github.com/coverslide/node-alea
* - https://github.com/nquinlan/better-random-numbers-for-javascript-mirror
* - http://baagoe.org/en/wiki/Better_random_numbers_for_javascript (original, perm. 404)
*
* @param seeds An array of values to use as the seed, or a generator state (from {#state}).
*/
constructor(seeds?: any[] | string);
/**
* Returns a random angle between -180 and 180.
* @return A random number between -180 and 180.
*/
angle(): number;
/**
* Returns a random integer between and including min and max.
* This method is an alias for RandomDataGenerator.integerInRange.
*
* @param min The minimum value in the range.
* @param max The maximum value in the range.
* @return A random number between min and max.
*/
between(min: number, max: number): number;
/**
* Returns a random real number between 0 and 1.
* @return A random real number between 0 and 1.
*/
frac(): number;
/**
* Returns a random integer between 0 and 2^32.
* @return A random integer between 0 and 2^32.
*/
integer(): number;
/**
* Returns a random integer between and including min and max.
*
* @param min The minimum value in the range.
* @param max The maximum value in the range.
* @return A random number between min and max.
*/
integerInRange(min: number, max: number): number;
/**
* Returns a random real number between -1 and 1.
* @return A random real number between -1 and 1.
*/
normal(): number;
/**
* Returns a random member of `array`.
*
* @param ary An Array to pick a random member of.
* @return A random member of the array.
*/
pick(ary: T[]): T;
/**
* Returns a random real number between 0 and 2^32.
* @return A random real number between 0 and 2^32.
*/
real(): number;
/**
* Returns a random real number between min and max.
*
* @param min The minimum value in the range.
* @param max The maximum value in the range.
* @return A random number between min and max.
*/
realInRange(min: number, max: number): number;
/**
* Returns a sign to be used with multiplication operator.
* @return -1 or +1.
*/
sign(): number;
/**
* Reset the seed of the random data generator.
*
* _Note_: the seed array is only processed up to the first `undefined` (or `null`) value, should such be present.
*
* @param seeds The array of seeds: the `toString()` of each value is used.
*/
sow(seeds: any[]): void;
/**
* Gets or Sets the state of the generator. This allows you to retain the values
* that the generator is using between games, i.e. in a game save file.
*
* To seed this generator with a previously saved state you can pass it as the
* `seed` value in your game config, or call this method directly after Phaser has booted.
*
* Call this method with no parameters to return the current state.
*
* If providing a state it should match the same format that this method
* returns, which is a string with a header `!rnd` followed by the `c`,
* `s0`, `s1` and `s2` values respectively, each comma-delimited.
*
* @param state Generator state to be set.
* @return The current state of the generator.
*/
state(state?: string): string;
/**
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified.
*
* @param min The minimum value in the range.
* @param max The maximum value in the range.
* @return A random timestamp between min and max.
*/
timestamp(min: number, max: number): number;
/**
* Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368
* @return A valid RFC4122 version4 ID hex string
*/
uuid(): string;
/**
* Returns a random member of `array`, favoring the earlier entries.
*
* @param ary An Array to pick a random member of.
* @return A random member of the array.
*/
weightedPick(ary: T[]): T;
}
/**
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.
* If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
*/
class Rectangle {
/**
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.
* If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
*
* @param x The x coordinate of the top-left corner of the Rectangle.
* @param y The y coordinate of the top-left corner of the Rectangle.
* @param width The width of the Rectangle. Should always be either zero or a positive value.
* @param height The height of the Rectangle. Should always be either zero or a positive value.
*/
constructor(x: number, y: number, width: number, height: number);
/**
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
*/
bottom: number;
/**
* The location of the Rectangles bottom right corner as a Point object. Gets or sets the location of the Rectangles bottom right corner as a Point object.
*/
bottomRight: Phaser.Point;
/**
* The location of the Rectangles bottom left corner as a Point object. Gets or sets the location of the Rectangles bottom left corner as a Point object.
*/
bottomLeft: Phaser.Point;
/**
* The x coordinate of the center of the Rectangle.
*/
centerX: number;
/**
* The y coordinate of the center of the Rectangle.
*/
centerY: number;
/**
* Determines whether or not this Rectangle object is empty. A Rectangle object is empty if its width or height is less than or equal to 0.
* If set to true then all of the Rectangle properties are set to 0. Gets or sets the Rectangles empty state.
*/
empty: boolean;
/**
* Half of the height of the Rectangle.
*/
halfHeight: number;
/**
* Half of the width of the Rectangle.
*/
halfWidth: number;
/**
* The height of the Rectangle. This value should never be set to a negative.
*/
height: number;
/**
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
*/
left: number;
/**
* The perimeter size of the Rectangle. This is the sum of all 4 sides.
*/
perimeter: number;
/**
* A random value between the left and right values (inclusive) of the Rectangle.
*/
randomX: number;
/**
* A random value between the top and bottom values (inclusive) of the Rectangle.
*/
randomY: number;
/**
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties, however it does affect the width property.
*/
right: number;
/**
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
* However it does affect the height property, whereas changing the y value does not affect the height property.
*/
top: number;
/**
* The location of the Rectangles top left corner as a Point object.
*/
topLeft: Phaser.Point;
/**
* The location of the Rectangles top right corner as a Point object. The location of the Rectangles top left corner as a Point object.
*/
topRight: Phaser.Point;
/**
* The const type of this object.
*/
type: number;
/**
* The volume of the Rectangle derived from width * height.
*/
volume: number;
/**
* The width of the Rectangle. This value should never be set to a negative.
*/
width: number;
/**
* The x coordinate of the top-left corner of the Rectangle.
*/
x: number;
/**
* The y coordinate of the top-left corner of the Rectangle.
*/
y: number;
/**
* Calculates the Axis Aligned Bounding Box (or aabb) from an array of points.
*
* @param points The array of one or more points.
* @param out Optional Rectangle to store the value in, if not supplied a new Rectangle object will be created.
* @return The new Rectangle object.
*/
static aabb(points: Phaser.Point[], out?: Phaser.Rectangle): Phaser.Rectangle;
/**
* Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
*
* @param output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
*/
static clone(a: Phaser.Rectangle, output?: Phaser.Rectangle): Phaser.Rectangle;
/**
* Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
*
* @param x The x coordinate of the point to test.
* @param y The y coordinate of the point to test.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
static contains(a: Phaser.Rectangle, x: number, y: number): boolean;
/**
* Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
*
* @param a The Rectangle object.
* @param point The point object being checked. Can be Point or any object with .x and .y values.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
static containsPoint(a: Phaser.Rectangle, point: Phaser.Point): boolean;
/**
* Determines whether the specified coordinates are contained within the region defined by the given raw values.
*
* @param rx The x coordinate of the top left of the area.
* @param ry The y coordinate of the top left of the area.
* @param rw The width of the area.
* @param rh The height of the area.
* @param x The x coordinate of the point to test.
* @param y The y coordinate of the point to test.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
static containsRaw(rx: number, ry: number, rw: number, rh: number, x: number, y: number): boolean;
/**
* Determines whether the first Rectangle object is fully contained within the second Rectangle object.
* A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
*
* @param b The second Rectangle object.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
static containsRect(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
/**
* Determines whether the two Rectangles are equal.
* This method compares the x, y, width and height properties of each Rectangle.
*
* @param b The second Rectangle object.
* @return A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
*/
static equals(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
/**
* Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
*
* @param dx The amount to be added to the left side of the Rectangle.
* @param dy The amount to be added to the bottom side of the Rectangle.
* @return This Rectangle object.
*/
static inflate(a: Phaser.Rectangle, dx: number, dy: number): Phaser.Rectangle;
/**
* Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
*
* @param a The Rectangle object.
* @param point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
* @return The Rectangle object.
*/
static inflatePoint(a: Phaser.Rectangle, point: Phaser.Point): Phaser.Rectangle;
/**
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
*
* @param b The second Rectangle object.
* @param out Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
*/
static intersection(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
/**
* Determines whether this Rectangle and another given Rectangle intersect with each other.
* This method checks the x, y, width, and height properties of the two Rectangles.
*
* @param b The second Rectangle object.
* @return A value of true if the specified object intersects with this Rectangle object; otherwise false.
*/
static intersects(a: Phaser.Rectangle, b: Phaser.Rectangle): boolean;
/**
* Determines whether the coordinates given intersects (overlaps) with this Rectangle.
*
* @param left The x coordinate of the left of the area.
* @param right The right coordinate of the area.
* @param top The y coordinate of the area.
* @param bottom The bottom coordinate of the area.
* @param tolerance A tolerance value to allow for an intersection test with padding, default to 0
* @return A value of true if the specified object intersects with the Rectangle; otherwise false.
*/
static intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean;
/**
* The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
*
* @param output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
* @return The size of the Rectangle object.
*/
static size(a: Phaser.Rectangle, output?: Phaser.Point): Phaser.Point;
/**
* Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
*
* @param b The second Rectangle object.
* @param out Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return A Rectangle object that is the union of the two Rectangles.
*/
static union(a: Phaser.Rectangle, b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
/**
* Runs Math.ceil() on both the x and y values of this Rectangle.
*/
ceil(): void;
/**
* Runs Math.ceil() on the x, y, width and height values of this Rectangle.
*/
ceilAll(): void;
/**
* Centers this Rectangle so that the center coordinates match the given x and y values.
*
* @param x The x coordinate to place the center of the Rectangle at.
* @param y The y coordinate to place the center of the Rectangle at.
* @return This Rectangle object
*/
centerOn(x: number, y: number): Phaser.Rectangle;
/**
* Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
*
* @param output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
*/
clone(output: Phaser.Rectangle): Phaser.Rectangle;
/**
* Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
*
* @param x The x coordinate of the point to test.
* @param y The y coordinate of the point to test.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
contains(x: number, y: number): boolean;
/**
* Determines whether the first Rectangle object is fully contained within the second Rectangle object.
* A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
*
* @param b The second Rectangle object.
* @return A value of true if the Rectangle object contains the specified point; otherwise false.
*/
containsRect(b: Phaser.Rectangle): boolean;
/**
* Copies the x, y, width and height properties from any given object to this Rectangle.
*
* @param source The object to copy from.
* @return This Rectangle object.
*/
copyFrom(source: any): Phaser.Rectangle;
/**
* Copies the x, y, width and height properties from this Rectangle to any given object.
*
* @param source The object to copy to.
* @return This object.
*/
copyTo(dest: any): any;
/**
* Determines whether the two Rectangles are equal.
* This method compares the x, y, width and height properties of each Rectangle.
*
* @param b The second Rectangle object.
* @return A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false.
*/
equals(b: Phaser.Rectangle): boolean;
/**
* Runs Math.floor() on both the x and y values of this Rectangle.
*/
floor(): void;
/**
* Runs Math.floor() on the x, y, width and height values of this Rectangle.
*/
floorAll(): void;
/**
* Returns a point based on the given position constant, which can be one of:
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
* and `Phaser.BOTTOM_RIGHT`.
*
* This method returns the same values as calling Rectangle.bottomLeft, etc, but those
* calls always create a new Point object, where-as this one allows you to use your own.
*
* @param position One of the Phaser position constants, such as `Phaser.TOP_RIGHT`.
* @param out A Phaser.Point that the values will be set in.
* If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
* @return An object containing the point in its `x` and `y` properties.
*/
getPoint(position: number, out: Phaser.Point): Phaser.Point;
/**
* Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
*
* @param dx The amount to be added to the left side of the Rectangle.
* @param dy The amount to be added to the bottom side of the Rectangle.
* @return This Rectangle object.
*/
inflate(dx: number, dy: number): Phaser.Rectangle;
/**
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
*
* @param b The second Rectangle object.
* @param out Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
*/
intersection(b: Phaser.Rectangle, out: Phaser.Rectangle): Phaser.Rectangle;
/**
* Determines whether this Rectangle and another given Rectangle intersect with each other.
* This method checks the x, y, width, and height properties of the two Rectangles.
*
* @param b The second Rectangle object.
* @return A value of true if the specified object intersects with this Rectangle object; otherwise false.
*/
intersects(b: Phaser.Rectangle, tolerance: number): boolean;
/**
* Determines whether the coordinates given intersects (overlaps) with this Rectangle.
*
* @param left The x coordinate of the left of the area.
* @param right The right coordinate of the area.
* @param top The y coordinate of the area.
* @param bottom The bottom coordinate of the area.
* @param tolerance A tolerance value to allow for an intersection test with padding, default to 0
* @return A value of true if the specified object intersects with the Rectangle; otherwise false.
*/
intersectsRaw(left: number, right: number, top: number, bottom: number, tolerance: number): boolean;
/**
* Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
*
* @param dx Moves the x value of the Rectangle object by this amount.
* @param dy Moves the y value of the Rectangle object by this amount.
* @return This Rectangle object.
*/
offset(dx: number, dy: number): Phaser.Rectangle;
/**
* Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
*
* @param point A Point object to use to offset this Rectangle object.
* @return This Rectangle object.
*/
offsetPoint(point: Phaser.Point): Phaser.Rectangle;
/**
* Returns a uniformly distributed random point from anywhere within this Rectangle.
*
* @param out A Phaser.Point, or any object with public x/y properties, that the values will be set in.
* If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
* @return An object containing the random point in its `x` and `y` properties.
*/
random(out?: Phaser.Point): Phaser.Point;
/**
* Resize the Rectangle by providing a new width and height.
* The x and y positions remain unchanged.
*
* @param width The width of the Rectangle. Should always be either zero or a positive value.
* @param height The height of the Rectangle. Should always be either zero or a positive value.
* @return This Rectangle object
*/
resize(width: number, height: number): Phaser.Rectangle;
/**
* Sets the members of Rectangle to the specified values.
*
* @param x The x coordinate of the top-left corner of the Rectangle.
* @param y The y coordinate of the top-left corner of the Rectangle.
* @param width The width of the Rectangle. Should always be either zero or a positive value.
* @param height The height of the Rectangle. Should always be either zero or a positive value.
* @return This Rectangle object
*/
setTo(x: number, y: number, width: number, height: number): Phaser.Rectangle;
/**
* Scales the width and height of this Rectangle by the given amounts.
*
* @param x The amount to scale the width of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the width, etc.
* @param y The amount to scale the height of the Rectangle by. A value of 0.5 would reduce by half, a value of 2 would double the height, etc.
* @return This Rectangle object
*/
scale(x: number, y?: number): Phaser.Rectangle;
/**
* The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
*
* @param output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
* @return The size of the Rectangle object.
*/
size(output?: Phaser.Point): Phaser.Point;
/**
* Returns a string representation of this object.
* @return A string representation of the instance.
*/
toString(): string;
/**
* Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles.
*
* @param b The second Rectangle object.
* @param out Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
* @return A Rectangle object that is the union of the two Rectangles.
*/
union(b: Phaser.Rectangle, out?: Phaser.Rectangle): Phaser.Rectangle;
}
/**
* A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and
* render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time.
*/
class RenderTexture extends PIXI.Texture {
/**
* A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and
* render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time.
*
* @param game Current game instance.
* @param width The width of the render texture. - Default: 100
* @param height The height of the render texture. - Default: 100
* @param key The key of the RenderTexture in the Cache, if stored there. - Default: ''
* @param scaleMode One of the Phaser.scaleModes consts. - Default: Phaser.scaleModes.DEFAULT
* @param resolution The resolution of the texture being generated. - Default: 1
*/
constructor(game: Phaser.Game, width?: number, height?: number, key?: string, scaleMode?: number, resolution?: number);
/**
* This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
* irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases)
*/
crop: PIXI.Rectangle;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* The key of the RenderTexture in the Cache, if stored there.
*/
key: string;
/**
* Base Phaser object type.
*/
type: number;
/**
* This function will draw the display object to the RenderTexture.
*
* In versions of Phaser prior to 2.4.0 the second parameter was a Phaser.Point object.
* This is now a Matrix allowing you much more control over how the Display Object is rendered.
* If you need to replicate the earlier behavior please use Phaser.RenderTexture.renderXY instead.
*
* If you wish for the displayObject to be rendered taking its current scale, rotation and translation into account then either
* pass `null`, leave it undefined or pass `displayObject.worldTransform` as the matrix value.
*
* @param displayObject The display object to render to this texture.
* @param matrix Optional matrix to apply to the display object before rendering. If null or undefined it will use the worldTransform matrix of the given display object.
* @param clear If true the texture will be cleared before the display object is drawn.
*/
render(displayObject: PIXI.DisplayObject, matrix?: Phaser.Matrix, clear?: boolean): void;
/**
* This function will draw the display object to the RenderTexture at the given coordinates.
*
* When the display object is drawn it takes into account scale and rotation.
*
* If you don't want those then use RenderTexture.renderRawXY instead.
*
* @param displayObject The display object to render to this texture.
* @param x The x position to render the object at.
* @param y The y position to render the object at.
* @param clear If true the texture will be cleared before the display object is drawn.
*/
renderXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void;
/**
* This function will draw the display object to the RenderTexture at the given coordinates.
*
* When the display object is drawn it doesn't take into account scale, rotation or translation.
*
* If you need those then use RenderTexture.renderXY instead.
*
* @param displayObject The display object to render to this texture.
* @param x The x position to render the object at.
* @param y The y position to render the object at.
* @param clear If true the texture will be cleared before the display object is drawn.
*/
renderRawXY(displayObject: PIXI.DisplayObject, x: number, y: number, clear?: boolean): void;
}
/**
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
*/
class RequestAnimationFrame {
/**
* Abstracts away the use of RAF or setTimeOut for the core game update loop.
*
* @param game A reference to the currently running game.
* @param forceSetTimeOut Tell Phaser to use setTimeOut even if raf is available.
*/
constructor(game: Phaser.Game, forceSetTimeOut?: boolean);
/**
* Tell Phaser to use setTimeOut even if raf is available.
*/
forceSetTimeOut: boolean;
/**
* The currently running game.
*/
game: Phaser.Game;
/**
* true if RequestAnimationFrame is running, otherwise false.
*/
isRunning: boolean;
/**
* Is the browser using requestAnimationFrame?
*/
isRAF(): boolean;
/**
* Is the browser using setTimeout?
*/
isSetTimeOut(): boolean;
/**
* Starts the requestAnimationFrame running or setTimeout if unavailable in browser
*/
start(): boolean;
/**
* Stops the requestAnimationFrame from running.
*/
stop(): void;
/**
* The update method for the requestAnimationFrame
*/
updateRAF(rafTime: number): void;
/**
* The update method for the setTimeout.
*/
updateSetTimeout(time: number): void;
}
/**
* A Retro Font is similar to a BitmapFont, in that it uses a texture to render the text. However unlike a BitmapFont every character in a RetroFont
* is the same size. This makes it similar to a sprite sheet. You typically find font sheets like this from old 8/16-bit games and demos.
*/
class RetroFont extends Phaser.RenderTexture {
/**
* A Retro Font is similar to a BitmapFont, in that it uses a texture to render the text. However unlike a BitmapFont every character in a RetroFont
* is the same size. This makes it similar to a sprite sheet. You typically find font sheets like this from old 8/16-bit games and demos.
*
* @param game Current game instance.
* @param key The font set graphic set as stored in the Game.Cache.
* @param characterWidth The width of each character in the font set.
* @param characterHeight The height of each character in the font set.
* @param chars The characters used in the font set, in display order. You can use the TEXT_SET consts for common font set arrangements.
* @param charsPerRow The number of characters per row in the font set. If not given charsPerRow will be the image width / characterWidth.
* @param xSpacing If the characters in the font set have horizontal spacing between them set the required amount here.
* @param ySpacing If the characters in the font set have vertical spacing between them set the required amount here.
* @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
* @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
*/
constructor(game: Phaser.Game, key: string, characterWidth: number, characterHeight: number, chars: string, charsPerRow?: number, xSpacing?: number, ySpacing?: number, xOffset?: number, yOffset?: number);
/**
* Align each line of multi-line text in the center.
*/
static ALIGN_CENTER: string;
/**
* Align each line of multi-line text to the left.
*/
static ALIGN_LEFT: string;
/**
* Align each line of multi-line text to the right.
*/
static ALIGN_RIGHT: string;
/**
* Text Set 1 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
*/
static TEXT_SET1: string;
/**
* Text Set 2 = !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
static TEXT_SET2: string;
/**
* Text Set 3 = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
*/
static TEXT_SET3: string;
/**
* Text Set 4 = ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789
*/
static TEXT_SET4: string;
/**
* Text Set 5 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,/() '!?-*:0123456789
*/
static TEXT_SET5: string;
/**
* Text Set 6 = ABCDEFGHIJKLMNOPQRSTUVWXYZ!?:;0123456789"(),-.'
*/
static TEXT_SET6: string;
/**
* Text Set 7 = AGMSY+:4BHNTZ!;5CIOU.?06DJPV,(17EKQW")28FLRX-'39
*/
static TEXT_SET7: string;
/**
* Text Set 8 = 0123456789 .ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
static TEXT_SET8: string;
/**
* Text Set 9 = ABCDEFGHIJKLMNOPQRSTUVWXYZ()-0123456789.:,'"?!
*/
static TEXT_SET9: string;
/**
* Text Set 10 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
*/
static TEXT_SET10: string;
/**
* Text Set 11 = ABCDEFGHIJKLMNOPQRSTUVWXYZ.,"-+!?()':;0123456789
*/
static TEXT_SET11: string;
/**
* Alignment of the text when multiLine = true or a fixedWidth is set. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER.
*/
align: string;
/**
* Automatically convert any text to upper case. Lots of old bitmap fonts only contain upper-case characters, so the default is true.
* Default: true
*/
autoUpperCase: boolean;
/**
* The height of each character in the font set.
*/
characterHeight: number;
/**
* The number of characters per row in the font set.
*/
characterPerRow: number;
/**
* If the characters in the font set have horizontal spacing between them set the required amount here.
*/
characterSpacingX: number;
/**
* If the characters in the font set have vertical spacing between them set the required amount here.
*/
characterSpacingY: number;
/**
* The width of each character in the font set.
*/
characterWidth: number;
/**
* Adds horizontal spacing between each character of the font, in pixels.
*/
customSpacingX: number;
/**
* Adds vertical spacing between each line of multi-line text, set in pixels.
*/
customSpacingY: number;
/**
* If you need this RetroFont image to have a fixed width you can set the width in this value.
* If text is wider than the width specified it will be cropped off.
*/
fixedWidth: number;
/**
* A reference to the image stored in the Game.Cache that contains the font.
*/
fontSet: Image;
/**
* The FrameData representing this Retro Font.
*/
frameData: Phaser.FrameData;
/**
* If set to true all carriage-returns in text will form new lines (see align). If false the font will only contain one single line of text (the default)
*/
multiLine: boolean;
/**
* If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
*/
offsetX: number;
/**
* If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
*/
offsetY: number;
/**
* Sets if the stamp is smoothed or not.
*/
smoothed: boolean;
/**
* The image that is stamped to the RenderTexture for each character in the font.
*/
stamp: Phaser.Image;
/**
* Set this value to update the text in this sprite. Carriage returns are automatically stripped out if multiLine is false. Text is converted to upper case if autoUpperCase is true.
*/
text: string;
/**
* Updates the texture with the new text.
*/
buildRetroFontText(): void;
/**
* Works out the longest line of text in _text and returns its length
* @return The length of the longest line of text.
*/
getLongestLine(): number;
/**
* Internal function that takes a single line of text (2nd parameter) and pastes it into the BitmapData at the given coordinates.
* Used by getLine and getMultiLine
*
* @param line The single line of text to paste.
* @param x The x coordinate.
* @param y The y coordinate.
* @param customSpacingX Custom X spacing.
*/
pasteLine(line: string, x: number, y: number, customSpacingX: number): void;
/**
* Internal helper function that removes all unsupported characters from the _text String, leaving only characters contained in the font set.
*
* @param stripCR Should it strip carriage returns as well? - Default: true
* @return A clean version of the string.
*/
removeUnsupportedCharacters(stripCR?: boolean): string;
/**
* If you need this RetroFont to have a fixed width and custom alignment you can set the width here.
* If text is wider than the width specified it will be cropped off.
*
* @param width Width in pixels of this RetroFont. Set to zero to disable and re-enable automatic resizing.
* @param lineAlignment Align the text within this width. Set to RetroFont.ALIGN_LEFT (default), RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. - Default: 'left'
*/
setFixedWidth(width: number, lineAlignment?: string): void;
/**
* A helper function that quickly sets lots of variables at once, and then updates the text.
*
* @param content The text of this sprite.
* @param multiLine Set to true if you want to support carriage-returns in the text and create a multi-line sprite instead of a single line.
* @param characterSpacing To add horizontal spacing between each character specify the amount in pixels.
* @param lineSpacing To add vertical spacing between each line of text, set the amount in pixels.
* @param lineAlignment Align each line of multi-line text. Set to RetroFont.ALIGN_LEFT, RetroFont.ALIGN_RIGHT or RetroFont.ALIGN_CENTER. - Default: 'left'
* @param allowLowerCase Lots of bitmap font sets only include upper-case characters, if yours needs to support lower case then set this to true.
*/
setText(content: string, multiLine?: boolean, characterSpacing?: number, lineSpacing?: number, lineAlignment?: string, allowLowerCase?: boolean): void;
/**
* Updates the x and/or y offset that the font is rendered from. This updates all of the texture frames, so be careful how often it is called.
* Note that the values given for the x and y properties are either ADDED to or SUBTRACTED from (if negative) the existing offsetX/Y values of the characters.
* So if the current offsetY is 8 and you want it to start rendering from y16 you would call updateOffset(0, 8) to add 8 to the current y offset.
*
* @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here.
* @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here.
*/
updateOffset(x?: number, y?: number): void;
}
/**
* A Rope is a Sprite that has a repeating texture.
*
* The texture will automatically wrap on the edges as it moves.
*
* Please note that Ropes cannot have an input handler.
*/
class Rope extends PIXI.Rope {
/**
* A Rope is a Sprite that has a repeating texture.
*
* The texture will automatically wrap on the edges as it moves.
*
* Please note that Ropes cannot have an input handler.
*
* @param game A reference to the currently running game.
* @param x The x coordinate (in world space) to position the Rope at.
* @param y The y coordinate (in world space) to position the Rope at.
* @param key This is the image or texture used by the Rope during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
* @param frame If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
* @param points An array of {Phaser.Point}.
*/
constructor(game: Phaser.Game, x: number, y: number, key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video, frame?: string | number, points?: Phaser.Point[]);
/**
* The angle property is the rotation of the Game Object in *degrees* from its original orientation.
*
* Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
*
* Values outside this range are added to or subtracted from 360 to obtain a value within the range.
* For example, the statement player.angle = 450 is the same as player.angle = 90.
*
* If you wish to work in radians instead of degrees you can use the property `rotation` instead.
* Working in radians is slightly faster as it doesn't have to perform any calculations.
*/
angle: number;
/**
* If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance.
* Through it you can create, play, pause and stop animations.
*/
animations: Phaser.AnimationManager;
/**
* A useful flag to control if the Game Object is alive or dead.
*
* This is set automatically by the Health components `damage` method should the object run out of health.
* Or you can toggle it via your game code.
*
* This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates.
* However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling.
* Default: true
*/
alive: boolean;
/**
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
autoCull: boolean;
/**
* `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated
* properties and methods via it.
*
* By default Game Objects won't add themselves to any physics system and their `body` property will be `null`.
*
* To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object
* and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`.
*
* You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group.
*
* Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5,
* so the physics body is centered on the Game Object.
*
* If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics.
*/
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
bottom: number;
/**
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
*
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
*/
cameraOffset: Phaser.Point;
/**
* If this is set to `true` the Game Object checks if it is within the World bounds each frame.
*
* When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event.
*
* If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event.
*
* It also optionally kills the Game Object if `outOfBoundsKill` is `true`.
*
* When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
checkWorldBounds: boolean;
/**
* The Rectangle used to crop the texture this Game Object uses.
* Set this property via `crop`.
* If you modify this property directly you must call `updateCrop` in order to have the change take effect.
*/
cropRect: Phaser.Rectangle;
/**
* The components this Game Object has installed.
*/
components: any;
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
customRender: boolean;
/**
* A debug flag designed for use with `Game.enableStep`.
*/
debug: boolean;
/**
* Returns the delta x value. The difference between world.x now and in the previous frame.
*
* The value will be positive if the Game Object has moved to the right or negative if to the left.
*/
deltaX: number;
/**
* Returns the delta y value. The difference between world.y now and in the previous frame.
*
* The value will be positive if the Game Object has moved down or negative if up.
*/
deltaY: number;
/**
* Returns the delta z value. The difference between rotation now and in the previous frame. The delta value.
*/
deltaZ: number;
/**
* As a Game Object runs through its destroy method this flag is set to true,
* and can be checked in any sub-systems or plugins it is being destroyed from.
*/
destroyPhase: boolean;
/**
* Controls if this Game Object is processed by the core game loop.
* If this Game Object has a physics body it also controls if its physics body is updated or not.
* When `exists` is set to `false` it will remove its physics body from the physics world if it has one.
* It also toggles the `visible` property to false as well.
*
* Setting `exists` to true will add its physics body back in to the physics world, if it has one.
* It will also set the `visible` property to `true`.
*/
exists: boolean;
/**
* All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this
* Game Object, or any of its components.
*/
events: Phaser.Events;
/**
* A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
* are stored in the `cameraOffset` property, which is initialized with the current object coordinates.
*
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
*
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
* regardless where in the world the camera is.
*
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
*
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index of the texture being used to render this Game Object.
*
* To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use,
* for example: `player.frame = 4`.
*
* If the frame index given doesn't exist it will revert to the first frame found in the texture.
*
* If you are using a texture atlas then you should use the `frameName` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frame: string | number;
/**
* Gets or sets the current frame name of the texture being used to render this Game Object.
*
* To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use,
* for example: `player.frameName = "idle"`.
*
* If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning.
*
* If you are using a sprite sheet then you should use the `frame` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frameName: string;
/**
* A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update.
* This property is mostly used internally by the physics systems, but is exposed for the use of plugins.
*/
fresh: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
*/
inCamera: boolean;
input: Phaser.InputHandler;
inputEnabled: boolean;
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
inWorld: boolean;
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
left: number;
/**
* The lifespan allows you to give a Game Object a lifespan in milliseconds.
*
* Once the Game Object is 'born' you can set this to a positive value.
*
* It is automatically decremented by 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.
*/
lifespan: number;
/**
* The key of the image or texture used by this Game Object during rendering.
* If it is a string it's the string used to retrieve the texture from the Phaser Image Cache.
* It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache.
* If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it.
*/
key: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture | Phaser.Video;
/**
* A user defined name given to this Game Object.
* This value isn't ever used internally by Phaser, it is meant as a game level property.
*/
name: string;
/**
* The amount the Game Object is visually offset from its x coordinate.
* This is the same as `width * anchor.x`.
* It will only be > 0 if anchor.x is not equal to zero.
*/
offsetX: number;
/**
* The amount the Game Object is visually offset from its y coordinate.
* This is the same as `height * anchor.y`.
* It will only be > 0 if anchor.y is not equal to zero.
*/
offsetY: number;
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
outOfBoundsKill: boolean;
/**
* Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
* which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result.
*
* This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result.
*
* Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
* It should be fine for low-volume testing where physics isn't required.
*
* @param displayObject The display object to check against.
* @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object.
*/
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
/**
* A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
* You can set it directly to allow you to flag an object to be destroyed on its next update.
*
* This is extremely useful if you wish to destroy an object from within one of its own callbacks
* such as with Buttons or other Input events.
*/
pendingDestroy: boolean;
points: Phaser.Point[];
/**
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
*
* The value of this property does not reflect any positioning happening further up the display list.
* To obtain that value please see the `worldPosition` property.
*/
position: Phaser.Point;
/**
* The position the Game Object was located in the previous frame.
*/
previousPosition: Phaser.Point;
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
previousRotation: number;
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
right: number;
/**
* The render order ID is used internally by the renderer and Input Manager and should not be modified.
* This property is mostly used internally by the renderers, but is exposed for the use of plugins.
*/
renderOrderID: number;
/**
* The segments that make up the rope body as an array of Phaser.Rectangles
*/
segments: Phaser.Rectangle[];
/**
* Enable or disable texture smoothing for this Game Object.
*
* It only takes effect if the Game Object is using an image based texture.
*
* Smoothing is enabled by default.
*/
smoothed: boolean;
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
top: number;
/**
* The const type of this object.
*/
type: number;
/**
* The callback that will apply any scale limiting to the worldTransform.
*/
transformCallback: Function;
/**
* The context under which `transformCallback` is called.
*/
transformCallbackContext: any;
/**
* The minimum scale this Game Object will scale down to.
*
* It allows you to prevent a parent from scaling this Game Object lower than the given value.
*
* Set it to `null` to remove the limit.
*/
scaleMin: Phaser.Point;
/**
* The maximum scale this Game Object will scale up to.
*
* It allows you to prevent a parent from scaling this Game Object higher than the given value.
*
* Set it to `null` to remove the limit.
*/
scaleMax: Phaser.Point;
/**
* A Rope will call its updateAnimation function on each update loop if it has one. Set to a function if you'd like the rope to animate during the update phase. Set to false or null to remove it.
*/
updateAnimation: Function;
/**
* The world coordinates of this Game Object in pixels.
* Depending on where in the display list this Game Object is placed this value can differ from `position`,
* which contains the x/y coordinates relative to the Game Objects parent.
*/
world: Phaser.Point;
/**
* The horizontal position of the DisplayObject, in pixels, relative to its parent.
* If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
*/
x: number;
/**
* The vertical position of the DisplayObject, in pixels, relative to its parent.
* If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
*/
y: number;
/**
* The z depth of this Game Object within its parent Group.
* No two objects in a Group can have the same z value.
* This value is adjusted automatically whenever the Group hierarchy changes.
* If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.
*/
z: number;
/**
* Brings this Game Object to the top of its 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.
*/
bringToTop(): Phaser.Rope;
/**
* Adjust scaling limits, if set, to this Game Object.
*
* @param wt The updated worldTransform matrix.
*/
checkTransform(wt: PIXI.Matrix): void;
/**
* Crop allows you to crop the texture being used to display this Game Object.
* Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly.
*
* Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method,
* or by modifying `cropRect` property directly and then calling `updateCrop`.
*
* The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object
* so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties.
*
* A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`,
* in which case the values are duplicated to a local object.
*
* @param rect The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle.
* @param copy If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect.
*/
crop(rect: Phaser.Rectangle, copy?: boolean): void;
/**
* 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.
*/
destroy(destroyChildren?: boolean): void;
/**
* Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false.
*
* It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal.
*
* Note that killing a Game Object is a way for you to quickly recycle it in an object pool,
* it doesn't destroy the object or free it up from memory.
*
* If you don't need this Game Object any more you should call `destroy` instead.
* @return This instance.
*/
kill(): Phaser.Rope;
/**
* Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.
*
* If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead.
*
* You should only use `loadTexture` if you want to replace the base texture entirely.
*
* Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.
*
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite.
* Doing this then sets the key to be the `frame` argument (the frame is set to zero).
*
* This allows you to create sprites using `load.image` during development, and then change them
* to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
* and swapping it to be the key of the atlas data.
*
* Note: You cannot use a RenderTexture as a texture for a TileSprite.
*
* @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
* @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true
*/
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
/**
* Moves this Game Object up one place in its 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.
*/
moveUp(): Phaser.Rope;
/**
* Moves this Game Object down one place in its parents display list.
* This call has no effect if the Game Object is already at the bottom of the display list.
*
* If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World,
* because the World is the root Group from which all Game Objects descend.
* @return This instance.
*/
moveDown(): Phaser.Rope;
/**
* Plays an Animation.
*
* The animation should have previously been created via `animations.add`.
*
* If the animation is already playing calling this again won't do anything.
* If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'.
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return A reference to playing Animation.
*/
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): void;
/**
* Internal method called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Resets the Rope. This places the Rope at the given x/y world coordinates and then
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state.
* If the Rope has a physics body that too is reset.
*
* @param x The x coordinate (in world space) to position the Sprite at.
* @param y The y coordinate (in world space) to position the Sprite at.
* @return This instance.
*/
reset(x: number, y: number, health?: number): Phaser.Rope;
/**
* Resizes the Frame dimensions that the Game Object uses for rendering.
*
* You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData
* it can be useful to adjust the dimensions directly in this way.
*
* @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object.
* @param width The new width of the texture.
* @param height The new height of the texture.
*/
resizeFrame(parent: any, width: number, height: number): void;
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
resetFrame(): void;
/**
* Brings a 'dead' Game Object back to life, optionally resetting its health value in the process.
*
* A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true.
*
* It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal.
*
* @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100
* @return This instance.
*/
revive(health?: number): Phaser.Rope;
/**
* Sends this Game Object to the bottom of its 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.
*/
sendToBack(): Phaser.Rope;
/**
* Sets the texture frame the Game Object uses for rendering.
*
* This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes.
*
* @param frame The Frame to be used by the texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent.
*
* For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored
* and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to.
*
* By setting these values you can carefully control how Game Objects deal with responsive scaling.
*
* If only one parameter is given then that value will be used for both scaleMin and scaleMax:
* `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1
*
* If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y:
* `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2
*
* If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly,
* or pass `null` for the `maxX` and `maxY` parameters.
*
* Call `setScaleMinMax(null)` to clear all previously set values.
*
* @param minX The minimum horizontal scale value this Game Object can scale down to.
* @param minY The minimum vertical scale value this Game Object can scale down to.
* @param maxX The maximum horizontal scale value this Game Object can scale up to.
* @param maxY The maximum vertical scale value this Game Object can scale up to.
*/
setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void;
/**
* If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property,
* or the rectangle it references, then you need to update the crop frame by calling this method.
*/
updateCrop(): void;
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*/
update(): void;
}
/**
* The Rounded Rectangle object is an area defined by its position and has nice rounded corners,
* as indicated by its top-left corner point (x, y) and by its width and its height.
*/
class RoundedRectangle extends PIXI.RoundedRectangle {
/**
* The x coordinate of the top-left corner of the Rectangle.
*/
x: number;
/**
* The y coordinate of the top-left corner of the Rectangle.
*/
y: number;
/**
* The width of the Rectangle. This value should never be set to a negative.
*/
width: number;
/**
* The height of the Rectangle. This value should never be set to a negative.
*/
height: number;
/**
* The radius of the rounded corners.
*/
radius: number;
/**
* The const type of this object.
*/
type: number;
/**
* Returns a new RoundedRectangle object with the same values for the x, y, width, height and
* radius properties as this RoundedRectangle object.
*/
clone(): RoundedRectangle;
/**
* Determines whether the specified coordinates are contained within the region defined by this Rounded Rectangle object.
*
* @param x The x coordinate of the point to test.
* @param y The y coordinate of the point to test.
* @return A value of true if the RoundedRectangle Rectangle object contains the specified point; otherwise false.
*/
contains(x: number, y: number): boolean;
}
/**
* Signals are what Phaser uses to handle events and event dispatching.
* You can listen for a Signal by binding a callback / function to it.
* This is done by using either `Signal.add` or `Signal.addOnce`.
*
* For example you can listen for a touch or click event from the Input Manager
* by using its `onDown` Signal:
*
* `game.input.onDown.add(function() { ... });`
*
* Rather than inline your function, you can pass a reference:
*
* `game.input.onDown.add(clicked, this);`
* `function clicked () { ... }`
*
* In this case the second argument (`this`) is the context in which your function should be called.
*
* Now every time the InputManager dispatches the `onDown` signal (or event), your function
* will be called.
*
* Multiple callbacks can be bound to the same signal.
* They're ordered first by their `priority` arguments and then by the order in which they were added.
* If a callback calls {@link Phaser.Signal#halt halt} or returns `false`, any remaining callbacks are skipped.
*
* Very often a Signal will send arguments to your function.
* This is specific to the Signal itself.
* If you're unsure then check the documentation, or failing that simply do:
*
* `Signal.add(function() { console.log(arguments); })`
*
* and it will log all of the arguments your function received from the Signal.
*
* Sprites have lots of default signals you can listen to in their Events class, such as:
*
* `sprite.events.onKilled`
*
* Which is called automatically whenever the Sprite is killed.
* There are lots of other events, see the Events component for a list.
*
* As well as listening to pre-defined Signals you can also create your own:
*
* `var mySignal = new Phaser.Signal();`
*
* This creates a new Signal. You can bind a callback to it:
*
* `mySignal.add(myCallback, this);`
*
* and then finally when ready you can dispatch the Signal:
*
* `mySignal.dispatch(your arguments);`
*
* And your callback will be invoked. See the dispatch method for more details.
*/
class Signal {
/**
* Is the Signal active? Only active signals will broadcast dispatched events.
*
* Setting this property during a dispatch will only affect the next dispatch. To stop the propagation of a signal from a listener use {@link Phaser.Signal#halt halt}.
* Default: true
*/
active: boolean;
boundDispatch: Function;
/**
* Memorize the previously dispatched event?
*
* If an event has been memorized it is automatically dispatched when a new listener is added with {@link Phaser.Signal#add add} or {@link Phaser.Signal#addOnce addOnce}.
* Use {@link Phaser.Signal#forget forget} to clear any currently memorized event.
*/
memorize: boolean;
/**
* Add an event listener for this signal.
*
* An event listener is a callback with a related context and priority.
*
* You can optionally provide extra arguments which will be passed to the callback after any internal parameters.
*
* For example: `Phaser.Key.onDown` when dispatched will send the Phaser.Key object that caused the signal as the first parameter.
* Any arguments you've specified after `priority` will be sent as well:
*
* `fireButton.onDown.add(shoot, this, 0, 'lazer', 100);`
*
* When onDown dispatches it will call the `shoot` callback passing it: `Phaser.Key, 'lazer', 100`.
*
* Where the first parameter is the one that Key.onDown dispatches internally and 'lazer',
* and the value 100 were the custom arguments given in the call to 'add'.
*
* If the callback calls {@link Phaser.Signal#halt halt} or returns `false`, any remaining callbacks bound to this Signal are skipped.
*
* @param listener The function to call when this Signal is dispatched.
* @param listenerContext The context under which the listener will be executed (i.e. the object that should represent the `this` variable).
* @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
* @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none)
* @return An Object representing the binding between the Signal and listener.
*/
add(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;
/**
* Add a one-time listener - the listener is automatically removed after the first execution.
*
* If there is as {@link Phaser.Signal#memorize memorized} event then it will be dispatched and
* the listener will be removed immediately.
*
* @param listener The function to call when this Signal is dispatched.
* @param listenerContext The context under which the listener will be executed (i.e. the object that should represent the `this` variable).
* @param priority The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added (default = 0)
* @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none)
* @return An Object representing the binding between the Signal and listener.
*/
addOnce(listener: Function, listenerContext?: any, priority?: number, ...args: any[]): Phaser.SignalBinding;
/**
* Dispatch / broadcast the event to all listeners.
*
* To create an instance-bound dispatch for this Signal, use {@link Phaser.Signal#boundDispatch boundDispatch}.
*
* @param params Parameters that should be passed to each handler.
*/
dispatch(...params: any[]): void;
/**
* Dispose the signal - no more events can be dispatched.
*
* This removes all event listeners and clears references to external objects.
* Calling methods on a disposed objects results in undefined behavior.
*/
dispose(): void;
/**
* Forget the currently {@link Phaser.Signal#memorize memorized} event, if any.
*/
forget(): void;
/**
* Gets the total number of listeners attached to this Signal.
* @return Number of listeners attached to the Signal.
*/
getNumListeners(): number;
/**
* Stop propagation of the event, blocking the dispatch to next listener on the queue.
*
* This should be called only during event dispatch as calling it before/after dispatch won't affect another broadcast.
* See {@link Phaser.Signal#active active} to enable/disable the signal entirely.
*/
halt(): void;
/**
* Check if a specific listener is attached.
*
* @param listener Signal handler function.
* @param context Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @return If Signal has the specified listener.
*/
has(listener: Function, context?: any): boolean;
/**
* Remove a single event listener.
*
* @param listener Handler function that should be removed.
* @param context Execution context (since you can add the same handler multiple times if executing in a different context).
* @return Listener handler function.
*/
remove(listener: Function, context?: any): Function;
/**
* Remove all event listeners.
*
* @param context If specified only listeners for the given context will be removed.
*/
removeAll(context?: any): void;
/**
* A string representation of the object.
* @return String representation of the object.
*/
toString(): string;
/**
*
*
* @param listener Signal handler function.
* @param fnName Function name.
*/
validateListener(listener: Function, fnName: string): void;
}
/**
* Object that represents a binding between a Signal and a listener function.
* This is an internal constructor and shouldn't be created directly.
* Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
*/
class SignalBinding {
/**
* Object that represents a binding between a Signal and a listener function.
* This is an internal constructor and shouldn't be created directly.
* Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
*
* @param signal Reference to Signal object that listener is currently bound to.
* @param listener Handler function bound to the signal.
* @param isOnce If binding should be executed just once.
* @param listenerContext Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param priority The priority level of the event listener. (default = 0).
* @param args Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched. - Default: (none)
*/
constructor(signal: Phaser.Signal, listener: Function, isOnce: boolean, listenerContext?: any, priority?: number, ...args: any[]);
/**
* If binding is active and should be executed.
* Default: true
*/
active: boolean;
/**
* The number of times the handler function has been called.
*/
callCount: number;
/**
* Context on which listener will be executed (object that should represent the `this` variable inside listener function).
*/
context: any;
/**
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters).
*/
params: any[];
/**
* Call listener passing arbitrary parameters.
* If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
*
* @param paramsArr Array of parameters that should be passed to the listener.
* @return Value returned by the listener.
*/
execute(paramsArr?: any[]): void;
/**
* Detach binding from signal.
* alias to: @see mySignal.remove(myBinding.getListener());
* @return Handler function bound to the signal or `null` if binding was previously detached.
*/
detach(): Function;
/**
*
* @return True if binding is still bound to the signal and has a listener.
*/
isBound(): boolean;
/**
*
* @return If SignalBinding will only be executed once.
*/
isOnce(): boolean;
/**
*
* @return Handler function bound to the signal.
*/
getListener(): Function;
/**
*
* @return Signal that listener is currently bound to.
*/
getSignal(): Phaser.Signal;
/**
*
* @return String representation of the object.
*/
toString(): string;
}
/**
* A single Phaser Gamepad
*/
class SinglePad {
/**
* A single Phaser Gamepad
*
* @param game Current game instance.
* @param padParent The parent Phaser.Gamepad object (all gamepads reside under this)
*/
constructor(game: Phaser.Game, padParent: any);
/**
* The context under which the callbacks are run.
*/
callbackContext: any;
/**
* Whether or not this particular gamepad is connected or not.
*/
connected: boolean;
/**
* Dead zone for axis feedback - within this value you won't trigger updates.
*/
deadZone: number;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* The gamepad index as per browsers data
*/
index: number;
/**
* This callback is invoked every time an axis is changed.
*/
onAxisCallback: Function;
/**
* This callback is invoked every time this gamepad is connected
*/
onConnectCallback: Function;
/**
* This callback is invoked every time this gamepad is disconnected
*/
onDisconnectCallback: Function;
/**
* This callback is invoked every time a button is pressed down.
*/
onDownCallback: Function;
/**
* This callback is invoked every time a button is changed to a value where value > 0 and value < 1.
*/
onFloatCallback: Function;
/**
* This callback is invoked every time a gamepad button is released.
*/
onUpCallback: Function;
/**
* Returns value of requested axis.
*
* @param axisCode The index of the axis to check
* @return Axis value if available otherwise false
*/
axis(axisCode: number): number;
/**
* Add callbacks to this Gamepad to handle connect / disconnect / button down / button up / axis change / float value buttons.
*
* @param context The context under which the callbacks are run.
* @param callbacks Object that takes six different callbak methods:
* onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, onAxisCallback, onFloatCallback
*/
addCallbacks(context: any, callbacks: any): void;
/**
* Returns the value of a gamepad button. Intended mainly for cases when you have floating button values, for example
* analog trigger buttons on the XBOX 360 controller.
*
* @param buttonCode The buttonCode of the button to check.
* @return Button value if available otherwise null. Be careful as this can incorrectly evaluate to 0.
*/
buttonValue(buttonCode: number): number;
/**
* Gamepad connect function, should be called by Phaser.Gamepad.
*
* @param rawPad The raw gamepad object
*/
connect(rawPad: any): void;
/**
* Destroys this object and associated callback references.
*/
destroy(): void;
/**
* Gamepad disconnect function, should be called by Phaser.Gamepad.
*/
disconnect(): void;
/**
* Gets a DeviceButton object from this controller to be stored and referenced locally.
* The DeviceButton object can then be polled, have events attached to it, etc.
*
* @param buttonCode The buttonCode of the button, i.e. Phaser.Gamepad.BUTTON_0, Phaser.Gamepad.XBOX360_A, etc.
* @return The DeviceButton object which you can store locally and reference directly.
*/
getButton(buttonCode: number): Phaser.DeviceButton;
/**
* Returns true if the button is pressed down.
*
* @param buttonCode The buttonCode of the button to check.
* @return True if the button is pressed down.
*/
isDown(buttonCode: number): boolean;
/**
* Returns true if the button is not currently pressed.
*
* @param buttonCode The buttonCode of the button to check.
* @return True if the button is not currently pressed down.
*/
isUp(buttonCode: number): boolean;
/**
* Returns the "just pressed" state of a button from this gamepad. Just pressed is considered true if the button was pressed down within the duration given (default 250ms).
*
* @param buttonCode The buttonCode of the button to check for.
* @param duration The duration below which the button is considered as being just pressed. - Default: 250
* @return True if the button is just pressed otherwise false.
*/
justPressed(buttonCode: number, duration?: number): boolean;
/**
* Returns the "just released" state of a button from this gamepad. Just released is considered as being true if the button was released within the duration given (default 250ms).
*
* @param buttonCode The buttonCode of the button to check for.
* @param duration The duration below which the button is considered as being just released. - Default: 250
* @return True if the button is just released otherwise false.
*/
justReleased(buttonCode: number, duration?: number): boolean;
/**
* Main update function called by Phaser.Gamepad.
*/
pollStatus(): void;
/**
* Handles changes in axis.
*
* @param axisState State of the relevant axis
*/
processAxisChange(axisState: any): void;
/**
* Handles button down press.
*
* @param buttonCode Which buttonCode of this button
* @param value Button value
*/
processButtonDown(buttonCode: number, value: any): void;
/**
* Handles buttons with floating values (like analog buttons that acts almost like an axis but still registers like a button)
*
* @param buttonCode Which buttonCode of this button
* @param value Button value (will range somewhere between 0 and 1, but not specifically 0 or 1.
*/
processButtonFloat(buttonCode: number, value: any): void;
/**
* Handles button release.
*
* @param buttonCode Which buttonCode of this button
* @param value Button value
*/
processButtonUp(buttonCode: number, value: any): void;
/**
* Reset all buttons/axes of this gamepad.
*/
reset(): void;
}
/**
* The Sound class constructor.
*/
class Sound {
/**
* The Sound class constructor.
*
* @param game Reference to the current game instance.
* @param key Asset key for the sound.
* @param volume Default value for the volume, between 0 and 1. - Default: 1
* @param loop Whether or not the sound will loop.
*/
constructor(game: Phaser.Game, key: string, volume?: number, loop?: boolean, connect?: boolean);
/**
* Boolean indicating whether the sound should start automatically.
*/
autoplay: boolean;
/**
* This will allow you to have multiple instances of this Sound playing at once. This is only useful when running under Web Audio, and we recommend you implement a local pooling system to not flood the sound channels.
*/
allowMultiple: boolean;
/**
* Reference to the AudioContext instance.
*/
context: any;
/**
* The string ID of the currently playing marker, if any.
*/
currentMarker: string;
/**
* The current time of sound playback in ms.
*/
currentTime: number;
/**
* Destroys this sound and all associated events and removes it from the SoundManager.
*
* @param remove If true this Sound is automatically removed from the SoundManager. - Default: true
*/
destroy(remove?: boolean): void;
/**
* The duration of the current sound marker in seconds.
*/
duration: number;
/**
* The duration of the current sound marker in ms.
*/
durationMS: number;
/**
* If defined this Sound won't connect to the SoundManager master gain node, but will instead connect to externalNode.
*/
externalNode: any;
/**
* The tween that fades the audio, set via Sound.fadeIn and Sound.fadeOut.
*/
fadeTween: Phaser.Tween;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The gain node in a Web Audio system.
*/
gainNode: any;
/**
* Returns true if the sound file has decoded.
*/
isDecoded: boolean;
/**
* Returns true if the sound file is still decoding.
*/
isDecoding: boolean;
/**
* true if the sound is currently playing, otherwise false.
*/
isPlaying: boolean;
/**
* Asset key for the sound.
*/
key: string;
/**
* Whether or not the sound or current sound marker will loop.
*/
loop: boolean;
/**
* The sound markers.
*/
markers: any;
/**
* The master gain node in a Web Audio system.
*/
masterGainNode: any;
/**
* Gets or sets the muted state of this sound.
*/
mute: boolean;
/**
* Name of the sound.
*/
name: string;
/**
* The onDecoded event is dispatched when the sound has finished decoding (typically for mp3 files)
*/
onDecoded: Phaser.Signal;
onEndedHandler: () => void;
/**
* The onFadeComplete event is dispatched when this sound finishes fading either in or out.
*/
onFadeComplete: Phaser.Signal;
/**
* The onLoop event is dispatched when this sound loops during playback.
*/
onLoop: Phaser.Signal;
/**
* The onMarkerComplete event is dispatched when a marker within this sound completes playback.
*/
onMarkerComplete: Phaser.Signal;
/**
* The onMute event is dispatched when this sound is muted.
*/
onMute: Phaser.Signal;
/**
* The onPause event is dispatched when this sound is paused.
*/
onPause: Phaser.Signal;
/**
* The onPlay event is dispatched each time this sound is played.
*/
onPlay: Phaser.Signal;
/**
* The onResume event is dispatched when this sound is resumed from a paused state.
*/
onResume: Phaser.Signal;
/**
* The onStop event is dispatched when this sound stops playback.
*/
onStop: Phaser.Signal;
/**
* if true when you play this sound it will always start from the beginning.
*/
override: boolean;
/**
* true if the sound is paused, otherwise false.
*/
paused: boolean;
/**
* The position the sound had reached when it was paused in ms.
*/
pausedPosition: number;
/**
* The game time (ms) at which the sound was paused.
*/
pausedTime: number;
/**
* true if the sound file is pending playback
*/
pendingPlayback: boolean;
/**
* The position of the current sound marker in ms.
*/
position: number;
/**
* The time the sound starts at in ms (typically 0 unless starting from a marker).
*/
startTime: number;
/**
* The time the sound stopped in ms.
*/
stopTime: number;
/**
* The total duration of the sound in seconds.
*/
totalDuration: number;
/**
* true if the sound is being played via the Audio tag.
*/
usingAudioTag: boolean;
/**
* true if this sound is being played with Web Audio.
*/
usingWebAudio: boolean;
/**
* Gets or sets the volume of this sound, a value between 0 and 1. The value given is clamped to the range 0 to 1.
*/
volume: number;
/**
* Adds a marker into the current Sound. A marker is represented by a unique key and a start time and duration.
* This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback.
*
* @param name A unique name for this marker, i.e. 'explosion', 'gunshot', etc.
* @param start The start point of this marker in the audio file, given in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc.
* @param duration The duration of the marker in seconds. 2.5 = 2500ms, 0.5 = 500ms, etc. - Default: 1
* @param volume The volume the sound will play back at, between 0 (silent) and 1 (full volume). - Default: 1
* @param loop Sets if the sound will loop or not.
*/
addMarker(name: string, start: number, duration: number, volume?: number, loop?: boolean): void;
/**
* Destroys this sound and all associated events and removes it from the SoundManager.
*
* @param remove If true this Sound is automatically removed from the SoundManager. - Default: true
*/
destroy(): void;
/**
* Starts this sound playing (or restarts it if already doing so) and sets the volume to zero.
* Then increases the volume from 0 to 1 over the duration specified.
*
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (1) as the second parameter.
*
* @param duration The time in milliseconds over which the Sound should fade in. - Default: 1000
* @param loop Should the Sound be set to loop? Note that this doesn't cause the fade to repeat.
* @param marker The marker to start at; defaults to the current (last played) marker. To start playing from the beginning specify specify a marker of `''`. - Default: (current marker)
*/
fadeIn(duration?: number, loop?: boolean, marker?: string): void;
/**
* Decreases the volume of this Sound from its current value to 0 over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (0) as the second parameter.
*
* @param duration The time in milliseconds over which the Sound should fade out. - Default: 1000
*/
fadeOut(duration?: number): void;
/**
* Fades the volume of this Sound from its current value to the given volume over the duration specified.
* At the end of the fade Sound.onFadeComplete is dispatched with this Sound object as the first parameter,
* and the final volume (volume) as the second parameter.
*
* @param duration The time in milliseconds during which the Sound should fade out. - Default: 1000
* @param volume The volume which the Sound should fade to. This is a value between 0 and 1.
*/
fadeTo(duration?: number, volume?: number): void;
/**
* Loops this entire sound. If you need to loop a section of it then use Sound.play and the marker and loop parameters.
*
* @param volume Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified). - Default: 1
* @return This sound instance.
*/
loopFull(volume?: number): Phaser.Sound;
/**
* Pauses the sound.
*/
pause(): void;
/**
* Play this sound, or a marked section of it.
*
* @param marker If you want to play a marker then give the key here, otherwise leave blank to play the full sound. - Default: ''
* @param position The starting position to play the sound from - this is ignored if you provide a marker.
* @param volume Volume of the sound you want to play. If none is given it will use the volume given to the Sound when it was created (which defaults to 1 if none was specified). - Default: 1
* @param loop Loop when finished playing? If not using a marker / audio sprite the looping will be done via the WebAudio loop property, otherwise it's time based.
* @param forceRestart If the sound is already playing you can set forceRestart to restart it from the beginning. - Default: true
* @return This sound instance.
*/
play(marker?: string, position?: number, volume?: number, loop?: boolean, forceRestart?: boolean): Phaser.Sound;
/**
* Removes a marker from the sound.
*
* @param name The key of the marker to remove.
*/
removeMarker(name: string): void;
/**
* Restart the sound, or a marked section of it.
*
* @param marker If you want to play a marker then give the key here, otherwise leave blank to play the full sound. - Default: ''
* @param position The starting position to play the sound from - this is ignored if you provide a marker.
* @param volume Volume of the sound you want to play. - Default: 1
* @param loop Loop when it finished playing?
*/
restart(marker: string, position: number, volume?: number, loop?: boolean): void;
/**
* Resumes the sound.
*/
resume(): void;
/**
* Called automatically when this sound is unlocked.
*
* @param key The Phaser.Cache key of the sound file to check for decoding.
*/
soundHasUnlocked(key: string): void;
/**
* Stop playing this sound.
*/
stop(): void;
/**
* Called automatically by Phaser.SoundManager.
*/
update(): void;
}
/**
* The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it.
* Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files.
* The audio file type and the encoding of those files are extremely important. Not all browsers can play all audio formats.
* There is a good guide to what's supported here: http://hpr.dogphilosophy.net/test/
*
* If you are reloading a Phaser Game on a page that never properly refreshes (such as in an AngularJS project) then you will quickly run out
* of AudioContext nodes. If this is the case create a global var called PhaserGlobal on the window object before creating the game. The active
* AudioContext will then be saved to window.PhaserGlobal.audioContext when the Phaser game is destroyed, and re-used when it starts again.
*
* Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio.
* When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system.
* The solution is to use a lower encoding rate such as 44100 Hz. Sometimes the audio context will
* be created with a sampleRate of 48000. If this happens and audio distorts you should re-create the context.
*/
class SoundManager {
/**
* The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it.
* Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files.
* The audio file type and the encoding of those files are extremely important. Not all browsers can play all audio formats.
* There is a good guide to what's supported here: http://hpr.dogphilosophy.net/test/
*
* If you are reloading a Phaser Game on a page that never properly refreshes (such as in an AngularJS project) then you will quickly run out
* of AudioContext nodes. If this is the case create a global var called PhaserGlobal on the window object before creating the game. The active
* AudioContext will then be saved to window.PhaserGlobal.audioContext when the Phaser game is destroyed, and re-used when it starts again.
*
* Mobile warning: There are some mobile devices (certain iPad 2 and iPad Mini revisions) that cannot play 48000 Hz audio.
* When they try to play the audio becomes extremely distorted and buzzes, eventually crashing the sound system.
* The solution is to use a lower encoding rate such as 44100 Hz. Sometimes the audio context will
* be created with a sampleRate of 48000. If this happens and audio distorts you should re-create the context.
*
* @param game Reference to the current game instance.
*/
constructor(game: Phaser.Game);
/**
* The number of audio channels to use in playback.
* Default: 32
*/
channels: number;
/**
* Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node.
* Default: true
*/
connectToMaster: boolean;
/**
* The AudioContext being used for playback.
*/
context: any;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Gets or sets the muted state of the SoundManager. This effects all sounds in the game.
*/
mute: boolean;
/**
* Set to true to have all sound muted when the Phaser game pauses (such as on loss of focus),
* or set to false to keep audio playing, regardless of the game pause state. You may need to
* do this should you wish to control audio muting via external DOM buttons or similar.
* Default: true
*/
muteOnPause: boolean;
/**
* True if audio been disabled via the PhaserGlobal (useful if you need to use a 3rd party audio library) or the device doesn't support any audio.
*/
noAudio: boolean;
/**
* The event dispatched when a sound decodes (typically only for mp3 files)
*/
onSoundDecode: Phaser.Signal;
/**
* This signal is dispatched whenever the global volume changes. The new volume is passed as the only parameter to your callback.
*/
onVolumeChange: Phaser.Signal;
/**
* This signal is dispatched when the SoundManager is globally muted, either directly via game code or as a result of the game pausing.
*/
onMute: Phaser.Signal;
/**
* This signal is dispatched when the SoundManager is globally un-muted, either directly via game code or as a result of the game resuming from a pause.
*/
onUnMute: Phaser.Signal;
/**
* true if the audio system is currently locked awaiting a touch event.
*/
touchLocked: boolean;
/**
* True the SoundManager and device are both using the Audio tag instead of Web Audio.
*/
usingAudioTag: boolean;
/**
* True the SoundManager and device are both using Web Audio.
*/
usingWebAudio: boolean;
/**
* Gets or sets the global volume of the SoundManager, a value between 0 and 1. The value given is clamped to the range 0 to 1.
*/
volume: number;
/**
* Adds a new Sound into the SoundManager.
*
* @param key Asset key for the sound.
* @param volume Default value for the volume. - Default: 1
* @param loop Whether or not the sound will loop.
* @param connect Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio. - Default: true
* @return The new sound instance.
*/
add(key: string, volume?: number, loop?: boolean, connect?: boolean): Phaser.Sound;
/**
* Adds a new AudioSprite into the SoundManager.
*
* @param key Asset key for the sound.
* @return The new AudioSprite instance.
*/
addSprite(key: string): Phaser.AudioSprite;
/**
* Initialises the sound manager.
*/
boot(): void;
/**
* Decode a sound by its asset key.
*
* @param key Assets key of the sound to be decoded.
* @param sound Its buffer will be set to decoded data.
*/
decode(key: string, sound?: Phaser.Sound): void;
/**
* Stops all the sounds in the game, then destroys them and finally clears up any callbacks.
*/
destroy(): void;
/**
* Pauses all the sounds in the game.
*/
pauseAll(): void;
/**
* Adds a new Sound into the SoundManager and starts it playing.
*
* @param key Asset key for the sound.
* @param volume Default value for the volume. - Default: 1
* @param loop Whether or not the sound will loop.
* @return The new sound instance.
*/
play(key: string, volume?: number, loop?: boolean): Phaser.Sound;
/**
* Removes a Sound from the SoundManager. The removed Sound is destroyed before removal.
*
* @param sound The sound object to remove.
* @return True if the sound was removed successfully, otherwise false.
*/
remove(sound: Phaser.Sound): boolean;
/**
* Removes all Sounds from the SoundManager that have an asset key matching the given value.
* The removed Sounds are destroyed before removal.
*
* @param key The key to match when removing sound objects.
* @return The number of matching sound objects that were removed.
*/
removeByKey(key: string): number;
/**
* Resumes every sound in the game.
*/
resumeAll(): void;
/**
* This method allows you to give the SoundManager a list of Sound files, or keys, and a callback.
* Once all of the Sound files have finished decoding the callback will be invoked.
* The amount of time spent decoding depends on the codec used and file size.
* If all of the files given have already decoded the callback is triggered immediately.
*
* @param files An array containing either Phaser.Sound objects or their key strings as found in the Phaser.Cache.
* @param callback The callback which will be invoked once all files have finished decoding.
* @param callbackContext The context in which the callback will run.
*/
setDecodedCallback(files: string[] | Phaser.Sound[], callback: Function, callbackContext: any): void;
/**
* Sets the Input Manager touch callback to be SoundManager.unlock.
* Required for iOS audio device unlocking. Mostly just used internally.
*/
setTouchLock(): void;
/**
* Stops all the sounds in the game.
*/
stopAll(): void;
/**
* Enables the audio, usually after the first touch.
* @return True if the callback should be removed, otherwise false.
*/
unlock(): boolean;
/**
* Updates every sound in the game, checks for audio unlock on mobile and monitors the decoding watch list.
*/
update(): void;
}
/**
* Sprites are the lifeblood of your game, used for nearly everything visual.
*
* At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas.
* They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
* events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
*/
class Sprite extends PIXI.Sprite {
/**
* Sprites are the lifeblood of your game, used for nearly everything visual.
*
* At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas.
* They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input),
* events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases.
*
* @param game A reference to the currently running game.
* @param x The x coordinate (in world space) to position the Sprite at.
* @param y The y coordinate (in world space) to position the Sprite at.
* @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. If this argument is omitted, the sprite will receive {@link Phaser.Cache.DEFAULT the default texture} (as if you had passed '__default'), but its `key` will remain empty.
* @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
*/
constructor(game: Phaser.Game, x: number, y: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number);
/**
* A useful flag to control if the Game Object is alive or dead.
*
* This is set automatically by the Health components `damage` method should the object run out of health.
* Or you can toggle it via your game code.
*
* This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates.
* However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling.
* Default: true
*/
alive: boolean;
/**
* The anchor sets the origin point of the texture.
* The default (0, 0) is the top left.
* (0.5, 0.5) is the center.
* (1, 1) is the bottom right.
*
* You can modify the default values in PIXI.Sprite.defaultAnchor.
*/
anchor: Phaser.Point;
/**
* The angle property is the rotation of the Game Object in *degrees* from its original orientation.
*
* Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
*
* Values outside this range are added to or subtracted from 360 to obtain a value within the range.
* For example, the statement player.angle = 450 is the same as player.angle = 90.
*
* If you wish to work in radians instead of degrees you can use the property `rotation` instead.
* Working in radians is slightly faster as it doesn't have to perform any calculations.
*/
angle: number;
/**
* If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance.
* Through it you can create, play, pause and stop animations.
*/
animations: Phaser.AnimationManager;
/**
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
autoCull: boolean;
/**
* `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated
* properties and methods via it.
*
* By default Game Objects won't add themselves to any physics system and their `body` property will be `null`.
*
* To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object
* and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`.
*
* You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group.
*
* Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5,
* so the physics body is centered on the Game Object.
*
* If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics.
*/
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
bottom: number;
/**
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
*
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
*/
cameraOffset: Phaser.Point;
/**
* The center x coordinate of the Game Object.
* This is the same as `(x - offsetX) + (width / 2)`.
*/
centerX: number;
/**
* The center y coordinate of the Game Object.
* This is the same as `(y - offsetY) + (height / 2)`.
*/
centerY: number;
/**
* If this is set to `true` the Game Object checks if it is within the World bounds each frame.
*
* When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event.
*
* If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event.
*
* It also optionally kills the Game Object if `outOfBoundsKill` is `true`.
*
* When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
checkWorldBounds: boolean;
/**
* The components this Game Object has installed.
*/
components: any;
/**
* The Rectangle used to crop the texture this Game Object uses.
* Set this property via `crop`.
* If you modify this property directly you must call `updateCrop` in order to have the change take effect.
*/
cropRect: Phaser.Rectangle;
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
customRender: boolean;
/**
* An empty Object that belongs to this Game Object.
* This value isn't ever used internally by Phaser, but may be used by your own code, or
* by Phaser Plugins, to store data that needs to be associated with the Game Object,
* without polluting the Game Object directly.
* Default: {}
*/
data: any;
/**
* A debug flag designed for use with `Game.enableStep`.
*/
debug: boolean;
/**
* Returns the delta x value. The difference between world.x now and in the previous frame.
*
* The value will be positive if the Game Object has moved to the right or negative if to the left.
*/
deltaX: number;
/**
* Returns the delta y value. The difference between world.y now and in the previous frame.
*
* The value will be positive if the Game Object has moved down or negative if up.
*/
deltaY: number;
/**
* Returns the delta z value. The difference between rotation now and in the previous frame. The delta value.
*/
deltaZ: number;
/**
* As a Game Object runs through its destroy method this flag is set to true,
* and can be checked in any sub-systems or plugins it is being destroyed from.
*/
destroyPhase: boolean;
/**
* All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this
* Game Object, or any of its components.
*/
events: Phaser.Events;
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}).
* Default: true
*/
exists: boolean;
/**
* A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
* are stored in the `cameraOffset` property, which is initialized with the current object coordinates.
*
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
*
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
* regardless where in the world the camera is.
*
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
*
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index of the texture being used to render this Game Object.
*
* To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use,
* for example: `player.frame = 4`.
*
* If the frame index given doesn't exist it will revert to the first frame found in the texture.
*
* If you are using a texture atlas then you should use the `frameName` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frame: string | number;
/**
* Gets or sets the current frame name of the texture being used to render this Game Object.
*
* To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use,
* for example: `player.frameName = "idle"`.
*
* If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning.
*
* If you are using a sprite sheet then you should use the `frame` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frameName: string;
/**
* A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update.
* This property is mostly used internally by the physics systems, but is exposed for the use of plugins.
*/
fresh: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The Game Objects health value. This is a handy property for setting and manipulating health on a Game Object.
*
* It can be used in combination with the `damage` method or modified directly.
* Default: 1
*/
health: number;
/**
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
*/
inCamera: boolean;
/**
* The Input Handler for this Game Object.
*
* By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`.
*
* After you have done this, this property will be a reference to the Phaser InputHandler.
*/
input: Phaser.InputHandler;
/**
* By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created
* for this Game Object and it will then start to process click / touch events and more.
*
* You can then access the Input Handler via `this.input`.
*
* Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`.
*
* If you set this property to false it will stop the Input Handler from processing any more input events.
*
* If you want to _temporarily_ disable input for a Game Object, then it's better to set
* `input.enabled = false`, as it won't reset any of the Input Handlers internal properties.
* You can then toggle this back on as needed.
*/
inputEnabled: boolean;
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
inWorld: boolean;
/**
* The key of the image or texture used by this Game Object during rendering.
* If it is a string it's the string used to retrieve the texture from the Phaser Image Cache.
* It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache.
* If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it.
*/
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
left: number;
/**
* The lifespan allows you to give a Game Object a lifespan in milliseconds.
*
* Once the Game Object is 'born' you can set this to a positive value.
*
* It is automatically decremented by 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.
*/
lifespan: number;
/**
* The Game Objects maximum health value. This works in combination with the `heal` method to ensure
* the health value never exceeds the maximum.
* Default: 100
*/
maxHealth: number;
/**
* A user defined name given to this Game Object.
* This value isn't ever used internally by Phaser, it is meant as a game level property.
*/
name: string;
/**
* The amount the Game Object is visually offset from its x coordinate.
* This is the same as `width * anchor.x`.
* It will only be > 0 if anchor.x is not equal to zero.
*/
offsetX: number;
/**
* The amount the Game Object is visually offset from its y coordinate.
* This is the same as `height * anchor.y`.
* It will only be > 0 if anchor.y is not equal to zero.
*/
offsetY: number;
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
outOfBoundsKill: boolean;
/**
* A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
* You can set it directly to allow you to flag an object to be destroyed on its next update.
*
* This is extremely useful if you wish to destroy an object from within one of its own callbacks
* such as with Buttons or other Input events.
*/
pendingDestroy: boolean;
/**
* The position the Game Object was located in the previous frame.
*/
previousPosition: Phaser.Point;
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
previousRotation: number;
/**
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
*
* The value of this property does not reflect any positioning happening further up the display list.
* To obtain that value please see the `worldPosition` property.
*/
position: Phaser.Point;
physicsEnabled: boolean;
/**
* The const physics body type of this object.
*/
physicsType: number;
/**
* The render order ID is used internally by the renderer and Input Manager and should not be modified.
* This property is mostly used internally by the renderers, but is exposed for the use of plugins.
*/
renderOrderID: number;
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
right: number;
/**
* The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject
* at its default size. A value of 0.5 would scale this DisplayObject by half, and so on.
*
* The value of this property does not reflect any scaling happening further up the display list.
* To obtain that value please see the `worldScale` property.
*/
scale: Phaser.Point;
/**
* The minimum scale this Game Object will scale down to.
*
* It allows you to prevent a parent from scaling this Game Object lower than the given value.
*
* Set it to `null` to remove the limit.
*/
scaleMin: Phaser.Point;
/**
* The maximum scale this Game Object will scale up to.
*
* It allows you to prevent a parent from scaling this Game Object higher than the given value.
*
* Set it to `null` to remove the limit.
*/
scaleMax: Phaser.Point;
/**
* Enable or disable texture smoothing for this Game Object.
*
* It only takes effect if the Game Object is using an image based texture.
*
* Smoothing is enabled by default.
*/
smoothed: boolean;
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
top: number;
/**
* The const type of this object.
*/
type: number;
/**
* A canvas that contains the tinted version of the Sprite (in Canvas mode, WebGL doesn't populate this)
* Default: null
*/
tintedTexture: HTMLCanvasElement;
/**
* The callback that will apply any scale limiting to the worldTransform.
*/
transformCallback: Function;
/**
* The context under which `transformCallback` is called.
*/
transformCallbackContext: any;
/**
* The world coordinates of this Game Object in pixels.
* Depending on where in the display list this Game Object is placed this value can differ from `position`,
* which contains the x/y coordinates relative to the Game Objects parent.
*/
world: Phaser.Point;
/**
* The horizontal position of the DisplayObject, in pixels, relative to its parent.
* If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
*/
x: number;
/**
* The vertical position of the DisplayObject, in pixels, relative to its parent.
* If you need the world position of the DisplayObject, use `DisplayObject.worldPosition` instead.
*/
y: number;
/**
* The z depth of this Game Object within its parent Group.
* No two objects in a Group can have the same z value.
* This value is adjusted automatically whenever the Group hierarchy changes.
* If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.
*/
z: number;
/**
* Aligns this Game Object within another Game Object, or Rectangle, known as the
* 'container', to one of 9 possible positions.
*
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the container. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* container, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive
* one expands it.
*
* @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
* 'parent', in one of 11 possible positions.
*
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the parent. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
* and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* parent, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
* one expands it.
*
* @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Brings this Game Object to the top of its 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.
*/
bringToTop(): Phaser.Sprite;
/**
* Crop allows you to crop the texture being used to display this Game Object.
* Setting a crop rectangle modifies the core texture frame. The Game Object width and height properties will be adjusted accordingly.
*
* Cropping takes place from the top-left and can be modified in real-time either by providing an updated rectangle object to this method,
* or by modifying `cropRect` property directly and then calling `updateCrop`.
*
* The rectangle object given to this method can be either a `Phaser.Rectangle` or any other object
* so long as it has public `x`, `y`, `width`, `height`, `right` and `bottom` properties.
*
* A reference to the rectangle is stored in `cropRect` unless the `copy` parameter is `true`,
* in which case the values are duplicated to a local object.
*
* @param rect The Rectangle used during cropping. Pass null or no parameters to clear a previously set crop rectangle.
* @param copy If false `cropRect` will be stored as a reference to the given rect. If true it will copy the rect values into a local Phaser Rectangle object stored in cropRect.
*/
crop(rect: Phaser.Rectangle, copy: boolean): void;
/**
* Adjust scaling limits, if set, to this Game Object.
*
* @param wt The updated worldTransform matrix.
*/
checkTransform(wt: PIXI.Matrix): void;
damage(amount: number): Phaser.Sprite;
/**
* 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.
*/
destroy(destroyChildren?: boolean): void;
drawPolygon(): void;
heal(amount: number): Phaser.Sprite;
/**
* Kills a Game Object. A killed Game Object has its `alive`, `exists` and `visible` properties all set to false.
*
* It will dispatch the `onKilled` event. You can listen to `events.onKilled` for the signal.
*
* Note that killing a Game Object is a way for you to quickly recycle it in an object pool,
* it doesn't destroy the object or free it up from memory.
*
* If you don't need this Game Object any more you should call `destroy` instead.
* @return This instance.
*/
kill(): Phaser.Sprite;
/**
* Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.
*
* If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead.
*
* You should only use `loadTexture` if you want to replace the base texture entirely.
*
* Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.
*
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite.
* Doing this then sets the key to be the `frame` argument (the frame is set to zero).
*
* This allows you to create sprites using `load.image` during development, and then change them
* to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
* and swapping it to be the key of the atlas data.
*
* Note: You cannot use a RenderTexture as a texture for a TileSprite.
*
* @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
* @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true
*/
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
/**
* Moves this Game Object up one place in its 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.
*/
moveUp(): Phaser.Sprite;
/**
* Moves this Game Object down one place in its parents display list.
* This call has no effect if the Game Object is already at the bottom of the display list.
*
* If this Game Object hasn't been added to a custom Group then this method will move it one object down within the Game World,
* because the World is the root Group from which all Game Objects descend.
* @return This instance.
*/
moveDown(): Phaser.Sprite;
/**
* Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
* which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result.
*
* This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result.
*
* Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
* It should be fine for low-volume testing where physics isn't required.
*
* @param displayObject The display object to check against.
* @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object.
*/
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
/**
* Plays an Animation.
*
* The animation should have previously been created via `animations.add`.
*
* If the animation is already playing calling this again won't do anything.
* If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'.
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return A reference to playing Animation.
*/
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
/**
* Internal method called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Automatically called by World.preUpdate.
* @return True if the Sprite was rendered, otherwise false.
*/
preUpdate(): void;
/**
* Resets the Game Object.
*
* This moves the Game Object to the given x/y world coordinates and sets `fresh`, `exists`,
* `visible` and `renderable` to true.
*
* If this Game Object has the LifeSpan component it will also set `alive` to true and `health` to the given value.
*
* If this Game Object has a Physics Body it will reset the Body.
*
* @param x The x coordinate (in world space) to position the Game Object at.
* @param y The y coordinate (in world space) to position the Game Object at.
* @param health The health to give the Game Object if it has the Health component. - Default: 1
* @return This instance.
*/
reset(x: number, y: number, health?: number): Phaser.Sprite;
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
resetFrame(): void;
/**
* Resizes the Frame dimensions that the Game Object uses for rendering.
*
* You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData
* it can be useful to adjust the dimensions directly in this way.
*
* @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object.
* @param width The new width of the texture.
* @param height The new height of the texture.
*/
resizeFrame(parent: any, width: number, height: number): void;
/**
* Brings a 'dead' Game Object back to life, optionally resetting its health value in the process.
*
* A resurrected Game Object has its `alive`, `exists` and `visible` properties all set to true.
*
* It will dispatch the `onRevived` event. Listen to `events.onRevived` for the signal.
*
* @param health The health to give the Game Object. Only set if the GameObject has the Health component. - Default: 100
* @return This instance.
*/
revive(health?: number): Phaser.Sprite;
/**
* Sends this Game Object to the bottom of its 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.
*/
sendToBack(): Phaser.Sprite;
/**
* Sets the texture frame the Game Object uses for rendering.
*
* This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes.
*
* @param frame The Frame to be used by the texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Sets the scaleMin and scaleMax values. These values are used to limit how far this Game Object will scale based on its parent.
*
* For example if this Game Object has a `minScale` value of 1 and its parent has a `scale` value of 0.5, the 0.5 will be ignored
* and the scale value of 1 will be used, as the parents scale is lower than the minimum scale this Game Object should adhere to.
*
* By setting these values you can carefully control how Game Objects deal with responsive scaling.
*
* If only one parameter is given then that value will be used for both scaleMin and scaleMax:
* `setScaleMinMax(1)` = scaleMin.x, scaleMin.y, scaleMax.x and scaleMax.y all = 1
*
* If only two parameters are given the first is set as scaleMin.x and y and the second as scaleMax.x and y:
* `setScaleMinMax(0.5, 2)` = scaleMin.x and y = 0.5 and scaleMax.x and y = 2
*
* If you wish to set `scaleMin` with different values for x and y then either modify Game Object.scaleMin directly,
* or pass `null` for the `maxX` and `maxY` parameters.
*
* Call `setScaleMinMax(null)` to clear all previously set values.
*
* @param minX The minimum horizontal scale value this Game Object can scale down to.
* @param minY The minimum vertical scale value this Game Object can scale down to.
* @param maxX The maximum horizontal scale value this Game Object can scale up to.
* @param maxY The maximum vertical scale value this Game Object can scale up to.
*/
setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void;
/**
* Override this method in your own custom objects to handle any update requirements.
* It is called immediately after `preUpdate` and before `postUpdate`.
* Remember if this Game Object has any children you should call update on those too.
*/
update(): void;
/**
* If you have set a crop rectangle on this Game Object via `crop` and since modified the `cropRect` property,
* or the rectangle it references, then you need to update the crop frame by calling this method.
*/
updateCrop(): void;
}
/**
* The SpriteBatch class is a really fast version of the DisplayObjectContainer built purely for speed, so use when you need a lot of sprites or particles.
* It's worth mentioning that by default sprite batches are used through-out the renderer, so you only really need to use a SpriteBatch if you have over
* 1000 sprites that all share the same texture (or texture atlas). It's also useful if running in Canvas mode and you have a lot of un-rotated or un-scaled
* Sprites as it skips all of the Canvas setTransform calls, which helps performance, especially on mobile devices.
*
* Please note that any Sprite that is part of a SpriteBatch will not have its bounds updated, so will fail checks such as outOfBounds.
*/
class SpriteBatch extends Phaser.Group {
/**
* The SpriteBatch class is a really fast version of the DisplayObjectContainer built purely for speed, so use when you need a lot of sprites or particles.
* It's worth mentioning that by default sprite batches are used through-out the renderer, so you only really need to use a SpriteBatch if you have over
* 1000 sprites that all share the same texture (or texture atlas). It's also useful if running in Canvas mode and you have a lot of un-rotated or un-scaled
* Sprites as it skips all of the Canvas setTransform calls, which helps performance, especially on mobile devices.
*
* Please note that any Sprite that is part of a SpriteBatch will not have its bounds updated, so will fail checks such as outOfBounds.
*
* @param game A reference to the currently running game.
* @param parent The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If `undefined` or `null` it will use game.world.
* @param name A name for this Group. Not used internally but useful for debugging. - Default: group
* @param addToStage If set to true this Group will be added directly to the Game.Stage instead of Game.World.
*/
constructor(game: Phaser.Game, parent: PIXI.DisplayObjectContainer, name?: string, addedToStage?: boolean);
/**
* Internal Phaser Type value.
*/
type: number;
}
/**
* The Stage controls root level display objects upon which everything is displayed.
* It also handles browser visibility handling and the pausing due to loss of focus.
*/
class Stage extends PIXI.DisplayObjectContainer {
/**
* The Stage controls root level display objects upon which everything is displayed.
* It also handles browser visibility handling and the pausing due to loss of focus.
*
* @param game Game reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The name of this object.
* Default: _stage_root
*/
name: string;
/**
* By default if the browser tab loses focus the game will pause.
* You can stop that behavior by setting this property to true.
* Note that the browser can still elect to pause your game if it wishes to do so,
* for example swapping to another browser tab. This will cause the RAF callback to halt,
* effectively pausing your game, even though no in-game pause event is triggered if you enable this property.
*/
disableVisibilityChange: boolean;
/**
* If exists is true the Stage and all children are updated, otherwise it is skipped.
* Default: true
*/
exists: boolean;
/**
* Reset each frame, keeps a count of the total number of objects updated.
*/
currentRenderOrderID: number;
/**
* Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000'
*/
backgroundColor: any;
/**
* Enable or disable texture smoothing for all objects on this Stage. Only works for bitmap/image textures. Smoothing is enabled by default. Set to true to smooth all sprites rendered on this Stage, or false to disable smoothing (great for pixel art)
*/
smoothed: boolean;
/**
* Parses a Game configuration object.
*
* @param config The configuration object to parse.
*/
parseConfig(config: any): void;
/**
* This is called automatically after the plugins preUpdate and before the State.update.
* Most objects have preUpdate methods and it's where initial movement and positioning is done.
*/
preUpdate(): void;
/**
* This is called automatically after the State.update, but before particles or plugins update.
*/
update(): void;
/**
* This is called automatically before the renderer runs and after the plugins have updated.
* In postUpdate this is where all the final physics calculations and object positioning happens.
* The objects are processed in the order of the display list.
*/
postUpdate(): void;
/**
* Updates the transforms for all objects on the display list.
* This overrides the Pixi default as we don't need the interactionManager, but do need the game property check.
*/
updateTransform(): void;
/**
* Starts a page visibility event listener running, or window.onpagehide/onpageshow if not supported by the browser.
* Also listens for window.onblur and window.onfocus.
*/
checkVisibility(): void;
/**
* This method is called when the document visibility is changed.
*
* @param event Its type will be used to decide whether the game should be paused or not.
*/
visibilityChange(event: Event): void;
/**
* Sets the background color for the Stage.
*
* The color can be given as a hex string (`'#RRGGBB'`), a CSS color string (`'rgb(r,g,b)'`), or a numeric value (`0xRRGGBB`).
*
* An alpha channel is _not_ supported and will be ignored.
*
* If you've set your game to be transparent then calls to setBackgroundColor are ignored.
*
* @param color The color of the background.
*/
setBackgroundColor(backgroundColor: number | string): void;
/**
* Destroys the Stage and removes event listeners.
*/
destroy(): void;
}
interface ResizeCallback {
(scale: ScaleManager, parentBounds: Rectangle): any;
}
/**
* The ScaleManager object handles the the scaling, resizing, and alignment of the
* Game size and the game Display canvas.
*
* The Game size is the logical size of the game; the Display canvas has size as an HTML element.
*
* The calculations of these are heavily influenced by the bounding Parent size which is the computed
* dimensions of the Display canvas's Parent container/element - the _effective CSS rules of the
* canvas's Parent element play an important role_ in the operation of the ScaleManager.
*
* The Display canvas - or Game size, depending {@link Phaser.ScaleManager#scaleMode scaleMode} - is updated to best utilize the Parent size.
* When in Fullscreen mode or with {@link Phaser.ScaleManager#parentIsWindow parentIsWindow} the Parent size is that of the visual viewport (see {@link Phaser.ScaleManager#getParentBounds getParentBounds}).
*
* #### Parent and Display canvas containment guidelines:
*
* - Style the Parent element (of the game canvas) to control the Parent size and
* thus the Display canvas's size and layout.
*
* - The Parent element's CSS styles should _effectively_ apply maximum (and minimum) bounding behavior.
*
* - The Parent element should _not_ apply a padding as this is not accounted for.
* If a padding is required apply it to the Parent's parent or apply a margin to the Parent.
* If you need to add a border, margin or any other CSS around your game container, then use a parent element and
* apply the CSS to this instead, otherwise you'll be constantly resizing the shape of the game container.
*
* - The Display canvas layout CSS styles (i.e. margins, size) should not be altered/specified as
* they may be updated by the ScaleManager.
*
* #### Example Uses
*
* - ##### Fixed game size; scale canvas proportionally to fill its container
*
* Use `scaleMode` SHOW_ALL.
*
* - ##### Fixed game size; stretch canvas to fill its container (uncommon)
*
* Use `scaleMode` EXACT_FIT.
*
* - ##### Fixed game size; scale canvas proportionally by some other criteria
*
* Use `scaleMode` USER_SCALE. Examine `parentBounds` in the {@link #setResizeCallback resize callback} and call {@link Phaser.ScaleManager#setUserScale setUserScale} if necessary.
*
* - ##### Fluid game/canvas size
*
* Use `scaleMode` RESIZE. Examine the game or canvas size from the {@link Phaser.ScaleManager#onSizeChange onSizeChange} signal and reposition game objects if necessary.
*
* - ##### Preferred orientation
*
* Call {@link Phaser.ScaleManager#forceOrientation forceOrientation} with the preferred orientation and use any of the {@link Phaser.ScaleManager#onOrientationChange onOrientationChange}, {@link Phaser.ScaleManager#enterIncorrectOrientation enterIncorrectOrientation}, or {@link Phaser.ScaleManager#leaveIncorrectOrientation leaveIncorrectOrientation} signals.
*/
class ScaleManager {
/**
* Create a new ScaleManager object - this is done automatically by {@link Phaser.Game}
*
* The `width` and `height` constructor parameters can either be a number which represents pixels or a string that represents a percentage: e.g. `800` (for 800 pixels) or `"80%"` for 80%.
*
* @param game A reference to the currently running game.
* @param width The width of the game. See above.
* @param height The height of the game. See above.
*/
constructor(game: Phaser.Game, width: number | string, height: number | string);
/**
* A scale mode that stretches content to fill all available space - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
static EXACT_FIT: number;
/**
* A scale mode that prevents any scaling - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
static NO_SCALE: number;
/**
* A scale mode that shows the entire game while maintaining proportions - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
static SHOW_ALL: number;
/**
* A scale mode that causes the Game size to change - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
static RESIZE: number;
/**
* A scale mode that allows a custom scale factor - see {@link Phaser.ScaleManager#scaleMode scaleMode}.
*/
static USER_SCALE: number;
/**
* The aspect ratio of the scaled Display canvas.
*/
aspectRatio: number;
/**
* The bounds of the scaled game. The x/y will match the offset of the canvas element and the width/height the scaled width and height.
*/
bounds: Rectangle;
/**
* The DOM element that is considered the Parent bounding element, if any.
*
* This `null` if {@link Phaser.ScaleManager#parentIsWindow parentIsWindow} is true or if fullscreen mode is entered and {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget} is specified.
* It will also be null if there is no game canvas or if the game canvas has no parent.
*/
boundingParent: HTMLElement;
/**
* Various compatibility settings.
* A value of "(auto)" indicates the setting is configured based on device and runtime information.
*
* A {@link Phaser.ScaleManager#refresh refresh} may need to be performed after making changes.
*/
compatibility: {
canExpandParent: boolean;
clickTrampoline: string;
forceMinimumDocumentHeight: boolean;
noMargins: boolean;
orientationFallback: boolean;
scrollTo: Point;
supportsFullScreen: boolean;
};
/**
* Returns the current scale mode - for normal or fullscreen operation.
*
* See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed.
*/
currentScaleMode: number;
/**
* Provides access to some cross-device DOM functions.
*/
dom: Phaser.DOM;
/**
* This signal is dispatched when the browser enters an incorrect orientation, as defined by {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
enterIncorrectOrientation: Signal;
/**
* The native browser events from Fullscreen API changes.
*/
event: any;
/**
* If true, the game should only run in a landscape orientation.
* Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*/
forceLandscape: boolean;
/**
* If true, the game should only run in a portrait
* Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*/
forcePortrait: boolean;
/**
* The scaling method used by the ScaleManager when in fullscreen.
*
* See {@link Phaser.ScaleManager#scaleMode scaleMode} for the different modes allowed.
*/
fullScreenScaleMode: number;
/**
* If specified, this is the DOM element on which the Fullscreen API enter request will be invoked.
* The target element must have the correct CSS styling and contain the Display canvas.
*
* The elements style will be modified (ie. the width and height might be set to 100%)
* but it will not be added to, removed from, or repositioned within the DOM.
* An attempt is made to restore relevant style changes when fullscreen mode is left.
*
* For pre-2.2.0 behavior set `game.scale.fullScreenTarget = game.canvas`.
*/
fullScreenTarget: HTMLElement;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* _EXPERIMENTAL:_ A responsive grid on which you can align game objects.
*/
grid: Phaser.FlexGrid;
/**
* This boolean provides you with a way to determine if the browser is in Full Screen
* mode (via the Full Screen API), and Phaser was the one responsible for activating it.
*
* It's possible that ScaleManager.isFullScreen returns `true` even if Phaser wasn't the
* one that made the browser go full-screen, so this flag lets you determine that.
*/
hasPhaserSetFullScreen: boolean;
/**
* Target height (in pixels) of the Display canvas.
*/
height: number;
/**
* True if {@link Phaser.ScaleManager#forceLandscape forceLandscape} or {@link Phaser.ScaleManager#forcePortrait forcePortrait} are set and do not agree with the browser orientation.
*
* This value is not updated immediately.
*/
incorrectOrientation: boolean;
/**
* Returns true if the browser is in fullscreen mode, otherwise false.
*/
isFullScreen: boolean;
/**
* Returns true if the game dimensions are landscape (width > height).
* This is especially useful to check when using the RESIZE scale mode
* but wanting to maintain game orientation on desktop browsers,
* where typically the screen orientation will always be landscape regardless of the browser viewport.
*/
isGameLandscape: boolean;
/**
* Returns true if the game dimensions are portrait (height > width).
* This is especially useful to check when using the RESIZE scale mode
* but wanting to maintain game orientation on desktop browsers,
* where typically the screen orientation will always be landscape regardless of the browser viewport.
*/
isGamePortrait: boolean;
/**
* Returns true if the screen orientation is in portrait mode.
*/
isPortrait: boolean;
/**
* Returns true if the screen orientation is in landscape mode.
*/
isLandscape: boolean;
/**
* This signal is dispatched when the browser leaves an incorrect orientation, as defined by {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
leaveIncorrectOrientation: Signal;
/**
* The Display canvas is aligned by adjusting the margins; the last margins are stored here.
*/
margin: { left: number; top: number; right: number; bottom: number; x: number; y: number; };
/**
* Maximum height the canvas should be scaled to (in pixels).
* If null it will scale to whatever height the browser can handle.
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
maxHeight: number;
/**
* Maximum width the canvas should be scaled to (in pixels).
* If null it will scale to whatever width the browser can handle.
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
maxWidth: number;
/**
* Minimum height the canvas should be scaled to (in pixels).
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
minHeight: number;
/**
* Minimum width the canvas should be scaled to (in pixels).
* Change with {@link Phaser.ScaleManager#setMinMax setMinMax}.
*/
minWidth: number;
/**
* The offset coordinates of the Display canvas from the top-left of the browser window.
* The is used internally by Phaser.Pointer (for Input) and possibly other types.
*/
offset: Point;
/**
* This signal is dispatched when fullscreen mode is ready to be initialized but
* before the fullscreen request.
*
* The signal is passed two arguments: `scale` (the ScaleManager), and an object in the form `{targetElement: DOMElement}`.
*
* The `targetElement` is the {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget} element,
* if such is assigned, or a new element created by {@link Phaser.ScaleManager#createFullScreenTarget createFullScreenTarget}.
*
* Custom CSS styling or resets can be applied to `targetElement` as required.
*
* If `targetElement` is _not_ the same element as {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget}:
* - After initialization the Display canvas is moved onto the `targetElement` for
* the duration of the fullscreen mode, and restored to it's original DOM location when fullscreen is exited.
* - The `targetElement` is moved/re-parented within the DOM and may have its CSS styles updated.
*
* The behavior of a pre-assigned target element is covered in {@link Phaser.ScaleManager#fullScreenTarget fullScreenTarget}.
*/
onFullScreenInit: Phaser.Signal;
/**
* This signal is dispatched when the browser enters or leaves fullscreen mode, if supported.
*
* The signal is supplied with a single argument: `scale` (the ScaleManager). Use `scale.isFullScreen` to determine
* if currently running in Fullscreen mode.
*/
onFullScreenChange: Phaser.Signal;
/**
* This signal is dispatched when the browser fails to enter fullscreen mode;
* or if the device does not support fullscreen mode and `startFullScreen` is invoked.
*
* The signal is supplied with a single argument: `scale` (the ScaleManager).
*/
onFullScreenError: Phaser.Signal;
/**
* This signal is dispatched when the orientation changes _or_ the validity of the current orientation changes.
*
* The signal is supplied with the following arguments:
* - `scale` - the ScaleManager object
* - `prevOrientation`, a string - The previous orientation as per {@link Phaser.ScaleManager#screenOrientation screenOrientation}.
* - `wasIncorrect`, a boolean - True if the previous orientation was last determined to be incorrect.
*
* Access the current orientation and validity with `scale.screenOrientation` and `scale.incorrectOrientation`.
* Thus the following tests can be done:
*
* // The orientation itself changed:
* scale.screenOrientation !== prevOrientation
* // The orientation just became incorrect:
* scale.incorrectOrientation && !wasIncorrect
*
* It is possible that this signal is triggered after {@link Phaser.ScaleManager#forceOrientation forceOrientation} so the orientation
* correctness changes even if the orientation itself does not change.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
onOrientationChange: Phaser.Signal;
/**
* This signal is dispatched when the size of the Display canvas changes _or_ the size of the Game changes.
* When invoked this is done _after_ the Canvas size/position have been updated.
*
* The callback is supplied with three arguments: the Scale Manager, canvas {@link Phaser.ScaleManager#width width}, and canvas {@link Phaser.ScaleManager#height height}. (Game dimensions can be found in `scale.game.width` and `scale.game.height`.)
*
* This signal is _only_ called when a change occurs and a reflow may be required.
* For example, if the canvas does not change sizes because of CSS settings (such as min-width)
* then this signal will _not_ be triggered.
*
* Use this to handle responsive game layout options.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
onSizeChange: Signal;
/**
* When enabled the Display canvas will be horizontally-aligned _in the Parent container_ (or {@link Phaser.ScaleManager#parentIsWindow window}).
*
* To align horizontally across the page the Display canvas should be added directly to page;
* or the parent container should itself be horizontally aligned.
*
* Horizontal alignment is not applicable with the {@link Phaser.ScaleManager.RESIZE RESIZE} scaling mode.
* Default: false
*/
pageAlignHorizontally: boolean;
/**
* When enabled the Display canvas will be vertically-aligned _in the Parent container_ (or {@link Phaser.ScaleManager#parentIsWindow window}).
*
* To align vertically the Parent element should have a _non-collapsible_ height, such that it will maintain
* a height _larger_ than the height of the contained Game canvas - the game canvas will then be scaled vertically
* _within_ the remaining available height dictated by the Parent element.
*
* One way to prevent the parent from collapsing is to add an absolute "min-height" CSS property to the parent element.
* If specifying a relative "min-height/height" or adjusting margins, the Parent height must still be non-collapsible (see note).
*
* _Note_: In version 2.2 the minimum document height is _not_ automatically set to the viewport/window height.
* To automatically update the minimum document height set {@link Phaser.ScaleManager#compatibility compatibility.forceMinimumDocumentHeight} to true.
*
* Vertical alignment is not applicable with the {@link Phaser.ScaleManager.RESIZE RESIZE} scaling mode.
* Default: false
*/
pageAlignVertically: boolean;
/**
* The _original_ DOM element for the parent of the Display canvas.
* This may be different in fullscreen - see {@link Phaser.ScaleManager#createFullScreenTarget createFullScreenTarget}.
*
* This should only be changed after moving the Game canvas to a different DOM parent.
*/
parentNode: HTMLElement;
/**
* 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.
*/
parentIsWindow: boolean;
/**
* The scale of the game in relation to its parent container.
*/
parentScaleFactor: Point;
/**
* The _current_ scale factor based on the game dimensions vs. the scaled dimensions.
*/
scaleFactor: Point;
/**
* The _current_ inversed scale factor. The displayed dimensions divided by the game dimensions.
*/
scaleFactorInversed: Point;
/**
* The scaling method used by the ScaleManager when not in fullscreen.
*
*
* - {@link Phaser.ScaleManager.NO_SCALE}
* -
* The Game display area will not be scaled - even if it is too large for the canvas/screen.
* This mode _ignores_ any applied scaling factor and displays the canvas at the Game size.
*
* - {@link Phaser.ScaleManager.EXACT_FIT}
* -
* The Game display area will be _stretched_ to fill the entire size of the canvas's parent element and/or screen.
* Proportions are not maintained.
*
* - {@link Phaser.ScaleManager.SHOW_ALL}
* -
* Show the entire game display area while _maintaining_ the original aspect ratio.
*
* - {@link Phaser.ScaleManager.RESIZE}
* -
* The dimensions of the game display area are changed to match the size of the parent container.
* That is, this mode _changes the Game size_ to match the display size.
*
* Any manually set Game size (see {@link Phaser.ScaleManager#setGameSize setGameSize}) is ignored while in effect.
*
* - {@link Phaser.ScaleManager.USER_SCALE}
* -
* The game Display is scaled according to the user-specified scale set by {@link Phaser.ScaleManager#setUserScale setUserScale}.
*
* This scale can be adjusted in the {@link Phaser.ScaleManager#setResizeCallback resize callback}
* for flexible custom-sizing needs.
*
*
*/
scaleMode: number;
/**
* The _last known_ orientation of the screen, as defined in the Window Screen Web API.
* See {@link Phaser.DOM.getScreenOrientation} for possible values.
*/
screenOrientation: string;
/**
* The aspect ratio of the original game dimensions.
*/
sourceAspectRatio: number;
/**
* The maximum time (in ms) between dimension update checks for the Canvas's parent element (or window).
* Update checks normally happen quicker in response to other events.
* Default: 2000
*/
trackParentInterval: number;
/**
* Target width (in pixels) of the Display canvas.
*/
width: number;
/**
* The edges on which to constrain the game Display/canvas in _addition_ to the restrictions of the parent container.
*
* The properties are strings and can be '', 'visual', 'layout', or 'layout-soft'.
* - If 'visual', the edge will be constrained to the Window / displayed screen area
* - If 'layout', the edge will be constrained to the CSS Layout bounds
* - An invalid value is treated as 'visual'
* Default: {"right":"layout","bottom":""}
*/
windowConstraints: {
bottom: string;
right: string;
};
/**
* Start the ScaleManager.
*/
boot(): void;
/**
* Creates a fullscreen target. This is called automatically as as needed when entering
* fullscreen mode and the resulting element is supplied to {@link Phaser.ScaleManager#onFullScreenInit onFullScreenInit}.
*
* Use {@link Phaser.ScaleManager#onFullScreenInit onFullScreenInit} to customize the created object.
*/
createFullScreenTarget(): HTMLDivElement;
/**
* Destroys the ScaleManager and removes any event listeners.
* This should probably only be called when the game is destroyed.
*/
destroy(): void;
/**
* Force the game to run in only one orientation.
*
* This enables generation of incorrect orientation signals and affects resizing but does not otherwise rotate or lock the orientation.
*
* Orientation checks are performed via the Screen Orientation API, if available in browser. This means it will check your monitor
* orientation on desktop, or your device orientation on mobile, rather than comparing actual game dimensions. If you need to check the
* viewport dimensions instead and bypass the Screen Orientation API then set: `ScaleManager.compatibility.orientationFallback = 'viewport'`
*
* @param forceLandscape true if the game should run in landscape mode only.
* @param forcePortrait true if the game should run in portrait mode only.
*/
forceOrientation(forceLandscape: boolean, forcePortrait?: boolean): void;
/**
* Returns the computed Parent size/bounds that the Display canvas is allowed/expected to fill.
*
* If in fullscreen mode or without parent (see {@link Phaser.ScaleManager#parentIsWindow parentIsWindow}),
* this will be the bounds of the visual viewport itself.
*
* This function takes the {@link Phaser.ScaleManager#windowConstraints windowConstraints} into consideration - if the parent is partially outside
* the viewport then this function may return a smaller than expected size.
*
* Values are rounded to the nearest pixel.
*
* @param target The rectangle to update; a new one is created as needed. - Default: (new Rectangle)
* @return The established parent bounds.
*/
getParentBounds(target?: Rectangle): Rectangle;
/**
* Load configuration settings.
*
* @param config The game configuration object.
*/
parseConfig(config: any): void;
/**
* The ScaleManager.preUpdate is called automatically by the core Game loop.
*/
preUpdate(): void;
/**
* Update method while paused.
*/
pauseUpdate(): void;
/**
* The "refresh" methods informs the ScaleManager that a layout refresh is required.
*
* The ScaleManager automatically queues a layout refresh (eg. updates the Game size or Display canvas layout)
* when the browser is resized, the orientation changes, or when there is a detected change
* of the Parent size. Refreshing is also done automatically when public properties,
* such as {@link Phaser.ScaleManager#scaleMode scaleMode}, are updated or state-changing methods are invoked.
*
* The "refresh" method _may_ need to be used in a few (rare) situtations when
*
* - a device change event is not correctly detected; or
* - the Parent size changes (and an immediate reflow is desired); or
* - the ScaleManager state is updated by non-standard means; or
* - certain {@link Phaser.ScaleManager#compatibility compatibility} properties are manually changed.
*
* The queued layout refresh is not immediate but will run promptly in an upcoming `preRender`.
*/
refresh(): void;
/**
* Set the actual Game size.
* Use this instead of directly changing `game.width` or `game.height`.
*
* The actual physical display (Canvas element size) depends on various settings including
* - Scale mode
* - Scaling factor
* - Size of Canvas's parent element or CSS rules such as min-height/max-height;
* - The size of the Window
*
* @param width _Game width_, in pixels.
* @param height _Game height_, in pixels.
*/
setGameSize(width: number, height: number): void;
/**
* Sets the callback that will be invoked before sizing calculations.
*
* Typically this is triggered when the Scale Manager has detected a change to the canvas's boundaries:
* the browser window has been resized, the device has been rotated, or the parent container's size has changed.
* At this point the Scale Manager has not resized the game or canvas yet (and may not resize them at all
* after it makes its sizing calculations). You can read the size of the parent container from the
* `parentBounds` argument to the callback.
*
* This is the appropriate place to call {@link Phaser.ScaleManager#setUserScale setUserScale} if needing custom dynamic scaling.
*
* The callback is supplied with two arguments `scale` and `parentBounds` where `scale` is the ScaleManager
* and `parentBounds`, a Phaser.Rectangle, is the size of the Parent element.
*
* This callback
* - May be invoked even though the parent container or canvas sizes have not changed
* - Unlike {@link Phaser.ScaleManager#onSizeChange onSizeChange}, it runs _before_ the canvas is guaranteed to be updated
* - Will be invoked from `preUpdate`, _even when_ the game is paused
*
* See {@link Phaser.ScaleManager#onSizeChange onSizeChange} for a better way of reacting to layout updates.
*
* @param callback The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
* @param context The context in which the callback will be called.
*/
setResizeCallback(callback: ResizeCallback, context: any): void;
/**
* Set a User scaling factor used in the USER_SCALE scaling mode.
*
* The target canvas size is computed by:
*
* canvas.width = (game.width * hScale) - hTrim
* canvas.height = (game.height * vScale) - vTrim
*
* This method can be used in the {@link Phaser.ScaleManager#setResizeCallback resize callback}. Set `queueUpdate` and `force` to false if the resize callback is being called repeatedly.
*
* @param hScale Horizontal scaling factor.
* @param vScale Vertical scaling factor.
* @param hTrim Horizontal trim, applied after scaling.
* @param vTrim Vertical trim, applied after scaling.
* @param queueUpdate Queue a size/bounds check at next preUpdate - Default: true
* @param force Force a resize during the next preUpdate - Default: true
*/
setUserScale(hScale: number, vScale: number, hTrim?: number, vTrim?: number, queueUpdate?: boolean, force?: boolean): void;
/**
* Set the min and max dimensions for the Display canvas.
*
* _Note:_ The min/max dimensions are only applied in some cases
* - When the device is not in an incorrect orientation; or
* - The scale mode is EXACT_FIT when not in fullscreen
*
* @param minWidth The minimum width the game is allowed to scale down to.
* @param minHeight The minimum height the game is allowed to scale down to.
* @param maxWidth The maximum width the game is allowed to scale up to; only changed if specified.
* @param maxHeight The maximum height the game is allowed to scale up to; only changed if specified.
*/
setMinMax(minWidth: number, minHeight: number, maxWidth?: number, maxHeight?: number): void;
/**
* Calculates and sets the game dimensions based on the given width and height.
*
* This should _not_ be called when in fullscreen mode.
*
* @param width The width of the game.
* @param height The height of the game.
*/
setupScale(width: number, height: number): void;
/**
* Calculates and sets the game dimensions based on the given width and height.
*
* This should _not_ be called when in fullscreen mode.
*
* @param width The width of the game.
* @param height The height of the game.
*/
setupScale(width: string, height: string): void;
/**
* Takes a Sprite or Image object and scales it to fit the given dimensions.
* Scaling happens proportionally without distortion to the sprites texture.
* The letterBox parameter controls if scaling will produce a letter-box effect or zoom the
* sprite until it fills the given values. Note that with letterBox set to false the scaled sprite may spill out over either
* the horizontal or vertical sides of the target dimensions. If you wish to stop this you can crop the Sprite.
*
* @param sprite The sprite we want to scale.
* @param width The target width that we want to fit the sprite in to. If not given it defaults to ScaleManager.width.
* @param height The target height that we want to fit the sprite in to. If not given it defaults to ScaleManager.height.
* @param letterBox True if we want the `fitted` mode. Otherwise, the function uses the `zoom` mode.
* @return The scaled sprite.
*/
scaleSprite(sprite: Sprite, width?: number, height?: number, letterBox?: boolean): Sprite;
/**
* Takes a Sprite or Image object and scales it to fit the given dimensions.
* Scaling happens proportionally without distortion to the sprites texture.
* The letterBox parameter controls if scaling will produce a letter-box effect or zoom the
* sprite until it fills the given values. Note that with letterBox set to false the scaled sprite may spill out over either
* the horizontal or vertical sides of the target dimensions. If you wish to stop this you can crop the Sprite.
*
* @param sprite The sprite we want to scale.
* @param width The target width that we want to fit the sprite in to. If not given it defaults to ScaleManager.width.
* @param height The target height that we want to fit the sprite in to. If not given it defaults to ScaleManager.height.
* @param letterBox True if we want the `fitted` mode. Otherwise, the function uses the `zoom` mode.
* @return The scaled sprite.
*/
scaleSprite(sprite: Image, width?: number, height?: number, letterBox?: boolean): Sprite;
/**
* 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.)
*/
startFullScreen(antialias?: boolean, allowTrampoline?: boolean): boolean;
/**
* Stops / exits fullscreen mode, if active.
* @return Returns true if the browser supports fullscreen mode and fullscreen mode will be exited.
*/
stopFullScreen(): boolean;
}
/**
* DOM utility class.
*
* Provides a useful Window and Element functions as well as cross-browser compatibility buffer.
*
* Some code originally derived from {@link https://github.com/ryanve/verge verge}.
* Some parts were inspired by the research of Ryan Van Etten, released under MIT License 2013.
*/
class DOM {
/**
* The bounds of the Visual viewport, as discussed in
* {@link http://www.quirksmode.org/mobile/viewports.html A tale of two viewports — part one}
* with one difference: the viewport size _excludes_ scrollbars, as found on some desktop browsers.
*
* Supported mobile:
* iOS/Safari, Android 4, IE10, Firefox OS (maybe not Firefox Android), Opera Mobile 16
*
* The properties change dynamically.
*/
static visualBounds: Phaser.Rectangle;
/**
* The bounds of the Layout viewport, as discussed in
* {@link http://www.quirksmode.org/mobile/viewports2.html A tale of two viewports — part two};
* but honoring the constraints as specified applicable viewport meta-tag.
*
* The bounds returned are not guaranteed to be fully aligned with CSS media queries (see
* {@link http://www.matanich.com/2013/01/07/viewport-size/ What size is my viewport?}).
*
* This is _not_ representative of the Visual bounds: in particular the non-primary axis will
* generally be significantly larger than the screen height on mobile devices when running with a
* constrained viewport.
*
* The properties change dynamically.
*/
static layoutBounds: Phaser.Rectangle;
/**
* The size of the document / Layout viewport.
*
* This incorrectly reports the dimensions in IE.
*
* The properties change dynamically.
*/
static documentBounds: Phaser.Rectangle;
/**
* Calibrates element coordinates for `inLayoutViewport` checks.
*
* @param coords An object containing the following properties: `{top: number, right: number, bottom: number, left: number}`
* @param cushion A value to adjust the coordinates by.
* @return The calibrated element coordinates
*/
static calibrate(coords: any, cushion?: number): any;
/**
* Get the Visual viewport aspect ratio (or the aspect ratio of an object or element)
*
* @param object The object to determine the aspect ratio for. Must have public `width` and `height` properties or methods. - Default: (visualViewport)
* @return The aspect ratio.
*/
static getAspectRatio(object: any): number;
/**
* Returns the device screen orientation.
*
* Orientation values: 'portrait-primary', 'landscape-primary', 'portrait-secondary', 'landscape-secondary'.
*
* Order of resolving:
* - Screen Orientation API, or variation of - Future track. Most desktop and mobile browsers.
* - Screen size ratio check - If fallback is 'screen', suited for desktops.
* - Viewport size ratio check - If fallback is 'viewport', suited for mobile.
* - window.orientation - If fallback is 'window.orientation', works iOS and probably most Android; non-recommended track.
* - Media query
* - Viewport size ratio check (probably only IE9 and legacy mobile gets here..)
*
* See
* - https://w3c.github.io/screen-orientation/ (conflicts with mozOrientation/msOrientation)
* - https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation (mozOrientation)
* - http://msdn.microsoft.com/en-us/library/ie/dn342934(v=vs.85).aspx
* - https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Testing_media_queries
* - http://stackoverflow.com/questions/4917664/detect-viewport-orientation
* - http://www.matthewgifford.com/blog/2011/12/22/a-misconception-about-window-orientation
*
* @param primaryFallback Specify 'screen', 'viewport', or 'window.orientation'. - Default: (none)
*/
static getScreenOrientation(primaryFallback?: string): string;
/**
* A cross-browser element.getBoundingClientRect method with optional cushion.
*
* Returns a plain object containing the properties `top/bottom/left/right/width/height` with respect to the top-left corner of the current viewport.
* Its properties match the native rectangle.
* The cushion parameter is an amount of pixels (+/-) to cushion the element.
* It adjusts the measurements such that it is possible to detect when an element is near the viewport.
*
* @param element The element or stack (uses first item) to get the bounds for.
* @param cushion A +/- pixel adjustment amount.
* @return A plain object containing the properties `top/bottom/left/right/width/height` or `false` if a non-valid element is given.
*/
static getBounds(element: any, cushion?: number): any;
/**
* Get the [absolute] position of the element relative to the Document.
*
* The value may vary slightly as the page is scrolled due to rounding errors.
*
* @param element The targeted element that we want to retrieve the offset.
* @param point The point we want to take the x/y values of the offset.
* @return - A point objet with the offsetX and Y as its properties.
*/
static getOffset(element: any, point?: Point): Point;
/**
* Tests if the given DOM element is within the Layout viewport.
*
* The optional cushion parameter allows you to specify a distance.
*
* inLayoutViewport(element, 100) is `true` if the element is in the viewport or 100px near it.
* inLayoutViewport(element, -100) is `true` if the element is in the viewport or at least 100px near it.
*
* @param element The DOM element to check. If no element is given it defaults to the Phaser game canvas.
* @param cushion The cushion allows you to specify a distance within which the element must be within the viewport.
* @return True if the element is within the viewport, or within `cushion` distance from it.
*/
static inLayoutViewport(element: any, cushion?: number): boolean;
}
/**
* This is a base State class which can be extended if you are creating your own game.
* It provides quick access to common functions such as the camera, cache, input, match, sound and more.
*
* #### Callbacks
*
* | start | preload | loaded | paused | stop |
* |-------|-------------|------------|--------------|----------|
* | init | | | | |
* | | preload | create | paused | |
* | | loadUpdate* | update* | pauseUpdate* | |
* | | | preRender* | | |
* | | loadRender* | render* | pauseRender* | |
* | | | | resumed | |
* | | | | | shutdown |
*
* Update and render calls (*) are repeated.
*/
class State {
/**
* A reference to the GameObjectFactory which can be used to add new objects to the World.
*/
add: Phaser.GameObjectFactory;
/**
* A reference to the game cache which contains any loaded or generated assets, such as images, sound and more.
*/
cache: Phaser.Cache;
/**
* A handy reference to World.camera.
*/
camera: Phaser.Camera;
/**
* This is a reference to the currently running Game.
*/
game: Phaser.Game;
/**
* A reference to the Input Manager.
*/
input: Phaser.Input;
/**
* The string based identifier given to the State when added into the State Manager.
*/
key: string;
/**
* A reference to the Loader, which you mostly use in the preload method of your state to load external assets.
*/
load: Phaser.Loader;
/**
* A reference to the GameObjectCreator which can be used to make new objects.
*/
make: Phaser.GameObjectCreator;
/**
* The Particle Manager. It is called during the core gameloop and updates any Particle Emitters it has created.
*/
particles: Phaser.Particles;
/**
* A reference to the physics manager which looks after the different physics systems available within Phaser.
*/
physics: Phaser.Physics;
/**
* A reference to the seeded and repeatable random data generator.
*/
rnd: Phaser.RandomDataGenerator;
/**
* A reference to the Scale Manager which controls the way the game scales on different displays.
*/
scale: Phaser.ScaleManager;
/**
* A reference to the Sound Manager which can create, play and stop sounds, as well as adjust global volume.
*/
sound: Phaser.SoundManager;
/**
* A reference to the Stage.
*/
stage: Phaser.Stage;
/**
* A reference to the State Manager, which controls state changes.
*/
state: Phaser.StateManager;
/**
* A reference to the game clock and timed events system.
*/
time: Phaser.Time;
/**
* A reference to the tween manager.
*/
tweens: Phaser.TweenManager;
/**
* A reference to the game world. All objects live in the Game World and its size is not bound by the display resolution.
*/
world: Phaser.World;
/**
* create is called once preload has completed, this includes the loading of any assets from the Loader.
* If you don't have a preload method then create is the first method called in your State.
*/
create(): void;
/**
* init is the very first function called when your State starts up. It's called before preload, create or anything else.
* If you need to route the game away to another State you could do so here, or if you need to prepare a set of variables
* or objects before the preloading starts.
*/
init(...args: any[]): void;
/**
* loadRender is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.
* The difference between loadRender and render is that any objects you render in this method you must be sure their assets exist.
*/
loadRender(): void;
/**
* loadUpdate is called during the Loader process. This only happens if you've set one or more assets to load in the preload method.
*/
loadUpdate(): void;
/**
* This method will be called if the core game loop is paused.
*/
paused(): void;
/**
* pauseUpdate is called while the game is paused instead of preUpdate, update and postUpdate.
*/
pauseUpdate(): void;
/**
* preload is called first. Normally you'd use this to load your game assets (or those needed for the current State)
* You shouldn't create any objects in this method that require assets that you're also loading in this method, as
* they won't yet be available.
*/
preload(): void;
/**
* The preRender method is called after all Game Objects have been updated, but before any rendering takes place.
*/
preRender(): void;
/**
* Nearly all display objects in Phaser render automatically, you don't need to tell them to render.
* However the render method is called AFTER the game renderer and plugins have rendered, so you're able to do any
* final post-processing style effects here. Note that this happens before plugins postRender takes place.
*/
render(): void;
/**
* If your game is set to Scalemode RESIZE then each time the browser resizes it will call this function, passing in the new width and height.
*/
resize(): void;
/**
* This method will be called when the core game loop resumes from a paused state.
*/
resumed(): void;
/**
* This method will be called when the State is shutdown (i.e. you switch to another state from this one).
*/
shutdown(): void;
/**
* The update method is left empty for your own use.
* It is called during the core game loop AFTER debug, physics, plugins and the Stage have had their preUpdate methods called.
* It is called BEFORE Stage, Tweens, Sounds, Input, Physics, Particles and Plugins have had their postUpdate methods called.
*/
update(): void;
}
interface IStateCycle {
preUpdate(): void;
update(): void;
render(): void;
postRender(): void;
destroy(): void;
}
/**
* The State Manager is responsible for loading, setting up and switching game states.
*/
class StateManager {
/**
* The State Manager is responsible for loading, setting up and switching game states.
*
* @param game A reference to the currently running game.
* @param pendingState A State object to seed the manager with.
*/
constructor(game: Phaser.Game, pendingState?: Phaser.State);
/**
* True if the current state has had its `create` method run (if it has one, if not this is true by default).
*/
created: boolean;
/**
* The current active State object.
*/
current: string;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* This is called when the state preload has finished and creation begins.
*/
onCreateCallback: Function;
/**
* This is called when the state is set as the active state.
*/
onInitCallback: Function;
/**
* This is called when the State is rendered during the preload phase.
*/
onLoadRenderCallback: Function;
/**
* This is called when the State is updated during the preload phase.
*/
onLoadUpdateCallback: Function;
/**
* This is called when the game is paused.
*/
onPausedCallback: Function;
/**
* This is called every frame while the game is paused.
*/
onPauseUpdateCallback: Function;
/**
* This is called when the state starts to load assets.
*/
onPreloadCallback: Function;
/**
* This is called before the state is rendered and before the stage is cleared but after all game objects have had their final properties adjusted.
*/
onPreRenderCallback: Function;
/**
* This is called post-render. It doesn't happen during preload (see onLoadRenderCallback).
*/
onRenderCallback: Function;
/**
* This is called when the game is resumed from a paused state.
*/
onResumedCallback: Function;
/**
* This is called if ScaleManager.scalemode is RESIZE and a resize event occurs. It's passed the new width and height.
*/
onResizeCallback: Function;
/**
* This is called when the state is shut down (i.e. swapped to another state).
*/
onShutDownCallback: Function;
/**
* This is called when the state is updated, every game loop. It doesn't happen during preload (@see onLoadUpdateCallback).
*/
onUpdateCallback: Function;
/**
* The object containing Phaser.States.
*/
states: any;
/**
* onStateChange is a Phaser.Signal that is dispatched whenever the game changes state.
*
* It is dispatched only when the new state is started, which isn't usually at the same time as StateManager.start
* is called because state swapping is done in sync with the game loop. It is dispatched *before* any of the new states
* methods (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.
*/
onStateChange: Phaser.Signal;
/**
* Adds a new State into the StateManager. You must give each State a unique key by which you'll identify it.
* The State can be 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.
*/
add(key: string, state: any, autoStart?: boolean): void;
/**
* Checks if a given phaser state is valid. A State is considered valid if it has at least one of the core functions: preload, create, update or render.
*
* @param key The key of the state you want to check.
* @return true if the State has the required functions, otherwise false.
*/
checkState(key: string): boolean;
/**
* This method clears the current State, calling its shutdown callback. The process also removes any active tweens,
* resets the camera, resets input, clears physics, removes timers and if set clears the world and cache too.
*/
clearCurrentState(): void;
/**
* Removes all StateManager callback references to the State object, nulls the game reference and clears the States object.
* You don't recover from this without rebuilding the Phaser instance again.
*/
destroy(): void;
/**
* Gets the current State.
*/
getCurrentState(): Phaser.State;
/**
* Links game properties to the State given by the key.
*
* @param key State key.
*/
link(key: string): void;
loadComplete(): void;
/**
*
*
* @param elapsedTime The time elapsed since the last update.
*/
preRender(elapsedTime: number): void;
/**
* preUpdate is called right at the start of the game loop. It is responsible for changing to a new state that was requested previously.
*/
preUpdate(): void;
render(): void;
/**
* Delete the given state.
*
* @param key A unique key you use to reference this state, i.e. "MainMenu", "Level1".
*/
remove(key: string): void;
resume(): void;
/**
* Restarts the current State. State.shutDown will be called (if it exists) before the State is restarted.
*
* @param clearWorld Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly) - Default: true
* @param clearCache Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well.
* @param args Additional parameters that will be passed to the State.init function if it has one.
*/
restart(clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void;
resize(width: number, height: number): void;
/**
* Start the given State. If a State is already running then State.shutDown will be called (if it exists) before switching to the new State.
*
* @param key The key of the state you want to start.
* @param clearWorld Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly) - Default: true
* @param clearCache Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well.
* @param args Additional parameters that will be passed to the State.init function (if it has one).
*/
start(key: string, clearWorld?: boolean, clearCache?: boolean, ...args: any[]): void;
update(): void;
/**
* Nulls all State level Phaser properties, including a reference to Game.
*
* @param key State key.
*/
unlink(key: string): void;
}
interface PhaserTextStyle {
font?: string;
fill?: any;
align?: string;
stroke?: string;
strokeThickness?: number;
wordWrap?: boolean;
wordWrapWidth?: number;
maxLines?: number;
shadowOffsetX?: number;
shadowOffsetY?: number;
shadowColor?: string;
shadowBlur?: number;
valign?: string;
tab?: number;
tabs?: number;
fontSize?: number;
fontStyle?: string;
fontVariant?: string;
fontWeight?: string | number;
backgroundColor?: string;
boundsAlignH?: string;
boundsAlignV?: string;
}
/**
* Create a new game object for displaying Text.
*
* This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view.
* Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded.
*
* See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts across mobile browsers.
*/
class Text extends Phaser.Sprite {
/**
* Create a new game object for displaying Text.
*
* This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view.
* Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded.
*
* See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts across mobile browsers.
*
* @param game Current game instance.
* @param x X position of the new text object.
* @param y Y position of the new text object.
* @param text The actual text that will be written.
* @param style The style properties to be set on the Text.
* @param style.font The style and size of the font. - Default: 'bold 20pt Arial'
* @param style.fontStyle The style of the font (eg. 'italic'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontVariant The variant of the font (eg. 'small-caps'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontWeight The weight of the font (eg. 'bold'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontSize The size of the font (eg. 32 or '32px'): overrides the value in `style.font`. - Default: (from font)
* @param style.backgroundColor A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable.
* @param style.fill A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. - Default: 'black'
* @param style.align Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that). - Default: 'left'
* @param style.boundsAlignH Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'. - Default: 'left'
* @param style.boundsAlignV Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'. - Default: 'top'
* @param style.stroke A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'. - Default: 'black'
* @param style.strokeThickness A number that represents the thickness of the stroke. Default is 0 (no stroke).
* @param style.wordWrap Indicates if word wrap should be used.
* @param style.wordWrapWidth The width in pixels at which text will wrap. - Default: 100
* @param style.maxLines The maximum number of lines to be shown for wrapped text.
* @param style.tabs The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.
*/
constructor(game: Phaser.Game, x: number, y: number, text: string, style?: PhaserTextStyle);
static fontPropertiesCanvas: any;
static fontPropertiesContext: any;
static fontPropertiesCache: any;
/**
* Controls the horizontal alignment for multiline text.
* Can be: 'left', 'center' or 'right'.
* Does not affect single lines of text. For that please see `setTextBounds`.
*/
align: string;
/**
* The angle property is the rotation of the Game Object in *degrees* from its original orientation.
*
* Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
*
* Values outside this range are added to or subtracted from 360 to obtain a value within the range.
* For example, the statement player.angle = 450 is the same as player.angle = 90.
*
* If you wish to work in radians instead of degrees you can use the property `rotation` instead.
* Working in radians is slightly faster as it doesn't have to perform any calculations.
*/
angle: number;
/**
* Should the linePositionX and Y values be automatically rounded before rendering the Text?
* You may wish to enable this if you want to remove the effect of sub-pixel aliasing from text.
*/
autoRound: boolean;
/**
* Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'.
*/
boundsAlignH: string;
/**
* Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'.
*/
boundsAlignV: string;
/**
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
*
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
*/
cameraOffset: Phaser.Point;
/**
* The canvas element that the text is rendered.
*/
canvas: HTMLCanvasElement;
/**
* An array of the color values as specified by {@link Phaser.Text#addColor addColor}.
*/
colors: string[];
/**
* The context of the canvas element that the text is rendered to.
*/
context: CanvasRenderingContext2D;
/**
* Change the font used.
*
* This is equivalent of the `font` property specified to {@link Phaser.Text#setStyle setStyle}, except
* that unlike using `setStyle` this will not change any current font fill/color settings.
*
* The CSS font string can also be individually altered with the `font`, `fontSize`, `fontWeight`, `fontStyle`, and `fontVariant` properties.
*/
cssFont: string;
/**
* As a Game Object runs through its destroy method this flag is set to true,
* and can be checked in any sub-systems or plugins it is being destroyed from.
*/
destroyPhase: boolean;
/**
* All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this
* Game Object, or any of its components.
*/
events: Phaser.Events;
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}).
* Default: true
*/
exists: boolean;
/**
* A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
*/
fill: any;
/**
* A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
* are stored in the `cameraOffset` property, which is initialized with the current object coordinates.
*
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
*
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
* regardless where in the world the camera is.
*
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
*
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
*/
fixedToCamera: boolean;
/**
* Change the font family that the text will be rendered in, such as 'Arial'.
*
* Multiple CSS font families and generic fallbacks can be specified as long as
* {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-family CSS font-family rules} are followed.
*
* To change the entire font string use {@link Phaser.Text#cssFont cssFont} instead: eg. `text.cssFont = 'bold 20pt Arial'`.
*/
font: string;
/**
* The size of the font.
*
* If the font size is specified in pixels (eg. `32` or `'32px`') then a number (ie. `32`) representing
* the font size in pixels is returned; otherwise the value with CSS unit is returned as a string (eg. `'12pt'`).
*/
fontSize: number | string;
/**
* The style of the font: 'normal', 'italic', 'oblique'
*/
fontStyle: string;
/**
* An array of the font styles values as specified by {@link Phaser.Text#addFontStyle addFontStyle}.
*/
fontStyles: string[];
/**
* The variant the font: 'normal', 'small-caps'
*/
fontVariant: string;
/**
* The weight of the font: 'normal', 'bold', or {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-weight a valid CSS font weight}.
*/
fontWeight: string | number;
/**
* An array of the font weights values as specified by {@link Phaser.Text#addFontWeight addFontWeight}.
*/
fontWeights: (string | number)[];
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The Input Handler for this Game Object.
*
* By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`.
*
* After you have done this, this property will be a reference to the Phaser InputHandler.
*/
input: Phaser.InputHandler;
/**
* By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created
* for this Game Object and it will then start to process click / touch events and more.
*
* You can then access the Input Handler via `this.input`.
*
* Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`.
*
* If you set this property to false it will stop the Input Handler from processing any more input events.
*
* If you want to _temporarily_ disable input for a Game Object, then it's better to set
* `input.enabled = false`, as it won't reset any of the Input Handlers internal properties.
* You can then toggle this back on as needed.
*/
inputEnabled: boolean;
/**
* Additional spacing (in pixels) between each line of text if multi-line.
*/
lineSpacing: number;
/**
* A user defined name given to this Game Object.
* This value isn't ever used internally by Phaser, it is meant as a game level property.
*/
name: string;
/**
* Specify a padding value which is added to the line width and height when calculating the Text size.
* ALlows you to add extra spacing if Phaser is unable to accurately determine the true font dimensions.
*/
padding: Phaser.Point;
/**
* A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
* You can set it directly to allow you to flag an object to be destroyed on its next update.
*
* This is extremely useful if you wish to destroy an object from within one of its own callbacks
* such as with Buttons or other Input events.
*/
pendingDestroy: boolean;
/**
* The const physics body type of this object.
*/
physicsType: number;
/**
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
*
* The value of this property does not reflect any positioning happening further up the display list.
* To obtain that value please see the `worldPosition` property.
*/
position: Phaser.Point;
/**
* The position the Game Object was located in the previous frame.
*/
previousPosition: Phaser.Point;
/**
* The rotation the Game Object was in set to in the previous frame. Value is in radians.
*/
previousRotation: number;
/**
* The render order ID is used internally by the renderer and Input Manager and should not be modified.
* This property is mostly used internally by the renderers, but is exposed for the use of plugins.
*/
renderOrderID: number;
/**
* The resolution of the canvas the text is rendered to.
* This defaults to match the resolution of the renderer, but can be changed on a per Text object basis.
*/
resolution: number;
/**
* The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene).
*/
shadowBlur: number;
/**
* The color of the shadow, as given in CSS rgba format. Set the alpha component to 0 to disable the shadow.
*/
shadowColor: string;
/**
* Sets if the drop shadow is applied to the Text fill.
*/
shadowFill: boolean;
/**
* The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
*/
shadowOffsetX: number;
/**
* The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
*/
shadowOffsetY: number;
/**
* Sets if the drop shadow is applied to the Text stroke.
*/
shadowStroke: boolean;
/**
* The Regular Expression that is used to split the text up into lines, in
* multi-line text. By default this is `/(?:\r\n|\r|\n)/`.
* You can change this RegExp to be anything else that you may need.
*/
splitRegExp: any;
/**
* A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'.
*/
stroke: string;
/**
* An array of the stroke color values as specified by {@link Phaser.Text#addStrokeColor addStrokeColor}.
*/
strokeColors: string[];
/**
* A number that represents the thickness of the stroke. Default is 0 (no stroke)
*/
strokeThickness: number;
/**
* The scale of this DisplayObject. A scale of 1:1 represents the DisplayObject
* at its default size. A value of 0.5 would scale this DisplayObject by half, and so on.
*
* The value of this property does not reflect any scaling happening further up the display list.
* To obtain that value please see the `worldScale` property.
*/
scale: Phaser.Point;
tab: number;
/**
* The size (in pixels) of the tabs, for when text includes tab characters. 0 disables.
* Can be an integer or an array of varying tab sizes, one tab per element.
* For example if you set tabs to 100 then when Text encounters a tab it will jump ahead 100 pixels.
* If you set tabs to be `[100,200]` then it will set the first tab at 100px and the second at 200px.
*/
tabs: number | number[];
/**
* The text to be displayed by this Text object.
* Use a \n to insert a carriage return and split the text.
* The text will be rendered with any style currently set.
*/
text: string;
/**
* The textBounds property allows you to specify a rectangular region upon which text alignment is based.
* See `Text.setTextBounds` for more details.
*/
textBounds: Phaser.Rectangle;
/**
* The const type of this object.
*/
type: number;
/**
* Will this Text object use Basic or Advanced Word Wrapping?
*
* Advanced wrapping breaks long words if they are the first of a line, and repeats the process as necessary.
* White space is condensed (e.g., consecutive spaces are replaced with one).
* Lines are trimmed of white space before processing.
*
* It throws an error if wordWrapWidth is less than a single character.
*/
useAdvancedWrap: boolean;
/**
* The world coordinates of this Game Object in pixels.
* Depending on where in the display list this Game Object is placed this value can differ from `position`,
* which contains the x/y coordinates relative to the Game Objects parent.
*/
world: Phaser.Point;
/**
* Indicates if word wrap should be used.
*/
wordWrap: boolean;
/**
* The width at which text will wrap.
*/
wordWrapWidth: number;
/**
* The z depth of this Game Object within its parent Group.
* No two objects in a Group can have the same z value.
* This value is adjusted automatically whenever the Group hierarchy changes.
* If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.
*/
z: number;
/**
* Set specific colors for certain characters within the Text.
*
* It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position.
* The position value is the index of the character in the Text string to start applying this color to.
* Once set the color remains in use until either another color or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow.
*
* If you wish to change the stroke color see addStrokeColor instead.
*
* @param color A canvas fillstyle that will be used on the text eg `red`, `#00FF00`, `rgba()`.
* @param position The index of the character in the string to start applying this color value from.
* @return This Text instance.
*/
addColor(color: string, position: number): Phaser.Text;
/**
* Set specific font styles for certain characters within the Text.
*
* It works by taking a font style value, which is a typical string such as `normal`, `italic` or `oblique`.
* The position value is the index of the character in the Text string to start applying this font style to.
* Once set the font style remains in use until either another font style or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addFontStyle('italic', 6)` it would font style in the word `Storm` in italic.
*
* If you wish to change the text font weight see addFontWeight instead.
*
* @param style A canvas font-style that will be used on the text style eg `normal`, `italic`, `oblique`.
* @param position The index of the character in the string to start applying this font style value from.
* @return This Text instance.
*/
addFontStyle(style: string, position: number): Phaser.Text;
/**
* Set specific font weights for certain characters within the Text.
*
* It works by taking a font weight value, which is a typical string such as `normal`, `bold`, `bolder`, etc.
* The position value is the index of the character in the Text string to start applying this font weight to.
* Once set the font weight remains in use until either another font weight or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addFontWeight('bold', 6)` it would font weight in the word `Storm` in bold.
*
* If you wish to change the text font style see addFontStyle instead.
*
* @param style A canvas font-weight that will be used on the text weight eg `normal`, `bold`, `bolder`, `lighter`, etc.
* @param position The index of the character in the string to start applying this font weight value from.
* @return This Text instance.
*/
addFontWeight(weight: string, position: number): Phaser.Text;
/**
* Set specific stroke colors for certain characters within the Text.
*
* It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position.
* The position value is the index of the character in the Text string to start applying this color to.
* Once set the color remains in use until either another color or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow.
*
* This has no effect if stroke is disabled or has a thickness of 0.
*
* If you wish to change the text fill color see addColor instead.
*
* @param color A canvas fillstyle that will be used on the text stroke eg `red`, `#00FF00`, `rgba()`.
* @param position The index of the character in the string to start applying this color value from.
* @return This Text instance.
*/
addStrokeColor(color: string, position: number): Phaser.Text;
/**
* Aligns this Game Object within another Game Object, or Rectangle, known as the
* 'container', to one of 9 possible positions.
*
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the container. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* container, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive
* one expands it.
*
* @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
* 'parent', in one of 11 possible positions.
*
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the parent. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
* and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* parent, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
* one expands it.
*
* @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Clears any text fill or stroke colors that were set by `addColor` or `addStrokeColor`.
* @return This Text instance.
*/
clearColors(): Phaser.Text;
/**
* Clears any text styles or weights font that were set by `addFontStyle` or `addFontWeight`.
* @return This Text instance.
*/
clearFontValues(): Phaser.Text;
/**
* Converts individual font components (see `fontToComponents`) to a short CSS font string.
*
* @param components Font components.
*/
componentsToFont(components: any): string;
/**
* Destroy this Text object, removing it from the group it belongs to.
*
* @param destroyChildren Should every child of this object have its destroy method called? - Default: true
*/
destroy(destroyChildren?: boolean): void;
/**
* Converting a short CSS-font string into the relevant components.
*
* @param font a CSS font string
*/
fontToComponents(font: string): any;
/**
* Internal method called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Converts the given array into a tab delimited string and then updates this Text object.
* This is mostly used when you want to display external data using tab stops.
*
* The array can be either single or multi dimensional depending on the result you need:
*
* `[ 'a', 'b', 'c' ]` would convert in to `"a\tb\tc"`.
*
* Where as:
*
* `[
* [ 'a', 'b', 'c' ],
* [ 'd', 'e', 'f']
* ]`
*
* would convert in to: `"a\tb\tc\nd\te\tf"`
*
* @param list The array of data to convert into a string.
* @return This Text instance.
*/
parseList(list: any[]): Phaser.Text;
/**
* Runs the given text through the Text.runWordWrap function and returns
* the results as an array, where each element of the array corresponds to a wrapped
* line of text.
*
* Useful if you wish to control pagination on long pieces of content.
*
* @param text The text for which the wrapping will be calculated.
* @return An array of strings with the pieces of wrapped text.
*/
precalculateWordWrap(text: string): string[];
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): void;
/**
* Renders a line of text that contains tab characters if Text.tab > 0.
* Called automatically by updateText.
*
* @param line The line of text to render.
* @param x The x position to start rendering from.
* @param y The y position to start rendering from.
* @param fill If true uses fillText, if false uses strokeText.
*/
renderTabLine(line: string, x: number, y: number, fill?: boolean): void;
/**
* Sets a drop shadow effect on the Text. You can specify the horizontal and vertical distance of the drop shadow with the `x` and `y` parameters.
* The color controls the shade of the shadow (default is black) and can be either an `rgba` or `hex` value.
* The blur is the strength of the shadow. A value of zero means a hard shadow, a value of 10 means a very soft shadow.
* To remove a shadow already in place you can call this method with no parameters set.
*
* @param x The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
* @param y The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
* @param color The color of the shadow, as given in CSS rgba or hex format. Set the alpha component to 0 to disable the shadow. - Default: 'rgba(0,0,0,1)'
* @param blur The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene).
* @param shadowStroke Apply the drop shadow to the Text stroke (if set). - Default: true
* @param shadowFill Apply the drop shadow to the Text fill (if set). - Default: true
* @return This Text instance.
*/
setShadow(x?: number, y?: number, color?: any, blur?: number, shadowStroke?: boolean, shadowFill?: boolean): Phaser.Text;
/**
* Set the style of the text by passing a single style object to it.
*
* @param style The style properties to be set on the Text.
* @param style.font The style and size of the font. - Default: 'bold 20pt Arial'
* @param style.fontStyle The style of the font (eg. 'italic'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontVariant The variant of the font (eg. 'small-caps'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontWeight The weight of the font (eg. 'bold'): overrides the value in `style.font`. - Default: (from font)
* @param style.fontSize The size of the font (eg. 32 or '32px'): overrides the value in `style.font`. - Default: (from font)
* @param style.backgroundColor A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable.
* @param style.fill A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. - Default: 'black'
* @param style.align Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that). - Default: 'left'
* @param style.boundsAlignH Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'. - Default: 'left'
* @param style.boundsAlignV Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'. - Default: 'top'
* @param style.stroke A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'. - Default: 'black'
* @param style.strokeThickness A number that represents the thickness of the stroke. Default is 0 (no stroke).
* @param style.wordWrap Indicates if word wrap should be used.
* @param style.wordWrapWidth The width in pixels at which text will wrap. - Default: 100
* @param style.maxLines The maximum number of lines to be shown for wrapped text.
* @param style.tabs The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.
* @param update Immediately update the Text object after setting the new style? Or wait for the next frame.
* @return This Text instance.
*/
setStyle(style?: PhaserTextStyle, update?: boolean): Phaser.Text;
/**
* The text to be displayed by this Text object.
* Use a \n to insert a carriage return and split the text.
* The text will be rendered with any style currently set.
*
* Use the optional `immediate` argument if you need the Text display to update immediately.
*
* If not it will re-create the texture of this Text object during the next time the render
* loop is called.
*
* @param text The text to be displayed. Set to an empty string to clear text that is already present.
* @param immediate Update the texture used by this Text object immediately (true) or automatically during the next render loop (false).
* @return This Text instance.
*/
setText(text: string, immediate?: boolean): Phaser.Text;
/**
* The Text Bounds is a rectangular region that you control the dimensions of into which the Text object itself is positioned,
* regardless of the number of lines in the text, the font size or any other attribute.
*
* Alignment is controlled via the properties `boundsAlignH` and `boundsAlignV` within the Text.style object, or can be directly
* set through the setters `Text.boundsAlignH` and `Text.boundsAlignV`. Bounds alignment is independent of text alignment.
*
* For example: If your game is 800x600 in size and you set the text bounds to be 0,0,800,600 then by setting boundsAlignH to
* 'center' and boundsAlignV to 'bottom' the text will render in the center and at the bottom of your game window, regardless of
* how many lines of text there may be. Even if you adjust the text content or change the style it will remain at the bottom center
* of the text bounds.
*
* This is especially powerful when you need to align text against specific coordinates in your game, but the actual text dimensions
* may vary based on font (say for multi-lingual games).
*
* If `Text.wordWrapWidth` is greater than the width of the text bounds it is clamped to match the bounds width.
*
* Call this method with no arguments given to reset an existing textBounds.
*
* It works by calculating the final position based on the Text.canvas size, which is modified as the text is updated. Some fonts
* have additional padding around them which you can mitigate by tweaking the Text.padding property. It then adjusts the `pivot`
* property based on the given bounds and canvas size. This means if you need to set the pivot property directly in your game then
* you either cannot use `setTextBounds` or you must place the Text object inside another DisplayObject on which you set the pivot.
*
* @param x The x coordinate of the Text Bounds region.
* @param y The y coordinate of the Text Bounds region.
* @param width The width of the Text Bounds region.
* @param height The height of the Text Bounds region.
* @return This Text instance.
*/
setTextBounds(x?: number, y?: number, width?: number, height?: number): Phaser.Text;
/**
* Override this function to handle any special update requirements.
*/
update(): void;
/**
* Updates the internal `style.font` if it now differs according to generation from components.
*
* @param components Font components.
*/
updateFont(components: any): void;
/**
* Updates a line of text, applying fill and stroke per-character colors or style and weight per-character font if applicable.
*/
updateLine(text: string, x?: number, y?: number): void;
/**
* Sets the Shadow on the Text.context based on the Style settings, or disables it if not enabled.
* This is called automatically by Text.updateText.
*
* @param state If true the shadow will be set to the Style values, otherwise it will be set to zero.
*/
updateShadow(state?: boolean): void;
/**
* Updates the texture based on the canvas dimensions.
*/
updateTexture(): void;
}
/**
* A Tile is a representation of a single tile within the Tilemap.
*/
class Tile {
/**
* A Tile is a representation of a single tile within the Tilemap.
*
* @param layer The layer in the Tilemap data that this tile belongs to.
* @param index The index of this tile type in the core map data.
* @param x The x coordinate of this tile.
* @param y The y coordinate of this tile.
* @param width Width of the tile.
* @param height Height of the tile.
*/
constructor(layer: any, index: number, x: number, y: Number, width: number, height: number);
/**
* The alpha value at which this tile is drawn to the canvas.
*/
alpha: number;
/**
* The sum of the y and height properties.
*/
bottom: number;
callback: Function;
callbackContext: any;
/**
* The width of the tile in pixels.
*/
centerX: number;
/**
* The height of the tile in pixels.
*/
centerY: number;
/**
* True if this tile can collide on any of its faces or has a collision callback set.
*/
canCollide: boolean;
/**
* Indicating collide with any object on the bottom.
*/
collideDown: boolean;
/**
* Indicating collide with any object on the left.
*/
collideLeft: boolean;
collideNone: boolean;
/**
* Indicating collide with any object on the right.
*/
collideRight: boolean;
/**
* Tile collision callback.
*/
collisionCallback: Function;
/**
* The context in which the collision callback will be called.
*/
collisionCallbackContext: any;
/**
* True if this tile can collide on any of its faces.
*/
collides: boolean;
/**
* Indicating collide with any object on the top.
*/
collideUp: boolean;
/**
* Is the bottom of this tile an interesting edge?
*/
faceBottom: boolean;
/**
* Is the left of this tile an interesting edge?
*/
faceLeft: boolean;
/**
* Is the right of this tile an interesting edge?
*/
faceRight: boolean;
/**
* Is the top of this tile an interesting edge?
*/
faceTop: boolean;
game: Phaser.Game;
/**
* The height of the tile in pixels.
*/
height: number;
/**
* The index of this tile within the map data corresponding to the tileset, or -1 if this represents a blank/null tile.
*/
index: number;
/**
* The layer in the Tilemap data that this tile belongs to.
*/
layer: any;
/**
* The x value in pixels.
*/
left: number;
/**
* Tile specific properties.
*/
properties: any;
/**
* The sum of the x and width properties.
*/
right: number;
/**
* Has this tile been walked / turned into a poly?
*/
scanned: boolean;
/**
* The y value.
*/
top: number;
/**
* The width of the tile in pixels.
*/
width: number;
/**
* The x map coordinate of this tile.
*/
worldX: number;
/**
* The y map coordinate of this tile.
*/
worldY: number;
/**
* The x map coordinate of this tile.
*/
x: number;
/**
* The y map coordinate of this tile.
*/
y: number;
/**
* Copies the tile data and properties from the given tile to this tile.
*
* @param tile The tile to copy from.
*/
copy(tile: Phaser.Tile): Phaser.Tile;
/**
* Check if the given x and y world coordinates are within this Tile.
*
* @param x The x coordinate to test.
* @param y The y coordinate to test.
* @return True if the coordinates are within this Tile, otherwise false.
*/
containsPoint(x: number, y: number): boolean;
/**
* Clean up memory.
*/
destroy(): void;
/**
* Check for intersection with this tile.
*
* @param x The x axis in pixels.
* @param y The y axis in pixels.
* @param right The right point.
* @param bottom The bottom point.
*/
intersects(x: number, y: number, right: number, bottom: number): boolean;
isInterested(collides: boolean, faces: boolean): boolean;
/**
* Reset collision status flags.
*/
resetCollision(): void;
/**
* Sets the collision flags for each side of this tile and updates the interesting faces list.
*
* @param left Indicating collide with any object on the left.
* @param right Indicating collide with any object on the right.
* @param up Indicating collide with any object on the top.
* @param down Indicating collide with any object on the bottom.
*/
setCollision(left: boolean, right: boolean, up: boolean, down: boolean): void;
/**
* Set a callback to be called when this tile is hit by an object.
* The callback must true true for collision processing to take place.
*
* @param callback Callback function.
* @param context Callback will be called within this context.
*/
setCollisionCallback(callback: Function, context: any): void;
}
/**
* Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
*
* Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
*
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
* A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself.
* A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around.
*/
class Tilemap {
/**
* Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file.
*
* Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org
*
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
* A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself.
* A map may have multiple layers. You can perform operations on the map data such as copying, pasting, filling and shuffling the tiles around.
*
* @param game Game reference to the currently running game.
* @param key The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`.
* @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10
* @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10
*/
constructor(game: Phaser.Game, key?: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number);
static CSV: number;
static TILED_JSON: number;
static NORTH: number;
static EAST: number;
static SOUTH: number;
static WEST: number;
/**
* An array of collision data (polylines, etc).
*/
collision: any[];
/**
* An array of tile indexes that collide.
*/
collideIndexes: any[];
/**
* The current layer.
*/
currentLayer: number;
/**
* Map data used for debug values only.
*/
debugMap: any[];
/**
* If set then console.log is used to dump out useful layer creation debug data.
*/
enableDebug: boolean;
/**
* The format of the map data, either Phaser.Tilemap.CSV or Phaser.Tilemap.TILED_JSON.
*/
format: number;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The height of the map (in tiles).
*/
height: number;
/**
* The height of the map in pixels based on height * tileHeight.
*/
heightInPixels: number;
/**
* An array of Tiled Image Layers.
*/
images: any[];
/**
* An array of Image Collections.
*/
imagecollections: ImageCollection[];
/**
* The key of this map data in the Phaser.Cache.
*/
key: string;
/**
* The current layer object.
*/
layer: Phaser.TilemapLayer[];
/**
* An array of Tilemap layer data.
*/
layers: any[];
/**
* An array of Tiled Object Layers.
*/
objects: any[];
/**
* The orientation of the map data (as specified in Tiled), usually 'orthogonal'.
*/
orientation: string;
/**
* Map specific properties as specified in Tiled.
*/
properties: any;
rayStepRate: number;
/**
* The base height of the tiles in the map (in pixels).
*/
tileHeight: number;
/**
* The super array of Tiles.
*/
tiles: Phaser.Tile[];
/**
* An array of Tilesets.
*/
tilesets: Phaser.Tileset[];
/**
* The base width of the tiles in the map (in pixels).
*/
tileWidth: number;
/**
* The version of the map data (as specified in Tiled, usually 1).
*/
version: number;
/**
* The width of the map (in tiles).
*/
width: number;
/**
* The width of the map in pixels based on width * tileWidth.
*/
widthInPixels: number;
/**
* Adds an image to the map to be used as a tileset. A single map may use multiple tilesets.
* Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled editor.
*
* @param tileset The name of the tileset as specified in the map data.
* @param key The key of the Phaser.Cache image used for this tileset.
* If `undefined` or `null` it will look for an image with a key matching the tileset parameter.
* You can also pass in a BitmapData which can be used instead of an Image.
* @param tileWidth The width of the tiles in the Tileset Image. If not given it will default to the map.tileWidth value, if that isn't set then 32. - Default: 32
* @param tileHeight The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value, if that isn't set then 32. - Default: 32
* @param tileMargin The width of the tiles in the Tileset Image.
* @param tileSpacing The height of the tiles in the Tileset Image.
* @param gid If adding multiple tilesets to a blank/dynamic map, specify the starting GID the set will use here.
* @return Returns the Tileset object that was created or updated, or null if it failed.
*/
addTilesetImage(tileset: string, key?: string | Phaser.BitmapData, tileWidth?: number, tileHeight?: number, tileMargin?: number, tileSpacing?: number, gid?: number): Phaser.Tileset;
/**
* Internal function.
*
* @param layer The index of the TilemapLayer to operate on.
*/
calculateFaces(layer: number): void;
/**
* Copies all of the tiles in the given rectangular block into the tilemap data buffer.
*
* @param x X position of the top left of the area to copy (given in tiles, not pixels)
* @param y Y position of the top left of the area to copy (given in tiles, not pixels)
* @param width The width of the area to copy (given in tiles, not pixels)
* @param height The height of the area to copy (given in tiles, not pixels)
* @param layer The layer to copy the tiles from.
* @return An array of the tiles that were copied.
*/
copy(x: number, y: number, width: number, height: number, layer?: any): Phaser.Tile[];
/**
* Creates an empty map of the given dimensions and one blank layer. If layers already exist they are erased.
*
* @param name The name of the default layer of the map.
* @param width The width of the map in tiles.
* @param height The height of the map in tiles.
* @param tileWidth The width of the tiles the map uses for calculations.
* @param tileHeight The height of the tiles the map uses for calculations.
* @param group Optional Group to add the layer to. If not specified it will be added to the World group.
* @return The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly.
*/
create(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer;
/**
* Creates a new and empty layer on this Tilemap. By default TilemapLayers are fixed to the camera.
*
* @param name The name of this layer. Must be unique within the map.
* @param width The width of the layer in tiles.
* @param height The height of the layer in tiles.
* @param tileWidth The width of the tiles the layer uses for calculations.
* @param tileHeight The height of the tiles the layer uses for calculations.
* @param group Optional Group to add the layer to. If not specified it will be added to the World group.
* @return The TilemapLayer object. This is an extension of Phaser.Image and can be moved around the display list accordingly.
*/
createBlankLayer(name: string, width: number, height: number, tileWidth: number, tileHeight: number, group?: Phaser.Group): Phaser.TilemapLayer;
/**
* Creates a Sprite for every {@link http://doc.mapeditor.org/reference/tmx-map-format/#object object} matching the `gid` argument. You can optionally specify the group that the Sprite will be created in. If none is
* given it will be created in the World. All properties from the map data objectgroup are copied across to the Sprite, so you can use this as an easy way to
* configure Sprite properties from within the map editor. For example giving an object a property of `alpha: 0.5` in the map editor will duplicate that when the
* Sprite is created. You could also give it a value like: `body.velocity.x: 100` to set it moving automatically.
*
* The `gid` argument is matched against:
*
* 1. For a tile object, the tile identifier (`gid`); or
* 2. The object's unique ID (`id`); or
* 3. The object's `name` (a string)
*
* @param name The name of the Object Group to create Sprites from.
* @param gid The object's tile reference (gid), unique ID (id) or name.
* @param key The Game.cache key of the image that this Sprite will use.
* @param frame If the Sprite image contains multiple frames you can specify which one to use here.
* @param exists The default exists state of the Sprite. - Default: true
* @param autoCull The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range.
* @param group Group to add the Sprite to. If not specified it will be added to the World group. - Default: Phaser.World
* @param CustomClass If you wish to create your own class, rather than Phaser.Sprite, pass the class here. Your class must extend Phaser.Sprite and have the same constructor parameters. - Default: Phaser.Sprite
* @param adjustY By default the Tiled map editor uses a bottom-left coordinate system. Phaser uses top-left. So most objects will appear too low down. This parameter moves them up by their height. - Default: true
*/
createFromObjects(name: string, gid: number, key: string, frame?: any, exists?: boolean, autoCull?: boolean, group?: Phaser.Group, CustomClass?: any, adjustY?: boolean): void;
/**
* Creates a Sprite for every object matching the given tile indexes in the map data.
* You can specify the group that the Sprite will be created in. If none is given it will be created in the World.
* You can optional specify if the tile will be replaced with another after the Sprite is created. This is useful if you want to lay down special
* tiles in a level that are converted to Sprites, but want to replace the tile itself with a floor tile or similar once converted.
*
* @param tiles The tile index, or array of indexes, to create Sprites from.
* @param replacements The tile index, or array of indexes, to change a converted tile to. Set to `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.
*/
createFromTiles(tiles: any, replacements: any, key: string, layer?: any, group?: Phaser.Group, properties?: any): number;
/**
* Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera.
* The `layer` parameter is important. If you've created your map in Tiled then you can get this by looking in Tiled and looking at the Layer name.
* Or you can open the JSON file it exports and look at the layers[].name value. Either way it must match.
* If you wish to create a blank layer to put your own tiles on then see Tilemap.createBlankLayer.
*
* @param layer The layer array index value, or if a string is given the layer name, within the map data that this TilemapLayer represents.
* @param width The rendered width of the layer, should never be wider than Game.width. If not given it will be set to Game.width.
* @param height The rendered height of the layer, should never be wider than Game.height. If not given it will be set to Game.height.
* @param group Optional Group to add the object to. If not specified it will be added to the World group.
* @return The TilemapLayer object. This is an extension of Phaser.Sprite and can be moved around the display list accordingly.
*/
createLayer(layer: any, width?: number, height?: number, group?: Phaser.Group): Phaser.TilemapLayer;
/**
* Removes all layer data from this tile map and nulls the game reference.
* Note: You are responsible for destroying any TilemapLayer objects you generated yourself, as Tilemap doesn't keep a reference to them.
*/
destroy(): void;
/**
* Dumps the tilemap data out to the console.
*/
dump(): void;
/**
* Fills the given area with the specified tile.
*
* @param index The index of the tile that the area will be filled with.
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
fill(index: number, x: number, y: number, width: number, height: number, layer?: any): void;
/**
* For each tile in the given area defined by x/y and width/height run the given callback.
*
* @param callback The callback. Each tile in the given area will be passed to this callback as the first and only parameter.
* @param context The context under which the callback should be run.
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
forEach(callback: Function, context: any, x: number, y: Number, width: number, height: number, layer?: any): void;
/**
* Gets the image index based on its name.
*
* @param name The name of the image to get.
* @return The index of the image in this tilemap, or null if not found.
*/
getImageIndex(name: string): number;
/**
* Gets the layer index based on the layers name.
*
* @param location The local array to search.
* @param name The name of the array element to get.
* @return The index of the element in the array, or null if not found.
*/
getIndex(location: any[], name: string): number;
/**
* Gets the TilemapLayer index as used in the setCollision calls.
*
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @return The TilemapLayer index.
*/
getLayer(layer: any): number;
/**
* Gets the layer index based on its name.
*
* @param name The name of the layer to get.
* @return The index of the layer in this tilemap, or null if not found.
*/
getLayerIndex(name: string): number;
getObjectIndex(name: string): number;
/**
* Gets a tile from the Tilemap Layer. The coordinates are given in tile values.
*
* @param x X position to get the tile from (given in tile units, not pixels)
* @param y Y position to get the tile from (given in tile units, not pixels)
* @param layer The layer to get the tile from.
* @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
* @return The tile at the given coordinates or null if no tile was found or the coordinates were invalid.
*/
getTile(x: number, y: number, layer?: any, nonNull?: boolean): Phaser.Tile;
/**
* Gets the tile above the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param x The x coordinate to get the tile from. In tiles, not pixels.
* @param y The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileAbove(layer: number, x: number, y: number): Phaser.Tile;
/**
* Gets the tile below the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param x The x coordinate to get the tile from. In tiles, not pixels.
* @param y The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileBelow(layer: number, x: number, y: number): Phaser.Tile;
/**
* Gets the tile to the left of the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param x The x coordinate to get the tile from. In tiles, not pixels.
* @param y The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileLeft(layer: number, x: number, y: number): Phaser.Tile;
/**
* Gets the tile to the right of the tile coordinates given.
* Mostly used as an internal function by calculateFaces.
*
* @param layer The local layer index to get the tile from. Can be determined by Tilemap.getLayer().
* @param x The x coordinate to get the tile from. In tiles, not pixels.
* @param y The y coordinate to get the tile from. In tiles, not pixels.
*/
getTileRight(layer: number, x: number, y: number): Phaser.Tile;
/**
* Gets the tileset index based on its name.
*
* @param name The name of the tileset to get.
* @return The index of the tileset in this tilemap, or null if not found.
*/
getTilesetIndex(name: string): number;
/**
* Gets a tile from the Tilemap layer. The coordinates are given in pixel values.
*
* @param x X position to get the tile from (given in pixels)
* @param y Y position to get the tile from (given in pixels)
* @param tileWidth The width of the tiles. If not given the map default is used.
* @param tileHeight The height of the tiles. If not given the map default is used.
* @param layer The layer to get the tile from.
* @param nonNull If true getTile won't return null for empty tiles, but a Tile object with an index of -1.
* @return The tile at the given coordinates.
*/
getTileWorldXY(x: number, y: number, tileWidth?: number, tileHeight?: number, layer?: number | string | Phaser.TilemapLayer, nonNull?: boolean): Phaser.Tile;
/**
* Checks if there is a tile at the given location.
*
* @param x X position to check if a tile exists at (given in tile units, not pixels)
* @param y Y position to check if a tile exists at (given in tile units, not pixels)
* @param layer The layer to set as current.
* @return True if there is a tile at the given location, otherwise false.
*/
hasTile(x: number, y: number, layer: Phaser.TilemapLayer): boolean;
/**
* Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy.
*
* @param x X position of the top left of the area to paste to (given in tiles, not pixels)
* @param y Y position of the top left of the area to paste to (given in tiles, not pixels)
* @param tileblock The block of tiles to paste.
* @param layer The layer to paste the tiles into.
*/
paste(x: number, y: number, tileblock: Phaser.Tile[], layer?: any): void;
/**
* Puts a tile of the given index value at the coordinate specified.
* If you pass `null` as the tile it will pass your call over to Tilemap.removeTile instead.
*
* @param tile The index of this tile to set or a Phaser.Tile object. If null the tile is removed from the map.
* @param x X position to place the tile (given in tile units, not pixels)
* @param y Y position to place the tile (given in tile units, not pixels)
* @param layer The layer to modify.
* @return The Tile object that was created or added to this map.
*/
putTile(tile: any, x: number, y: number, layer?: any): Phaser.Tile;
/**
* Puts a tile into the Tilemap layer. The coordinates are given in pixel values.
*
* @param tile The index of this tile to set or a Phaser.Tile object.
* @param x X position to insert the tile (given in pixels)
* @param y Y position to insert the tile (given in pixels)
* @param tileWidth The width of the tile in pixels.
* @param tileHeight The height of the tile in pixels.
* @param layer The layer to modify.
* @return The Tile object that was created or added to this map.
*/
putTileWorldXY(tile: any, x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): void;
/**
* Randomises a set of tiles in a given area.
*
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
random(x: number, y: number, width: number, height: number, layer?: any): void;
/**
* Removes all layers from this tile map.
*/
removeAllLayers(): void;
/**
* Removes the tile located at the given coordinates and updates the collision data.
*
* @param x X position to place the tile (given in tile units, not pixels)
* @param y Y position to place the tile (given in tile units, not pixels)
* @param layer The layer to modify.
* @return The Tile object that was removed from this map.
*/
removeTile(x: number, y: number, layer?: any): Phaser.Tile;
/**
* Removes the tile located at the given coordinates and updates the collision data. The coordinates are given in pixel values.
*
* @param x X position to insert the tile (given in pixels)
* @param y Y position to insert the tile (given in pixels)
* @param tileWidth The width of the tile in pixels.
* @param tileHeight The height of the tile in pixels.
* @param layer The layer to modify.
* @return The Tile object that was removed from this map.
*/
removeTileWorldXY(x: number, y: number, tileWidth: number, tileHeight: number, layer?: any): Phaser.Tile;
/**
* Scans the given area for tiles with an index matching `source` and updates their index to match `dest`.
*
* @param source The tile index value to scan for.
* @param dest The tile index value to replace found tiles with.
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
replace(source: number, dest: number, x: number, y: number, width: number, height: number, layer?: any): void;
/**
* Searches the entire map layer for the first tile 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.
*/
searchTileIndex(index: number, skip?: number, reverse?: boolean, layer?: any): Phaser.Tile;
/**
* Sets collision on the given tile or tiles. You can pass in either a single numeric index or an array of indexes: [2, 3, 15, 20].
* The `collides` parameter controls if collision will be enabled (true) or disabled (false).
*
* Collision-enabled tiles can be collided against Sprites using {@link Phaser.Physics.Arcade#collide}.
*
* @param indexes Either a single tile index, or an array of tile IDs to be checked for collision.
* @param collides If true it will enable collision. If false it will clear collision. - Default: true
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @param recalculate Recalculates the tile faces after the update. - Default: true
*/
setCollision(indexes: any, collides?: boolean, layer?: any, recalculate?: boolean): void;
/**
* Sets collision on a range of tiles where the tile IDs increment sequentially.
* Calling this with a start value of 10 and a stop value of 14 would set collision for tiles 10, 11, 12, 13 and 14.
* The `collides` parameter controls if collision will be enabled (true) or disabled (false).
*
* @param start The first index of the tile to be set for collision.
* @param stop The last index of the tile to be set for collision.
* @param collides If true it will enable collision. If false it will clear collision. - Default: true
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @param recalculate Recalculates the tile faces after the update. - Default: true
*/
setCollisionBetween(start: number, stop: number, collides?: boolean, layer?: any, recalculate?: boolean): void;
/**
* Sets collision on all tiles in the given layer, except for the IDs of those in the given array.
* The `collides` parameter controls if collision will be enabled (true) or disabled (false).
*
* @param indexes An array of the tile IDs to not be counted for collision.
* @param collides If true it will enable collision. If false it will clear collision. - Default: true
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @param recalculate Recalculates the tile faces after the update. - Default: true
*/
setCollisionByExclusion(indexes: any[], collides?: boolean, layer?: any, recalculate?: boolean): void;
/**
* Sets collision values on a tile in the set.
* You shouldn't usually call this method directly, instead use setCollision, setCollisionBetween or setCollisionByExclusion.
*
* @param index The index of the tile on the layer.
* @param collides If true it will enable collision on the tile. If false it will clear collision values from the tile. - Default: true
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @param recalculate Recalculates the tile faces after the update. - Default: true
*/
setCollisionByIndex(index: number, collides?: boolean, layer?: number, recalculate?: boolean): void;
/**
* Sets the current layer to the given index.
*
* @param layer The layer to set as current.
*/
setLayer(layer: any): void;
/**
* Turn off/on the recalculation of faces for tile or collision updates.
* `setPreventRecalculate(true)` puts recalculation on hold while `setPreventRecalculate(false)` recalculates all the changed layers.
*
* @param value If true it will put the recalculation on hold.
*/
setPreventRecalculate(value: boolean): void;
/**
* Sets a global collision callback for the given tile index within the layer. This will affect all tiles on this layer that have the same index.
* If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.
* If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
*
* Return `true` from the callback to continue separating the tile and colliding object, or `false` to cancel the collision for the current tile (see {@link Phaser.Physics.Arcade#separateTile}).
*
* @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for.
* @param callback The callback that will be invoked when the tile is collided with (via {@link Phaser.Physics.Arcade#collide}).
* @param callbackContext The context under which the callback is called.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
*/
setTileIndexCallback(indexes: any, callback: Function, callbackContext: any, layer?: any): void;
/**
* Sets a global collision callback for the given map location within the layer. This will affect all tiles on this layer found in the given area.
* If a callback is already set for the tile index it will be replaced. Set the callback to null to remove it.
* If you want to set a callback for a tile at a specific location on the map then see setTileLocationCallback.
*
* Return `true` from the callback to continue separating the tile and colliding object, or `false` to cancel the collision for the current tile (see {@link Phaser.Physics.Arcade#separateTile}).
*
* @param x X position of the top left of the area to copy (given in tiles, not pixels)
* @param y Y position of the top left of the area to copy (given in tiles, not pixels)
* @param width The width of the area to copy (given in tiles, not pixels)
* @param height The height of the area to copy (given in tiles, not pixels)
* @param callback The callback that will be invoked when the tile is collided with (via {@link Phaser.Physics.Arcade#collide}).
* @param callbackContext The context under which the callback is called.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
*/
setTileLocationCallback(x: number, y: number, width: number, height: number, callback: Function, callbackContext: any, layer?: any): void;
/**
* Sets the base tile size for the map.
*
* @param tileWidth The width of the tiles the map uses for calculations.
* @param tileHeight The height of the tiles the map uses for calculations.
*/
setTileSize(tileWidth: number, tileHeight: number): void;
/**
* Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed!
*
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
shuffle(x: number, y: number, width: number, height: number, layer: any): void;
/**
* Scans the given area for tiles with an index matching tileA and swaps them with tileB.
*
* @param tileA First tile index.
* @param tileB Second tile index.
* @param x X position of the top left of the area to operate one, given in tiles, not pixels.
* @param y Y position of the top left of the area to operate one, given in tiles, not pixels.
* @param width The width in tiles of the area to operate on.
* @param height The height in tiles of the area to operate on.
* @param layer The layer to operate on.
*/
swap(tileA: number, tileB: number, x: number, y: number, width: number, height: number, layer?: any): void;
}
/**
* A TilemapLayer is a Phaser.Image/Sprite that renders a specific TileLayer of a Tilemap.
*
* Since a TilemapLayer is a Sprite it can be moved around the display, added to other groups or display objects, etc.
*
* By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior.
*/
class TilemapLayer extends Phaser.Sprite {
/**
* A TilemapLayer is a Phaser.Image/Sprite that renders a specific TileLayer of a Tilemap.
*
* Since a TilemapLayer is a Sprite it can be moved around the display, added to other groups or display objects, etc.
*
* By default TilemapLayers have fixedToCamera set to `true`. Changing this will break Camera follow and scrolling behavior.
*
* @param game Game reference to the currently running game.
* @param tilemap The tilemap to which this layer belongs.
* @param index The index of the TileLayer to render within the Tilemap.
* @param width Width of the renderable area of the layer (in pixels).
* @param height Height of the renderable area of the layer (in pixels).
*/
constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number);
/**
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
*
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
*/
cameraOffset: Phaser.Point;
/**
* The canvas to which this TilemapLayer draws.
*/
canvas: HTMLCanvasElement;
collisionHeight: number;
collisionWidth: number;
/**
* The 2d context of the canvas.
*/
context: CanvasRenderingContext2D;
/**
* An empty Object that belongs to this Game Object.
* This value isn't ever used internally by Phaser, but may be used by your own code, or
* by Phaser Plugins, to store data that needs to be associated with the Game Object,
* without polluting the Game Object directly.
* Default: {}
*/
data: any;
/**
* Enable an additional "debug rendering" pass to display collision information.
*/
debug: boolean;
debugAlpha: number;
debugCallbackColor: string;
debugColor: string;
/**
* Settings used for debugging and diagnostics.
*/
debugSettings: { missingImageFill: string; debuggedTileOverfill: string; forceFullRedraw: boolean; debugAlpha: number; facingEdgeStroke: string; collidingTileOverfill: string; };
/**
* If true tiles will be force rendered, even if such is not believed to be required.
*/
dirty: boolean;
/**
* Controls if the core game loop and physics update this game object or not.
*/
exists: boolean;
/**
* A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
* are stored in the `cameraOffset` property, which is initialized with the current object coordinates.
*
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
*
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
* regardless where in the world the camera is.
*
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
*
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
*/
fixedToCamera: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The index of this layer within the Tilemap.
*/
index: number;
/**
* The layer object within the Tilemap that this layer represents.
*/
layer: Phaser.TilemapLayer;
/**
* The Tilemap to which this layer is bound.
*/
map: Phaser.Tilemap;
/**
* A user defined name given to this Game Object.
* This value isn't ever used internally by Phaser, it is meant as a game level property.
*/
name: string;
/**
* The const physics body type of this object.
*/
physicsType: number;
/**
* Settings that control standard (non-diagnostic) rendering.
* Default: {"enableScrollDelta":true,"overdrawRatio":0.2,"copyCanvas":null}
*/
renderSettings: { enableScrollDelta: boolean; overdrawRatio: number; copyCanvas: any; };
/**
* Speed at which this layer scrolls horizontally, relative to the camera (e.g. scrollFactorX of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do).
* Default: 1
*/
scrollFactorX: number;
/**
* Speed at which this layer scrolls vertically, relative to the camera (e.g. scrollFactorY of 0.5 scrolls half as quickly as the 'normal' camera-locked layers do)
* Default: 1
*/
scrollFactorY: number;
scrollX: number;
scrollY: number;
/**
* The const type of this object.
* Default: Phaser.TILEMAPLAYER
*/
type: number;
wrap: boolean;
/**
* Destroys this TilemapLayer.
*/
destroy(): void;
/**
* Gets all tiles that intersect with the given line.
*
* @param line The line used to determine which tiles to return.
* @param stepRate How many steps through the ray will we check? Defaults to `rayStepRate`. - Default: (rayStepRate)
* @param collides If true, _only_ return tiles that collide on one or more faces.
* @param interestingFace If true, _only_ return tiles that have interesting faces.
* @return An array of Phaser.Tiles.
*/
getRayCastTiles(line: Phaser.Line, stepRate?: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
/**
* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles.
*
* @param x X position of the top left corner (in pixels).
* @param y Y position of the top left corner (in pixels).
* @param width Width of the area to get (in pixels).
* @param height Height of the area to get (in pixels).
* @param collides If true, _only_ return tiles that collide on one or more faces.
* @param interestingFace If true, _only_ return tiles that have interesting faces.
* @return An array of Tiles.
*/
getTiles(x: number, y: number, width: number, height: number, collides?: boolean, interestingFace?: boolean): Phaser.Tile[];
/**
* Convert a pixel value to a tile coordinate.
*
* @param x X position of the point in target tile (in pixels).
* @return The X map location of the tile.
*/
getTileX(x: number): number;
/**
* Convert a pixel coordinate to a tile coordinate.
*
* @param x X position of the point in target tile (in pixels).
* @param y Y position of the point in target tile (in pixels).
* @param point The Point/object to update.
* @return A Point/object with its `x` and `y` properties set.
*/
getTileXY(x: number, y: number, point: Phaser.Point): Phaser.Point;
/**
* Convert a pixel value to a tile coordinate.
*
* @param y Y position of the point in target tile (in pixels).
* @return The Y map location of the tile.
*/
getTileY(y: number): number;
/**
* Automatically called by World.postUpdate. Handles cache updates.
*/
postUpdate(): void;
/**
* Renders the tiles to the layer canvas and pushes to the display.
*/
render(): void;
/**
* Resizes the internal canvas and texture frame used by this TilemapLayer.
*
* This is an expensive call, so don't bind it to a window resize event! But instead call it at carefully
* selected times.
*
* Be aware that no validation of the new sizes takes place and the current map scroll coordinates are not
* modified either. You will have to handle both of these things from your game code if required.
*
* @param width The new width of the TilemapLayer
* @param height The new height of the TilemapLayer
*/
resize(width: number, height: number): void;
/**
* Sets the world size to match the size of this layer.
*/
resizeWorld(): void;
/**
* The TilemapLayer caches tileset look-ups.
*
* Call this method of clear the cache if tilesets have been added or updated after the layer has been rendered.
*/
resetTilesetCache(): void;
/**
* This method will set the scale of the tilemap as well as update the underlying block data of this layer.
*
* @param xScale The scale factor along the X-plane - Default: 1
* @param yScale The scale factor along the Y-plane
*/
setScale(xScale?: number, yScale?: number): void;
updateMax(): void;
getTileOffsetX(): number;
/**
* Get the Y axis position offset of this layer's tiles.
*/
getTileOffsetY(): number;
}
class TilemapLayerGL {
constructor(game: Phaser.Game, tilemap: Phaser.Tilemap, index: number, width?: number, height?: number, tileset?: Phaser.Tileset);
collisionHeight: number;
collisionWidth: number;
data: any;
dirty: boolean;
exists: boolean;
fixedToCamera: boolean;
game: Phaser.Game;
index: number;
layer: Phaser.TilemapLayer;
map: Phaser.Tilemap;
name: string;
physicsType: number;
scrollFactorX: number;
scrollFactorY: number;
scrollX: number;
scrollY: number;
type: number;
wrap: boolean;
x: number;
y: number;
width: number;
height: number;
destroy(): void;
postUpdate(): void;
render(): void;
resize(width: number, height: number): void;
resizeWorld(): void;
resetTilesetCache(): void;
setScale(xScale?: number, yScale?: number): void;
updateMax(): void;
}
/**
* Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap.
*/
class TilemapParser {
/**
* When scanning the Tiled map data the TilemapParser can either insert a null value (true) or
* a Phaser.Tile instance with an index of -1 (false, the default). Depending on your game type
* depends how this should be configured. If you've a large sparsely populated map and the tile
* data doesn't need to change then setting this value to `true` will help with memory consumption.
* However if your map is small, or you need to update the tiles (perhaps the map dynamically changes
* during the game) then leave the default value set.
*/
static INSERT_NULL: boolean;
/**
* Returns an empty map data object.
* @return Generated map data.
*/
static getEmptyData(tileWidth?: number, tileHeight?: number, width?: number, height?: number): any;
/**
* Parse tilemap data from the cache and creates data for a Tilemap object.
*
* @param game Game reference to the currently running game.
* @param key The key of the tilemap in the Cache.
* @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @param width The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10
* @param height The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this. - Default: 10
* @return The parsed map object.
*/
static parse(game: Phaser.Game, key: string, tileWidth?: number, tileHeight?: number, width?: number, height?: number): any;
/**
* Parses a CSV file into valid map data.
*
* @param key The name you want to give the map data.
* @param data The CSV file data.
* @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data. - Default: 32
* @return Generated map data.
*/
static parseCSV(key: string, data: string, tileWidth?: number, tileHeight?: number): any;
static parseJSON(json: any): any;
}
/**
* A Tile set is a combination of an image containing the tiles and collision data per tile.
*
* Tilesets are normally created automatically when Tiled data is loaded.
*/
class Tileset {
/**
* A Tile set is a combination of an image containing the tiles and collision data per tile.
*
* Tilesets are normally created automatically when Tiled data is loaded.
*
* @param name The name of the tileset in the map data.
* @param firstgid The first tile index this tileset contains.
* @param width Width of each tile (in pixels). - Default: 32
* @param height Height of each tile (in pixels). - Default: 32
* @param margin The margin around all tiles in the sheet (in pixels).
* @param spacing The spacing between each tile in the sheet (in pixels).
* @param properties Custom Tileset properties. - Default: {}
*/
constructor(name: string, firstgid: number, width?: number, height?: number, margin?: number, spacing?: number, properties?: any);
/**
* The number of tile columns in the tileset.
*/
columns: number;
/**
* The Tiled firstgid value.
* This is the starting index of the first tile index this Tileset contains.
*/
firstgid: number;
/**
* The cached image that contains the individual tiles. Use {@link Phaser.Tileset.setImage setImage} to set.
*/
image: any;
lastgid: number;
/**
* The name of the Tileset.
*/
name: string;
/**
* Tileset-specific properties that are typically defined in the Tiled editor.
*/
properties: any;
/**
* The number of tile rows in the the tileset.
*/
rows: number;
/**
* The height of each tile (in pixels).
*/
tileHeight: number;
/**
* The margin around the tiles in the sheet (in pixels).
* Use `setSpacing` to change.
*/
tileMargin: number;
/**
* The spacing between each tile in the sheet (in pixels).
* Use `setSpacing` to change.
*/
tileSpacing: number;
/**
* The width of each tile (in pixels).
*/
tileWidth: number;
/**
* The total number of tiles in the tileset.
*/
total: number;
/**
* Returns true if and only if this tileset contains the given tile index.
* @return True if this tileset contains the given index.
*/
containsTileIndex(tileIndex: number): boolean;
/**
* Draws a tile from this Tileset at the given coordinates on the context.
*
* @param context The context to draw the tile onto.
* @param x The x coordinate to draw to.
* @param y The y coordinate to draw to.
* @param index The index of the tile within the set to draw.
*/
draw(context: CanvasRenderingContext2D, x: number, y: number, index: number): void;
drawGl(glBatch: any[], x: number, y: number, index: number, alpha: number, flippedVal: number): void;
/**
* Set the image associated with this Tileset and update the tile data.
*
* @param image The image that contains the tiles.
*/
setImage(image: any): void;
/**
* Sets tile spacing and margins.
*
* @param margin The margin around the tiles in the sheet (in pixels).
* @param spacing The spacing between the tiles in the sheet (in pixels).
*/
setSpacing(margin?: number, spacing?: number): void;
}
/**
* A TileSprite is a Sprite that has a repeating texture. The texture can be scrolled and scaled independently of the TileSprite itself.
* Textures will automatically wrap and are designed so that you can create game backdrops using seamless textures as a source.
*
* TileSprites have no input handler or physics bodies by default, both need enabling in the same way as for normal Sprites.
*
* You shouldn't ever create a TileSprite any larger than your actual screen size. If you want to create a large repeating background
* that scrolls across the whole map of your game, then you create a TileSprite that fits the screen size and then use the `tilePosition`
* property to scroll the texture as the player moves. If you create a TileSprite that is thousands of pixels in size then it will
* consume huge amounts of memory and cause performance issues. Remember: use `tilePosition` to scroll your texture and `tileScale` to
* adjust the scale of the texture - don't resize the sprite itself or make it larger than it needs.
*
* An important note about texture dimensions:
*
* When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should ideally be
* a power of two in size (i.e. 4, 8, 16, 32, 64, 128, 256, 512, etc pixels width by height). If the texture isn't a power of two
* it will be rendered to a blank canvas that is the correct size, which means you may have 'blank' areas appearing to the right and
* bottom of your frame. To avoid this ensure your textures are perfect powers of two.
*
* TileSprites support animations in the same way that Sprites do. You add and play animations using the AnimationManager. However
* if your game is running under WebGL please note that each frame of the animation must be a power of two in size, or it will receive
* additional padding to enforce it to be so.
*/
class TileSprite extends PIXI.TilingSprite {
/**
* A TileSprite is a Sprite that has a repeating texture. The texture can be scrolled and scaled independently of the TileSprite itself.
* Textures will automatically wrap and are designed so that you can create game backdrops using seamless textures as a source.
*
* TileSprites have no input handler or physics bodies by default, both need enabling in the same way as for normal Sprites.
*
* You shouldn't ever create a TileSprite any larger than your actual screen size. If you want to create a large repeating background
* that scrolls across the whole map of your game, then you create a TileSprite that fits the screen size and then use the `tilePosition`
* property to scroll the texture as the player moves. If you create a TileSprite that is thousands of pixels in size then it will
* consume huge amounts of memory and cause performance issues. Remember: use `tilePosition` to scroll your texture and `tileScale` to
* adjust the scale of the texture - don't resize the sprite itself or make it larger than it needs.
*
* An important note about texture dimensions:
*
* When running under Canvas a TileSprite can use any texture size without issue. When running under WebGL the texture should ideally be
* a power of two in size (i.e. 4, 8, 16, 32, 64, 128, 256, 512, etc pixels width by height). If the texture isn't a power of two
* it will be rendered to a blank canvas that is the correct size, which means you may have 'blank' areas appearing to the right and
* bottom of your frame. To avoid this ensure your textures are perfect powers of two.
*
* TileSprites support animations in the same way that Sprites do. You add and play animations using the AnimationManager. However
* if your game is running under WebGL please note that each frame of the animation must be a power of two in size, or it will receive
* additional padding to enforce it to be so.
*
* @param game A reference to the currently running game.
* @param x The x coordinate (in world space) to position the TileSprite at.
* @param y The y coordinate (in world space) to position the TileSprite at.
* @param width The width of the TileSprite. - Default: 256
* @param height The height of the TileSprite. - Default: 256
* @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Phaser Image Cache entry, or an instance of a PIXI.Texture or BitmapData.
* @param frame If this TileSprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
*/
constructor(game: Phaser.Game, x: number, y: number, width: number, height: number, key?: string | Phaser.RenderTexture | Phaser.BitmapData | PIXI.Texture, frame?: string | number);
/**
* A useful flag to control if the Game Object is alive or dead.
*
* This is set automatically by the Health components `damage` method should the object run out of health.
* Or you can toggle it via your game code.
*
* This property is mostly just provided to be used by your game - it doesn't effect rendering or logic updates.
* However you can use `Group.getFirstAlive` in conjunction with this property for fast object pooling and recycling.
* Default: true
*/
alive: boolean;
/**
* The angle property is the rotation of the Game Object in *degrees* from its original orientation.
*
* Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
*
* Values outside this range are added to or subtracted from 360 to obtain a value within the range.
* For example, the statement player.angle = 450 is the same as player.angle = 90.
*
* If you wish to work in radians instead of degrees you can use the property `rotation` instead.
* Working in radians is slightly faster as it doesn't have to perform any calculations.
*/
angle: number;
/**
* If the Game Object is enabled for animation (such as a Phaser.Sprite) this is a reference to its AnimationManager instance.
* Through it you can create, play, pause and stop animations.
*/
animations: Phaser.AnimationManager;
/**
* A Game Object with `autoCull` set to true will check its bounds against the World Camera every frame.
* If it is not intersecting the Camera bounds at any point then it has its `renderable` property set to `false`.
* This keeps the Game Object alive and still processing updates, but forces it to skip the render step entirely.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
autoCull: boolean;
/**
* `body` is the Game Objects physics body. Once a Game Object is enabled for physics you access all associated
* properties and methods via it.
*
* By default Game Objects won't add themselves to any physics system and their `body` property will be `null`.
*
* To enable this Game Object for physics you need to call `game.physics.enable(object, system)` where `object` is this object
* and `system` is the Physics system you are using. If none is given it defaults to `Phaser.Physics.Arcade`.
*
* You can alternatively call `game.physics.arcade.enable(object)`, or add this Game Object to a physics enabled Group.
*
* Important: Enabling a Game Object for P2 or Ninja physics will automatically set its `anchor` property to 0.5,
* so the physics body is centered on the Game Object.
*
* If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics.
*/
body: Phaser.Physics.Arcade.Body | Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body | any;
/**
* The sum of the y and height properties.
* This is the same as `y + height - offsetY`.
*/
bottom: number;
/**
* The x/y coordinate offset applied to the top-left of the camera that this Game Object will be drawn at if `fixedToCamera` is true.
*
* The values are relative to the top-left of the camera view and in addition to any parent of the Game Object on the display list.
*/
cameraOffset: Phaser.Point;
/**
* If this is set to `true` the Game Object checks if it is within the World bounds each frame.
*
* When it is no longer intersecting the world bounds it dispatches the `onOutOfBounds` event.
*
* If it was *previously* out of bounds but is now intersecting the world bounds again it dispatches the `onEnterBounds` event.
*
* It also optionally kills the Game Object if `outOfBoundsKill` is `true`.
*
* When `checkWorldBounds` is enabled it forces the Game Object to calculate its full bounds every frame.
*
* This is a relatively expensive operation, especially if enabled on hundreds of Game Objects. So enable it only if you know it's required,
* or you have tested performance and find it acceptable.
*/
checkWorldBounds: boolean;
/**
* The components this Game Object has installed.
*/
components: any;
/**
* Does this texture require a custom render call? (as set by BitmapData, Video, etc)
*/
customRender: boolean;
/**
* An empty Object that belongs to this Game Object.
* This value isn't ever used internally by Phaser, but may be used by your own code, or
* by Phaser Plugins, to store data that needs to be associated with the Game Object,
* without polluting the Game Object directly.
* Default: {}
*/
data: any;
/**
* A debug flag designed for use with `Game.enableStep`.
*/
debug: boolean;
/**
* As a Game Object runs through its destroy method this flag is set to true,
* and can be checked in any sub-systems or plugins it is being destroyed from.
*/
destroyPhase: boolean;
/**
* All Phaser Game Objects have an Events class which contains all of the events that are dispatched when certain things happen to this
* Game Object, or any of its components.
*/
events: Phaser.Events;
/**
* Controls if this Sprite is processed by the core Phaser game loops and Group loops (except {@link Phaser.Group#update}).
* Default: true
*/
exists: boolean;
/**
* A Game Object that is "fixed" to the camera is rendered at a given x/y offsets from the top left of the camera. The offsets
* are stored in the `cameraOffset` property, which is initialized with the current object coordinates.
*
* The values are adjusted at the rendering stage, overriding the Game Objects actual world position.
*
* The end result is that the Game Object will appear to be 'fixed' to the camera, regardless of where in the game world
* the camera is viewing. This is useful if for example this Game Object is a UI item that you wish to be visible at all times
* regardless where in the world the camera is.
*
* Note that the `cameraOffset` values are in addition to any parent of this Game Object on the display list.
*
* Be careful not to set `fixedToCamera` on Game Objects which are in Groups that already have `fixedToCamera` enabled on them.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index of the texture being used to render this Game Object.
*
* To change the frame set `frame` to the index of the new frame in the sprite sheet you wish this Game Object to use,
* for example: `player.frame = 4`.
*
* If the frame index given doesn't exist it will revert to the first frame found in the texture.
*
* If you are using a texture atlas then you should use the `frameName` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frame: string | number;
/**
* Gets or sets the current frame name of the texture being used to render this Game Object.
*
* To change the frame set `frameName` to the name of the new frame in the texture atlas you wish this Game Object to use,
* for example: `player.frameName = "idle"`.
*
* If the frame name given doesn't exist it will revert to the first frame found in the texture and throw a console warning.
*
* If you are using a sprite sheet then you should use the `frame` property instead.
*
* If you wish to fully replace the texture being used see `loadTexture`.
*/
frameName: string;
/**
* A Game Object is considered `fresh` if it has just been created or reset and is yet to receive a renderer transform update.
* This property is mostly used internally by the physics systems, but is exposed for the use of plugins.
*/
fresh: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* Checks if the Game Objects bounds intersect with the Game Camera bounds.
* Returns `true` if they do, otherwise `false` if fully outside of the Cameras bounds.
*/
inCamera: boolean;
/**
* The Input Handler for this Game Object.
*
* By default it is disabled. If you wish this Game Object to process input events you should enable it with: `inputEnabled = true`.
*
* After you have done this, this property will be a reference to the Phaser InputHandler.
*/
input: Phaser.InputHandler;
/**
* By default a Game Object won't process any input events. By setting `inputEnabled` to true a Phaser.InputHandler is created
* for this Game Object and it will then start to process click / touch events and more.
*
* You can then access the Input Handler via `this.input`.
*
* Note that Input related events are dispatched from `this.events`, i.e.: `events.onInputDown`.
*
* If you set this property to false it will stop the Input Handler from processing any more input events.
*
* If you want to _temporarily_ disable input for a Game Object, then it's better to set
* `input.enabled = false`, as it won't reset any of the Input Handlers internal properties.
* You can then toggle this back on as needed.
*/
inputEnabled: boolean;
/**
* Checks if the Game Objects bounds are within, or intersect at any point with the Game World bounds.
*/
inWorld: boolean;
/**
* The key of the image or texture used by this Game Object during rendering.
* If it is a string it's the string used to retrieve the texture from the Phaser Image Cache.
* It can also be an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* If a Game Object is created without a key it is automatically assigned the key `__default` which is a 32x32 transparent PNG stored within the Cache.
* If a Game Object is given a key which doesn't exist in the Image Cache it is re-assigned the key `__missing` which is a 32x32 PNG of a green box with a line through it.
*/
key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture;
/**
* The left coordinate of the Game Object.
* This is the same as `x - offsetX`.
*/
left: number;
/**
* A user defined name given to this Game Object.
* This value isn't ever used internally by Phaser, it is meant as a game level property.
*/
name: string;
/**
* The amount the Game Object is visually offset from its x coordinate.
* This is the same as `width * anchor.x`.
* It will only be > 0 if anchor.x is not equal to zero.
*/
offsetX: number;
/**
* The amount the Game Object is visually offset from its y coordinate.
* This is the same as `height * anchor.y`.
* It will only be > 0 if anchor.y is not equal to zero.
*/
offsetY: number;
/**
* If this and the `checkWorldBounds` property are both set to `true` then the `kill` method is called as soon as `inWorld` returns false.
*/
outOfBoundsKill: boolean;
/**
* A Game Object is that is pendingDestroy is flagged to have its destroy method called on the next logic update.
* You can set it directly to allow you to flag an object to be destroyed on its next update.
*
* This is extremely useful if you wish to destroy an object from within one of its own callbacks
* such as with Buttons or other Input events.
*/
pendingDestroy: boolean;
/**
* The const physics body type of this object.
*/
physicsType: number;
/**
* The coordinates, in pixels, of this DisplayObject, relative to its parent container.
*
* The value of this property does not reflect any positioning happening further up the display list.
* To obtain that value please see the `worldPosition` property.
*/
position: Phaser.Point;
/**
* Enable or disable texture smoothing for this Game Object.
*
* It only takes effect if the Game Object is using an image based texture.
*
* Smoothing is enabled by default.
*/
smoothed: boolean;
/**
* The position the Game Object was located in the previous frame.
*/
previousPosition: Phaser.Point;
previousRoation: number;
/**
* The right coordinate of the Game Object.
* This is the same as `x + width - offsetX`.
*/
right: number;
/**
* The y coordinate of the Game Object.
* This is the same as `y - offsetY`.
*/
top: number;
/**
* The render order ID is used internally by the renderer and Input Manager and should not be modified.
* This property is mostly used internally by the renderers, but is exposed for the use of plugins.
*/
renderOrderID: number;
/**
* The const type of this object.
*/
type: number;
/**
* The world coordinates of this Game Object in pixels.
* Depending on where in the display list this Game Object is placed this value can differ from `position`,
* which contains the x/y coordinates relative to the Game Objects parent.
*/
world: Phaser.Point;
/**
* The z depth of this Game Object within its parent Group.
* No two objects in a Group can have the same z value.
* This value is adjusted automatically whenever the Group hierarchy changes.
* If you wish to re-order the layering of a Game Object then see methods like Group.moveUp or Group.bringToTop.
*/
z: number;
/**
* Aligns this Game Object within another Game Object, or Rectangle, known as the
* 'container', to one of 9 possible positions.
*
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the container. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* container, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the containers bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the container bounds by that amount, and providing a positive
* one expands it.
*
* @param container The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
* 'parent', in one of 11 possible positions.
*
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
* TileSprites or Buttons.
*
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
* the parent. It simply modifies its position coordinates so it aligns with it.
*
* The position constants you can use are:
*
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
* and `Phaser.BOTTOM_RIGHT`.
*
* The Game Objects are placed in such a way that their _bounds_ align with the
* parent, taking into consideration rotation, scale and the anchor property.
* This allows you to neatly align Game Objects, irrespective of their position value.
*
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
* aligned position of the Game Object. For example:
*
* `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
*
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
* Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
* So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
* one expands it.
*
* @param parent The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
* @param position The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
* @param offsetX A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @param offsetY A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
* @return This Game Object.
*/
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
/**
* Sets this TileSprite to automatically scroll in the given direction until stopped via TileSprite.stopScroll().
* The scroll speed is specified in pixels per second.
* A negative x value will scroll to the left. A positive x value will scroll to the right.
* A negative y value will scroll up. A positive y value will scroll down.
*
* @param x Horizontal scroll speed in pixels per second.
* @param y Vertical scroll speed in pixels per second.
* @return This instance.
*/
autoScroll(x: number, y: number): void;
/**
* Destroys the TileSprite. This removes it from its parent group, destroys the event and animation handlers if present
* and nulls its reference to game, freeing it up for garbage collection.
*
* @param destroyChildren Should every child of this object have its destroy method called? - Default: true
*/
destroy(destroyChildren?: boolean): void;
/**
* Changes the base texture the Game Object is using. The old texture is removed and the new one is referenced or fetched from the Cache.
*
* If your Game Object is using a frame from a texture atlas and you just wish to change to another frame, then see the `frame` or `frameName` properties instead.
*
* You should only use `loadTexture` if you want to replace the base texture entirely.
*
* Calling this method causes a WebGL texture update, so use sparingly or in low-intensity portions of your game, or if you know the new texture is already on the GPU.
*
* You can use the new const `Phaser.PENDING_ATLAS` as the texture key for any sprite.
* Doing this then sets the key to be the `frame` argument (the frame is set to zero).
*
* This allows you to create sprites using `load.image` during development, and then change them
* to use a Texture Atlas later in development by simply searching your code for 'PENDING_ATLAS'
* and swapping it to be the key of the atlas data.
*
* Note: You cannot use a RenderTexture as a texture for a TileSprite.
*
* @param key This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache Image entry, or an instance of a RenderTexture, BitmapData, Video or PIXI.Texture.
* @param frame If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
* @param stopAnimation If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing. - Default: true
*/
loadTexture(key: string | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Video | PIXI.Texture, frame?: string | number, stopAnimation?: boolean): void;
/**
* Plays an Animation.
*
* The animation should have previously been created via `animations.add`.
*
* If the animation is already playing calling this again won't do anything.
* If you need to reset an already running animation do so directly on the Animation object itself or via `AnimationManager.stop`.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump". Must have been previously created via 'AnimationManager.add'.
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return A reference to playing Animation.
*/
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
/**
* Internal method called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): void;
/**
* Checks to see if the bounds of this Game Object overlaps with the bounds of the given Display Object,
* which can be a Sprite, Image, TileSprite or anything that extends those such as Button or provides a `getBounds` method and result.
*
* This check ignores the `hitArea` property if set and runs a `getBounds` comparison on both objects to determine the result.
*
* Therefore it's relatively expensive to use in large quantities, i.e. with lots of Sprites at a high frequency.
* It should be fine for low-volume testing where physics isn't required.
*
* @param displayObject The display object to check against.
* @return True if the bounds of this Game Object intersects at any point with the bounds of the given display object.
*/
overlap(displayObject: Phaser.Sprite | Phaser.Image | Phaser.TileSprite | Phaser.Button | PIXI.DisplayObject): boolean;
/**
* Resets the TileSprite. This places the TileSprite at the given x/y world coordinates, resets the tilePosition and then
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state.
* If the TileSprite has a physics body that too is reset.
*
* @param x The x coordinate (in world space) to position the Sprite at.
* @param y The y coordinate (in world space) to position the Sprite at.
* @return This instance.
*/
reset(x: number, y: number, health?: number): Phaser.TileSprite;
/**
* Resizes the Frame dimensions that the Game Object uses for rendering.
*
* You shouldn't normally need to ever call this, but in the case of special texture types such as Video or BitmapData
* it can be useful to adjust the dimensions directly in this way.
*
* @param parent The parent texture object that caused the resize, i.e. a Phaser.Video object.
* @param width The new width of the texture.
* @param height The new height of the texture.
*/
resizeFrame(parent: any, width: number, height: number): void;
/**
* Resets the texture frame dimensions that the Game Object uses for rendering.
*/
resetFrame(): void;
/**
* Sets the texture frame the Game Object uses for rendering.
*
* This is primarily an internal method used by `loadTexture`, but is exposed for the use of plugins and custom classes.
*
* @param frame The Frame to be used by the texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Stops an automatically scrolling TileSprite.
* @return This instance.
*/
stopScroll(): void;
/**
* Override this method in your own custom objects to handle any update requirements.
* It is called immediately after `preUpdate` and before `postUpdate`.
* Remember if this Game Object has any children you should call update on those too.
*/
update(): void;
}
/**
* This is the core internal game clock.
*
* It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens,
* and also handles the standard Timer pool.
*
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
*
* There are different *types* of time in Phaser:
*
* - ***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.
*/
class Time {
/**
* This is the core internal game clock.
*
* It manages the elapsed time and calculation of elapsed values, used for game object motion and tweens,
* and also handles the standard Timer pool.
*
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
*
* There are different *types* of time in Phaser:
*
* - ***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.
*/
constructor(game: Phaser.Game);
/**
* If true then advanced profiling, including the fps rate, fps min/max, suggestedFps and msMin/msMax are updated. This isn't expensive, but displaying it with {@link Phaser.Utils.Debug#text} can be, especially in WebGL mode.
*/
advancedTiming: boolean;
/**
* The 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.
*/
desiredFps: number;
/**
* The desiredFps multiplier as used by Game.update.
*/
desiredFpsMult: number;
/**
* 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.
*/
elapsed: number;
/**
* A {@link Phaser.Timer} object bound to the master clock (this Time object) which events can be added to.
*/
events: Phaser.Timer;
/**
* The time in ms since the last time update, in milliseconds, based on `time`.
*
* This value is corrected for game pauses and will be "about zero" after a game is resumed.
*
* _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.
*/
elapsedMS: number;
/**
* Advanced timing result: Frames per second.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
*/
fps: number;
/**
* Advanced timing result: The highest rate the fps has reached (usually no higher than 60fps).
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
* This value can be manually reset.
*/
fpsMax: number;
/**
* Advanced timing result: The lowest rate the fps has dropped to.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
* This value can be manually reset.
*/
fpsMin: number;
/**
* Advanced timing result: The number of render frames record in the last second.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
*/
frames: number;
/**
* Local reference to game.
*/
game: Phaser.Game;
lastTime: number;
/**
* Advanced timing result: The maximum amount of time the game has taken between consecutive frames.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
* This value can be manually reset.
*/
msMax: number;
/**
* Advanced timing result: The minimum amount of time the game has taken between consecutive frames.
*
* Only calculated if {@link Phaser.Time#advancedTiming advancedTiming} is enabled.
* This value can be manually reset.
* Default: 1000
*/
msMin: number;
/**
* An increasing value representing cumulative milliseconds since an undisclosed epoch.
*
* While this value is in milliseconds and can be used to compute time deltas,
* it must must _not_ be used with `Date.now()` as it may not use the same epoch / starting reference.
*
* The source may either be from a high-res source (eg. if RAF is available) or the standard Date.now;
* the value can only be relied upon within a particular game instance.
*/
now: number;
pausedTime: number;
/**
* Records how long the game was last paused, in milliseconds.
* (This is not updated until the game is resumed.)
*/
pauseDuration: number;
/**
* 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`.
*/
physicsElapsed: number;
/**
* The physics update delta, in milliseconds - equivalent to `physicsElapsed * 1000`.
*/
physicsElapsedMS: number;
/**
* The `now` when the previous update occurred.
*/
prevTime: number;
/**
* Scaling factor to make the game move smoothly in slow motion
* - 1.0 = normal speed
* - 2.0 = half speed
* Default: 1
*/
slowMotion: number;
/**
* The suggested frame rate for your game, based on an averaged real frame rate.
* This value is only populated if `Time.advancedTiming` is enabled.
*
* _Note:_ This is not available until after a few frames have passed; until then
* it's set to the same value as desiredFps.
*/
suggestedFps: number;
/**
* The `Date.now()` value when the time was last updated.
*/
time: number;
/**
* The time when the next call is expected when using setTimer to control the update loop
*/
timeExpected: number;
/**
* The value that setTimeout needs to work out when to next update
*/
timeToCall: number;
/**
* Adds an existing Phaser.Timer object to the Timer pool.
*
* @param timer An existing Phaser.Timer object.
* @return The given Phaser.Timer object.
*/
add(timer: Phaser.Timer): Phaser.Timer;
/**
* Called automatically by Phaser.Game after boot. Should not be called directly.
*/
boot(): void;
/**
* Creates a new stand-alone Phaser.Timer object.
*
* @param autoDestroy A Timer that is set to automatically destroy itself will do so after all of its events have been dispatched (assuming no looping events). - Default: true
* @return The Timer object that was created.
*/
create(autoDestroy?: boolean): Phaser.Timer;
/**
* How long has passed since the given time (in seconds).
*
* @param since The time you want to measure (in seconds).
* @return Duration between given time and now (in seconds).
*/
elapsedSecondsSince(since: number): number;
/**
* How long has passed since the given time.
*
* @param since The time you want to measure against.
* @return The difference between the given time and now.
*/
elapsedSince(since: number): number;
/**
* Remove all Timer objects, regardless of their state and clears all Timers from the {@link Phaser.Time#events events} timer.
*/
removeAll(): void;
/**
* Resets the private _started value to now and removes all currently running Timers.
*/
reset(): void;
/**
* The number of seconds that have elapsed since the game was started.
* @return The number of seconds that have elapsed since the game was started.
*/
totalElapsedSeconds(): number;
/**
* Updates the game clock and 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}.
*/
update(time: number): void;
}
/**
* A Timer is a way to create and manage {@link Phaser.TimerEvent timer events} that wait for a specific duration and then run a callback.
* Many different timer events, with individual delays, can be added to the same Timer.
*
* All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second.
*
* Timers are based on 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.
*/
class Timer {
/**
* A Timer is a way to create and manage {@link Phaser.TimerEvent timer events} that wait for a specific duration and then run a callback.
* Many different timer events, with individual delays, can be added to the same Timer.
*
* All Timer delays are in milliseconds (there are 1000 ms in 1 second); so a delay value of 250 represents a quarter of a second.
*
* Timers are based on 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
*/
constructor(game: Phaser.Game, autoDestroy?: boolean);
/**
* Number of milliseconds in half a second.
*/
static HALF: number;
/**
* Number of milliseconds in a minute.
*/
static MINUTE: number;
/**
* Number of milliseconds in a quarter of a second.
*/
static QUARTER: number;
/**
* Number of milliseconds in a second.
*/
static SECOND: number;
/**
* If true, the timer will automatically destroy itself after all the events have been dispatched (assuming no looping events).
*/
autoDestroy: boolean;
/**
* The duration in ms remaining until the next event will occur.
*/
duration: number;
/**
* An array holding all of this timers Phaser.TimerEvent objects. Use the methods add, repeat and loop to populate it.
*/
events: Phaser.TimerEvent[];
/**
* An expired Timer is one in which all of its events have been dispatched and none are pending.
*/
expired: boolean;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* The number of pending events in the queue.
*/
length: number;
/**
* The duration in milliseconds that this Timer has been running for.
*/
ms: number;
/**
* The time at which the next event will occur.
*/
next: number;
/**
* The time the next tick will occur.
*/
nextTick: number;
/**
* This signal will be dispatched when this Timer has completed which means that there are no more events in the queue.
*
* The signal is supplied with one argument, `timer`, which is this Timer object.
*/
onComplete: Phaser.Signal;
/**
* True if the Timer is actively running.
*
* Do not modify this boolean - use {@link Phaser.Timer#pause pause} (and {@link Phaser.Timer#resume resume}) to pause the timer.
*/
running: boolean;
/**
* The paused state of the Timer. You can pause the timer by calling Timer.pause() and Timer.resume() or by the game pausing.
*/
paused: boolean;
/**
* The duration in seconds that this Timer has been running for.
*/
seconds: number;
/**
* Adds a new Event to this Timer.
*
* The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running.
* The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time.
*
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
*
* @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
* @param callback The callback that will be called when the timer event occurs.
* @param callbackContext The context in which the callback will be called.
* @param args Additional arguments that will be supplied to the callback.
* @return The Phaser.TimerEvent object that was created.
*/
add(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
/**
* Clears any events from the Timer which have pendingDelete set to true and then resets the private _len and _i values.
*/
clearPendingEvents(): void;
/**
* Destroys this Timer. Any pending Events are not dispatched.
* The onComplete callbacks won't be called.
*/
destroy(): void;
/**
* Adds a new looped Event to this Timer that will repeat forever or until the Timer is stopped.
*
* The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running.
* The delay is in relation to when the Timer starts, not the time it was added. If the Timer is already running the delay will be calculated based on the timers current time.
*
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
*
* @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
* @param callback The callback that will be called when the timer event occurs.
* @param callbackContext The context in which the callback will be called.
* @param args Additional arguments that will be supplied to the callback.
* @return The Phaser.TimerEvent object that was created.
*/
loop(delay: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
/**
* Orders the events on this Timer so they are in tick order.
* This is called automatically when new events are created.
*/
order(): void;
/**
* Pauses the Timer and all events in the queue.
*/
pause(): void;
/**
* Removes a pending TimerEvent from the queue.
*
* @param event The event to remove from the queue.
*/
remove(event: Phaser.TimerEvent): boolean;
/**
* Removes all Events from this Timer and all callbacks linked to onComplete, but leaves the Timer running.
* The onComplete callbacks won't be called.
*/
removeAll(): void;
/**
* Adds a new TimerEvent that will always play through once and then repeat for the given number of iterations.
*
* The event will fire after the given amount of `delay` in milliseconds has passed, once the Timer has started running.
* The delay is in relation to when the Timer starts, not the time it was added.
* If the Timer is already running the delay will be calculated based on the timers current time.
*
* Make sure to call {@link Phaser.Timer#start start} after adding all of the Events you require for this Timer.
*
* @param delay The number of milliseconds, in {@link Phaser.Time game time}, before the timer event occurs.
* @param repeatCount The number of times the event will repeat once is has finished playback. A repeatCount of 1 means it will repeat itself once, playing the event twice in total.
* @param callback The callback that will be called when the timer event occurs.
* @param callbackContext The context in which the callback will be called.
* @param args Additional arguments that will be supplied to the callback.
* @return The Phaser.TimerEvent object that was created.
*/
repeat(delay: number, repeatCount: number, callback: Function, callbackContext?: any, ...args: any[]): Phaser.TimerEvent;
/**
* Resumes the Timer and updates all pending events.
*/
resume(): void;
/**
* Sort handler used by Phaser.Timer.order.
*/
sortHandler(a: any, b: any): number;
/**
* Starts this Timer running.
*
* @param delay The number of milliseconds, in {@link Phaser.Time game time}, that should elapse before the Timer will start.
*/
start(startDelay?: number): void;
/**
* Stops this Timer from running. Does not cause it to be destroyed if autoDestroy is set to true.
*
* @param clearEvents If true all the events in Timer will be cleared, otherwise they will remain. - Default: true
*/
stop(clearEvents?: boolean): void;
/**
* The main Timer update event, called automatically by Phaser.Time.update.
*
* @param time The time from the core game clock.
* @return True if there are still events waiting to be dispatched, otherwise false if this Timer can be destroyed.
*/
update(time: number): boolean;
}
/**
* A TimerEvent is a single event that is processed by a Phaser.Timer.
*
* It consists of a delay, which is a value in milliseconds after which the event will fire.
* When the event fires it calls a specific callback with the specified arguments.
*
* TimerEvents are removed by their parent timer once finished firing or repeating.
*
* Use {@link Phaser.Timer#add}, {@link Phaser.Timer#repeat}, or {@link Phaser.Timer#loop} methods to create a new event.
*/
class TimerEvent {
/**
* A TimerEvent is a single event that is processed by a Phaser.Timer.
*
* It consists of a delay, which is a value in milliseconds after which the event will fire.
* When the event fires it calls a specific callback with the specified arguments.
*
* TimerEvents are removed by their parent timer once finished firing or repeating.
*
* Use {@link Phaser.Timer#add}, {@link Phaser.Timer#repeat}, or {@link Phaser.Timer#loop} methods to create a new event.
*
* @param timer The Timer object that this TimerEvent belongs to.
* @param delay The delay in ms at which this TimerEvent fires.
* @param tick The tick is the next game clock time that this event will fire at.
* @param repeatCount If this TimerEvent repeats it will do so this many times.
* @param loop True if this TimerEvent loops, otherwise false.
* @param callback The callback that will be called when the TimerEvent occurs.
* @param callbackContext The context in which the callback will be called.
* @param arguments Additional arguments to be passed to the callback.
*/
constructor(timer: Phaser.Timer, delay: number, tick: number, repeatCount: number, loop: boolean, callback: Function, callbackContext: any, ...args: any[]);
/**
* Additional arguments to be passed to the callback.
*/
args: any[];
/**
* The callback that will be called when the TimerEvent occurs.
*/
callback: Function;
/**
* The context in which the callback will be called.
*/
callbackContext: any;
/**
* The delay in ms at which this TimerEvent fires.
*/
delay: number;
/**
* True if this TimerEvent loops, otherwise false.
*/
loop: boolean;
/**
* A flag that controls if the TimerEvent is pending deletion.
*/
pendingDelete: boolean;
/**
* If this TimerEvent repeats it will do so this many times.
*/
repeatCount: number;
/**
* The tick is the next game clock time that this event will fire at.
*/
tick: number;
/**
* The Timer object that this TimerEvent belongs to.
*/
timer: Phaser.Timer;
}
/**
* Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch.
*
* You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you.
*/
class Touch {
/**
* Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch.
*
* You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you.
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* The context under which callbacks are called.
*/
callbackContext: any;
/**
* Touch events will only be processed if enabled.
* Default: true
*/
enabled: boolean;
/**
* The browser touch DOM event. Will be set to null if no touch event has ever been received.
*/
event: any;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* If true the TouchEvent will have prevent.default called on it.
* Default: true
*/
preventDefault: boolean;
/**
* A callback that can be fired on a touchCancel event.
*/
touchCancelCallback: Function;
/**
* A callback that can be fired on a touchEnd event.
*/
touchEndCallback: Function;
/**
* A callback that can be fired on a touchEnter event.
*/
touchEnterCallback: Function;
/**
* A callback that can be fired on a touchLeave event.
*/
touchLeaveCallback: Function;
/**
* A callback that can be fired on a touchMove event.
*/
touchMoveCallback: Function;
/**
* A callback that can be fired on a touchStart event.
*/
touchStartCallback: Function;
/**
* 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`.
*/
touchLockCallbacks: Function[];
/**
* 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?
*/
addTouchLockCallback(callback: Function, context?: any, onEnd?: boolean): void;
/**
* 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.
*/
removeTouchLockCallback(callback: Function, context?: any): boolean;
/**
* Consumes all touchmove events on the document (only enable this if you know you need it!).
*/
consumeTouchMove(): void;
/**
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome).
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchCancel(event: any): void;
/**
* The handler for the touchend events.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchEnd(event: any): void;
/**
* For touch enter and leave its a list of the touch points that have entered or left the target.
* Doesn't appear to be supported by most browsers on a canvas element yet.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchEnter(event: any): void;
/**
* For touch enter and leave its a list of the touch points that have entered or left the target.
* Doesn't appear to be supported by most browsers on a canvas element yet.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchLeave(event: any): void;
/**
* The handler for the touchmove events.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchMove(event: any): void;
/**
* The internal method that handles the touchstart event from the browser.
*
* @param event The native event from the browser. This gets stored in Touch.event.
*/
onTouchStart(event: any): void;
/**
* Starts the event listeners running.
*/
start(): void;
/**
* Stop the event listeners.
*/
stop(): void;
}
/**
* A Tween allows you to alter one or more properties of a target object over a defined period of time.
* This can be used for things such as alpha fading Sprites, scaling them or motion.
* Use `Tween.to` or `Tween.from` to set-up the tween values. You can create multiple tweens on the same object
* by calling Tween.to multiple times on the same Tween. Additional tweens specified in this way become "child" tweens and
* are played through in sequence. You can use Tween.timeScale and Tween.reverse to control the playback of this Tween and all of its children.
*/
class Tween {
/**
* A Tween allows you to alter one or more properties of a target object over a defined period of time.
* This can be used for things such as alpha fading Sprites, scaling them or motion.
* Use `Tween.to` or `Tween.from` to set-up the tween values. You can create multiple tweens on the same object
* by calling Tween.to multiple times on the same Tween. Additional tweens specified in this way become "child" tweens and
* are played through in sequence. You can use Tween.timeScale and Tween.reverse to control the playback of this Tween and all of its children.
*
* @param target The target object, such as a Phaser.Sprite or Phaser.Sprite.scale.
* @param game Current game instance.
* @param manager The TweenManager responsible for looking after this Tween.
*/
constructor(target: any, game: Phaser.Game, manager: Phaser.TweenManager);
/**
* If this Tween is chained to another this holds a reference to it.
*/
chainedTween: Phaser.Tween;
/**
* The current Tween child being run.
*/
current: number;
/**
* 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.
*/
frameBased: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state or waiting to start are considered as being running.
*/
isRunning: boolean;
/**
* Is this Tween paused or not?
*/
isPaused: boolean;
/**
* Reference to the TweenManager responsible for updating this Tween.
*/
manager: Phaser.TweenManager;
/**
* The onChildComplete event is fired when the Tween or any of its children completes.
* Fires every time a child completes unless a child is set to repeat forever.
* It will be sent 2 parameters: the target object and this tween.
*/
onChildComplete: Phaser.Signal;
/**
* The onComplete event is fired when the Tween and all of its children completes. Does not fire if the Tween is set to loop or repeatAll(-1).
* It will be sent 2 parameters: the target object and this tween.
*/
onComplete: Phaser.Signal;
/**
* The onLoop event is fired if the Tween, or any child tweens loop.
* It will be sent 2 parameters: the target object and this tween.
*/
onLoop: Phaser.Signal;
/**
* The onRepeat event is fired if the Tween and all of its children repeats. If this tween has no children this will never be fired.
* It will be sent 2 parameters: the target object and this tween.
*/
onRepeat: Phaser.Signal;
/**
* The onStart event is fired when the Tween begins. If there is a delay before the tween starts then onStart fires after the delay is finished.
* It will be sent 2 parameters: the target object and this tween.
*/
onStart: Phaser.Signal;
/**
* True if this Tween is ready to be deleted by the TweenManager.
*/
pendingDelete: boolean;
/**
* Target property cache used when building the child data values.
*/
properties: any;
/**
* If the Tween and any child tweens are set to repeat this contains the current repeat count.
*/
repeatCounter: number;
/**
* If set to `true` the current tween will play in reverse.
* If the tween hasn't yet started this has no effect.
* If there are child tweens then all child tweens will play in reverse from the current point.
*/
reverse: boolean;
/**
* The target object, such as a Phaser.Sprite or property like Phaser.Sprite.scale.
*/
target: any;
/**
* An Array of TweenData objects that comprise the different parts of this Tween.
*/
timeline: Phaser.TweenData[];
/**
* The speed at which the tweens will run. A value of 1 means it will match the game frame rate. 0.5 will run at half the frame rate. 2 at double the frame rate, etc.
* If a tweens duration is 1 second but timeScale is 0.5 then it will take 2 seconds to complete.
* Default: 1
*/
timeScale: number;
/**
* Gets the total duration of this Tween, including all child tweens, in milliseconds.
*/
totalDuration: number;
/**
* This method allows you to chain tweens together. Any tween chained to this tween will have its `Tween.start` method called
* as soon as this tween completes. If this tween never completes (i.e. repeatAll or loop is set) then the chain will never progress.
* Note that `Tween.onComplete` will fire when *this* tween completes, not when the whole chain completes.
* For that you should listen to `onComplete` on the final tween in your chain.
*
* If you pass multiple tweens to this method they will be joined into a single long chain.
* For example if this is Tween A and you pass in B, C and D then B will be chained to A, C will be chained to B and D will be chained to C.
* Any previously chained tweens that may have been set will be overwritten.
*
* @param tweens One or more tweens that will be chained to this one.
* @return This tween. Useful for method chaining.
*/
chain(...args: any[]): Phaser.Tween;
/**
* Sets the delay in milliseconds before this tween will start. If there are child tweens it sets the delay before the first child starts.
* The delay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to delay.
* If you have child tweens and pass -1 as the index value it sets the delay across all of them.
*
* @param duration The amount of time in ms that the Tween should wait until it begins once started is called. Set to zero to remove any active delay.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children.
* @return This tween. Useful for method chaining.
*/
delay(duration: number, index?: number): Phaser.Tween;
/**
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
* If you have child tweens and pass -1 as the index value it sets the easing function defined here across all of them.
*
* @param ease The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the easing function on all children.
* @return This tween. Useful for method chaining.
*/
easing(ease: Function, index?: number): Phaser.Tween;
/**
* Set easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
* If you have child tweens and pass -1 as the index value it sets the easing function defined here across all of them.
*
* @param ease The easing function this tween will use, i.e. Phaser.Easing.Linear.None.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the easing function on all children.
* @return This tween. Useful for method chaining.
*/
easing(ease: string, index?: number): Phaser.Tween;
/**
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. 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.
*/
from(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. 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.
*/
from(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* This will generate an array populated with the tweened object values from start to end.
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
* It ignores delay and repeat counts and any chained tweens, but does include child tweens.
* Just one play through of the tween data is returned, including yoyo if set.
*
* @param frameRate The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates. - Default: 60
* @param data If given the generated data will be appended to this array, otherwise a new array will be returned.
* @return An array of tweened values.
*/
generateData(frameRate?: number, data?: any): any[];
/**
* Sets the interpolation function the tween will use. By default it uses Phaser.Math.linearInterpolation.
* Also available: Phaser.Math.bezierInterpolation and Phaser.Math.catmullRomInterpolation.
* The interpolation function is only used if the target properties is an array.
* If you have child tweens and pass -1 as the index value and it will set the interpolation function across all of them.
*
* @param interpolation The interpolation function to use (Phaser.Math.linearInterpolation by default)
* @param context The context under which the interpolation function will be run.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the interpolation function on all children.
* @return This tween. Useful for method chaining.
*/
interpolation(interpolation: Function, context?: any, index?: number): Phaser.Tween;
/**
* Enables the looping of this tween. The tween will loop forever, and onComplete will never fire.
*
* If `value` is `true` then this is the same as setting `Tween.repeatAll(-1)`.
* If `value` is `false` it is the same as setting `Tween.repeatAll(0)` and will reset the `repeatCounter` to zero.
*
* Usage:
* game.add.tween(p).to({ x: 700 }, 1000, Phaser.Easing.Linear.None, true)
* .to({ y: 300 }, 1000, Phaser.Easing.Linear.None)
* .to({ x: 0 }, 1000, Phaser.Easing.Linear.None)
* .to({ y: 0 }, 1000, Phaser.Easing.Linear.None)
* .loop();
*
* @param value If `true` this tween will loop once it reaches the end. Set to `false` to remove an active loop. - Default: true
* @return This tween. Useful for method chaining.
*/
loop(value?: boolean): Phaser.Tween;
/**
* Sets a callback to be fired each time this tween updates.
*
* @param callback The callback to invoke each time this tween is updated. Set to `null` to remove an already active callback.
* @param callbackContext The context in which to call the onUpdate callback.
* @return This tween. Useful for method chaining.
*/
onUpdateCallback(callback: Function, callbackContext?: any): Phaser.Tween;
/**
* Pauses the tween. Resume playback with Tween.resume.
*/
pause(): void;
/**
* Sets the number of times this tween will repeat.
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to repeat.
* If you have child tweens and pass -1 as the index value it sets the number of times they'll repeat across all of them.
* If you wish to define how many times this Tween and all children will repeat see Tween.repeatAll.
*
* @param total How many times a tween should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
* @param repeat This is the amount of time to pause (in ms) before the repeat will start.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeat value on all the children.
* @return This tween. Useful for method chaining.
*/
repeat(total: number, repeatDelay?: number, index?: number): Phaser.Tween;
/**
* Sets the delay in milliseconds before this tween will repeat itself.
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
*
* @param duration The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active repeatDelay.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the repeatDelay on all the children.
* @return This tween. Useful for method chaining.
*/
repeatDelay(duration: number, index?: number): Phaser.Tween;
/**
* Set how many times this tween and all of its children will repeat.
* A tween (A) with 3 children (B,C,D) with a `repeatAll` value of 2 would play as: ABCDABCD before completing.
*
* @param total How many times this tween and all children should repeat before completing. Set to zero to remove an active repeat. Set to -1 to repeat forever.
* @return This tween. Useful for method chaining.
*/
repeatAll(total?: number): Phaser.Tween;
/**
* Resumes a paused tween.
*/
resume(): void;
/**
* Starts the tween running. Can also be called by the autoStart parameter of `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.
*/
start(index?: number): Phaser.Tween;
/**
* 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.
*/
stop(complete?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. 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.
*/
to(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. 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.
*/
to(properties: any, duration?: number, ease?: string, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* Core tween update function called by the TweenManager. Does not need to be invoked directly.
*
* @param time A timestamp passed in by the TweenManager.
* @return false if the tween and all child tweens have completed and should be deleted from the manager, otherwise true (still active).
*/
update(time: number): boolean;
/**
* Updates either a single TweenData or all TweenData objects properties to the given value.
* Used internally by methods like Tween.delay, Tween.yoyo, etc. but can also be called directly if you know which property you want to tweak.
* The property is not checked, so if you pass an invalid one you'll generate a run-time error.
*
* @param property The property to update.
* @param value The value to set the property to.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the delay on all the children.
* @return This tween. Useful for method chaining.
*/
updateTweenData(property: string, value: number | Function, index?: number): Phaser.Tween;
/**
* A Tween that has yoyo set to true will run through from its starting values to its end values and then play back in reverse from end to start.
* Used in combination with repeat you can create endless loops.
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to yoyo.
* If you have child tweens and pass -1 as the index value it sets the yoyo property across all of them.
* If you wish to yoyo this Tween and all of its children then see Tween.yoyoAll.
*
* @param enable Set to true to yoyo this tween, or false to disable an already active yoyo.
* @param yoyoDelay This is the amount of time to pause (in ms) before the yoyo will start.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set yoyo on all the children.
* @return This tween. Useful for method chaining.
*/
yoyo(enable: boolean, yoyoDelay?: number, index?: number): Phaser.Tween;
/**
* Sets the delay in milliseconds before this tween will run a yoyo (only applies if yoyo is enabled).
* The repeatDelay is invoked as soon as you call `Tween.start`. If the tween is already running this method doesn't do anything for the current active tween.
* If you have not yet called `Tween.to` or `Tween.from` at least once then this method will do nothing, as there are no tweens to set repeatDelay on.
* If you have child tweens and pass -1 as the index value it sets the repeatDelay across all of them.
*
* @param duration The amount of time in ms that the Tween should wait until it repeats or yoyos once start is called. Set to zero to remove any active yoyoDelay.
* @param index If this tween has more than one child this allows you to target a specific child. If set to -1 it will set the yoyoDelay on all the children.
* @return This tween. Useful for method chaining.
*/
yoyoDelay(duration: number, index?: number): Phaser.Tween;
}
/**
* A Phaser.Tween contains at least one TweenData object. It contains all of the tween data values, such as the
* starting and ending values, the ease function, interpolation and duration. The Tween acts as a timeline manager for
* TweenData objects and can contain multiple TweenData objects.
*/
class TweenData {
/**
* A Phaser.Tween contains at least one TweenData object. It contains all of the tween data values, such as the
* starting and ending values, the ease function, interpolation and duration. The Tween acts as a timeline manager for
* TweenData objects and can contain multiple TweenData objects.
*
* @param parent The Tween that owns this TweenData object.
*/
constructor(parent: Phaser.Tween);
static COMPLETE: number;
static LOOPED: number;
static PENDING: number;
static RUNNING: number;
/**
* The amount to delay by until the Tween starts (in ms). Only applies to the start, use repeatDelay to handle repeats.
*/
delay: number;
/**
* Current time value.
*/
dt: number;
/**
* The duration of the tween in ms.
* Default: 1000
*/
duration: number;
/**
* The easing function used for the Tween.
* Default: Phaser.Easing.Default
*/
easingFunction: Function;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* When a Tween is yoyoing this value holds if it's currently playing forwards (false) or in reverse (true).
*/
inReverse: boolean;
/**
* True if the Tween will use interpolation (i.e. is an Array to Array tween)
*/
interpolate: boolean;
interpolateFunctionContext: Phaser.Math;
/**
* The interpolation function context used for the Tween.
* Default: Phaser.Math
*/
interpolationContext: Phaser.Math;
/**
* The interpolation function used for the Tween.
* Default: Phaser.Math.linearInterpolation
*/
interpolationFunction: Function;
/**
* If the tween is running this is set to `true`. Unless Phaser.Tween a TweenData that is waiting for a delay to expire is *not* considered as running.
*/
isRunning: boolean;
/**
* Is this a from tween or a to tween?
*/
isFrom: boolean;
/**
* The Tween which owns this TweenData.
*/
parent: Phaser.Tween;
/**
* A value between 0 and 1 that represents how far through the duration this tween is.
*/
percent: number;
/**
* If the Tween is set to repeat this contains the current repeat count.
*/
repeatCounter: number;
/**
* The time the Tween started or null if it hasn't yet started.
*/
startTime: number;
/**
* The current calculated value.
*/
value: number;
/**
* True if the Tween is set to yoyo, otherwise false.
*/
yoyo: boolean;
/**
* The amount of time in ms between yoyos of this tween.
*/
yoyoDelay: number;
/**
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
*
* @param properties The properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden at will.
* @param delay Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This ignores any chained tweens.
* @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
* @return This Tween object.
*/
from(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData;
/**
* This will generate an array populated with the tweened object values from start to end.
* It works by running the tween simulation at the given frame rate based on the values set-up in Tween.to and Tween.from.
* Just one play through of the tween data is returned, including yoyo if set.
*
* @param frameRate The speed in frames per second that the data should be generated at. The higher the value, the larger the array it creates. - Default: 60
* @return An array of tweened values.
*/
generateData(frameRate?: number): any[];
/**
* Checks if this Tween is meant to repeat or yoyo and handles doing so.
* @return Either Phaser.TweenData.LOOPED or Phaser.TweenData.COMPLETE.
*/
repeat(): number;
/**
* Starts the Tween running.
* @return This Tween object.
*/
start(): Phaser.TweenData;
/**
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
*
* @param properties The properties you want to tween, such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden at will.
* @param delay Delay before this tween will start, defaults to 0 (no delay). Value given is in ms.
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This ignores any chained tweens.
* @param yoyo A tween that yoyos will reverse itself and play backwards automatically. A yoyo'd tween doesn't fire the Tween.onComplete event, so listen for Tween.onLoop instead.
* @return This Tween object.
*/
to(properties: any, duration?: number, ease?: Function, delay?: number, repeat?: number, yoyo?: boolean): Phaser.TweenData;
/**
* Updates this Tween. This is called automatically by Phaser.Tween.
*
* @param time A timestamp passed in by the Tween parent.
* @return The current status of this Tween. One of the Phaser.TweenData constants: PENDING, RUNNING, LOOPED or COMPLETE.
*/
update(time: number): number;
}
/**
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by http://soledadpenades.com.
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
*/
class TweenManager {
/**
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by http://soledadpenades.com.
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* 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.
*/
frameBased: boolean;
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Add a new tween into the TweenManager.
*
* @param tween The tween object you want to add.
* @return The tween object you added to the manager.
*/
add(tween: Phaser.Tween): Phaser.Tween;
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @param object Object the tween will be run on.
* @return The newly created tween object.
*/
create(object: any): Phaser.Tween;
/**
* Get all the tween objects in an array.
* @return Array with all tween objects.
*/
getAll(): Phaser.Tween[];
/**
* Checks to see if a particular Sprite is currently being tweened.
*
* @param object The object to check for tweens against.
* @return Returns true if the object is currently being tweened, false if not.
*/
isTweening(object: any): boolean;
/**
* Remove a tween from this manager.
*
* @param tween The tween object you want to remove.
*/
remove(tween: Phaser.Tween): Phaser.Tween;
/**
* Remove all tweens running and in the queue. Doesn't call any of the tween onComplete events.
*/
removeAll(): void;
/**
* Remove all tweens from a specific object, array of objects or Group.
*
* @param obj The object you want to remove the tweens from.
* @param children If passing a group, setting this to true will remove the tweens from all of its children instead of the group itself. - Default: true
*/
removeFrom(obj: any, children?: boolean): void;
/**
* Resumes all currently paused tweens.
*/
resumeAll(): void;
/**
* Update all the tween objects you added to this manager.
* @return Return false if there's no tween to update, otherwise return true.
*/
update(): boolean;
/**
* Pauses all currently running tweens.
*/
pauseAll(): void;
}
class Utils {
/**
* Gets an object's property by string.
*
* @param obj The object to traverse.
* @param prop The property whose value will be returned.
* @return - The value of the property or `undefined` if the property isn't found.
*/
static getProperty(obj: any, prop: string): any;
/**
* 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.
*/
static setProperty(obj: any, prop: string, value: any): any;
/**
* Generate a random bool result based on the chance value.
*
* Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance
* of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed.
*
* @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%).
* @return True if the roll passed, or false otherwise.
*/
static chanceRoll(chance: number): boolean;
/**
* Choose between one of two values randomly.
*
* @param choice1
* @param choice2
* @return The randomly selected choice
*/
static randomChoice(choice1: string | number, choice2: any): any;
/**
* Takes the given string and reverses it, returning the reversed string.
* For example if given the string `Atari 520ST` it would return `TS025 iratA`.
*
* @param string The string to be reversed.
* @return The reversed string.
*/
static reverseString(string: string): string;
/**
* Get a unit dimension from a string.
*
* @param size The size to parse.
* @param dimension The window dimension to check.
* @return The parsed dimension.
*/
static parseDimension(size: any, dimension: number): number;
/**
* Takes the given string and pads it out, to the length required, using the character
* specified. For example if you need a string to be 6 characters long, you can call:
*
* `pad('bob', 6, '-', 2)`
*
* This would return: `bob---` as it has padded it out to 6 characters, using the `-` on the right.
*
* You can also use it to pad numbers (they are always returned as strings):
*
* `pad(512, 6, '0', 1)`
*
* Would return: `000512` with the string padded to the left.
*
* If you don't specify a direction it'll pad to both sides:
*
* `pad('c64', 7, '*')`
*
* Would return: `**c64**`
*
* @param str The target string. `toString()` will be called on the string, which means you can also pass in common data types like numbers.
* @param len The number of characters to be added.
* @param pad The string to pad it out with (defaults to a space). - Default: " "
* @param dir The direction dir = 1 (left), 2 (right), 3 (both). - Default: 3
* @return The padded string.
*/
static pad(str: string, len?: number, pad?: string, dir?: number): string;
/**
* This is a slightly modified version of jQuery.isPlainObject.
* A plain object is an object whose internal class property is [object Object].
*
* @param obj The object to inspect.
* @return - true if the object is plain, otherwise false.
*/
static isPlainObject(object: any): boolean;
/**
* This is a slightly modified version of http://api.jquery.com/jQuery.extend/
*
* @param deep Perform a deep copy?
* @param target The target object to copy to.
* @return The extended object.
*/
static extend(deep: boolean, target: any, ...args: any[]): any;
/**
* Mixes in an existing mixin object with the target.
*
* Values in the mixin that have either `get` or `set` functions are created as properties via `defineProperty`
* _except_ if they also define a `clone` method - if a clone method is defined that is called instead and
* the result is assigned directly.
*
* @param target The target object to receive the new functions.
* @param mixin The object to copy the functions from.
* @param replace If the target object already has a matching function should it be overwritten or not?
*/
static mixinPrototype(target: any, mixin: any, replace?: boolean): void;
/**
* Mixes the source object into the destination object, returning the newly modified destination object.
* Based on original code by @mudcube
*
* @param from The object to copy (the source object).
* @param to The object to copy to (the destination object).
* @return The modified destination object.
*/
static mixin(from: T, to: any): T;
}
module Utils {
/**
* A collection of methods for displaying debug information about game objects.
*
* If your game is running in Canvas mode, then you should invoke all of the Debug methods from
* your 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.
*
* If your game is running in WebGL then Debug will create a Sprite that is placed at the top of the Stage display list and bind a canvas texture
* to it, which must be uploaded every frame. Be advised: this is very expensive, especially in browsers like Firefox. So please only enable Debug
* in WebGL mode if you really need it (or your desktop can cope with it well) and disable it for production!
*/
class Debug {
/**
* A collection of methods for displaying debug information about game objects.
*
* If your game is running in Canvas mode, then you should invoke all of the Debug methods from
* your 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.
*
* If your game is running in WebGL then Debug will create a Sprite that is placed at the top of the Stage display list and bind a canvas texture
* to it, which must be uploaded every frame. Be advised: this is very expensive, especially in browsers like Firefox. So please only enable Debug
* in WebGL mode if you really need it (or your desktop can cope with it well) and disable it for production!
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* In WebGL mode this BitmapData contains a copy of the debug canvas.
*/
bmd: Phaser.BitmapData;
/**
* The canvas to which Debug calls draws.
*/
canvas: HTMLCanvasElement;
/**
* The spacing between columns.
* Default: 100
*/
columnWidth: number;
/**
* The 2d context of the canvas.
*/
context: CanvasRenderingContext2D;
/**
* The alpha of the Debug context, set before all debug information is rendered to it.
* Default: 1
*/
currentAlpha: number;
/**
* The current X position the debug information will be rendered at.
*/
currentX: number;
/**
* The current Y position the debug information will be rendered at.
*/
currentY: number;
/**
* Does the canvas need re-rendering?
*/
dirty: boolean;
/**
* The font that the debug information is rendered in.
* Default: 14px Courier
*/
font: string;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The line height between the debug text.
* Default: 16
*/
lineHeight: number;
/**
* Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
* Default: true
*/
renderShadow: boolean;
/**
* If debugging in WebGL mode, this is the Image displaying the debug {@link #bmd BitmapData}.
*/
sprite: Phaser.Image;
/**
* Debug method to draw the last calculated path by AStar
*
* @param astar- The AStar plugin that you want to debug.
* @param x X position on camera for debug display.
* @param y Y position on camera for debug display.
* @param color Color to stroke the path line.
*/
AStar(astar: Phaser.Plugin.AStar, x: number, y: number, showVisited: boolean): void;
/**
* Internal method that boots the debug displayer.
*/
boot(): void;
/**
* Render a Sprites Physics body if it has one set. The body is rendered as a filled or stroked rectangle.
* This only works for Arcade Physics, Ninja Physics (AABB and Circle only) and Box2D Physics bodies.
* To display a P2 Physics body you should enable debug mode on the body when creating it.
*
* @param sprite The Sprite who's body will be rendered.
* @param color Color of the debug rectangle to be rendered. The format is a CSS color string such as '#ff0000' or 'rgba(255,0,0,0.5)'. - Default: 'rgba(0,255,0,0.4)'
* @param filled Render the body as a filled rectangle (true) or a stroked rectangle (false) - Default: true
*/
body(sprite: Phaser.Sprite, color?: string, filled?: boolean): void;
/**
* Render a Sprites Physic Body information.
*
* @param sprite The sprite to be rendered.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
bodyInfo(sprite: Phaser.Sprite, x: number, y: Number, color?: string): void;
/**
* Renders 'debug draw' data for the given Box2D body.
* This uses the standard debug drawing feature of Box2D, so colors will be decided by the Box2D engine.
*
* @param 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)'
*/
box2dBody(body: Phaser.Sprite, color?: string): void;
/**
* Renders 'debug draw' data for the Box2D world if it exists.
* This uses the standard debug drawing feature of Box2D, so colors will be decided by
* the Box2D engine.
*/
box2dWorld(): void;
/**
* Marks the follow {@link Phaser.Utils.Debug#target target} and {@link Phaser.Utils.Debug#deadzone deadzone}.
*
* @param camera The Phaser.Camera to show the debug information for.
* @param color Color of the debug shapes to be rendered (format is css color string).
* @param filled Render the shapes filled (default, true) or stroked (false). - Default: true
*/
camera(camera: Phaser.Camera, color?: string, filled?: boolean): void;
/**
* Render camera information including dimensions and location.
*
* @param camera The Phaser.Camera to show the debug information for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
cameraInfo(camera: Phaser.Camera, x: number, y: number, color?: string): void;
/**
* Destroy this object.
*/
destroy(): void;
/**
* 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.
*/
geom(object: any, color?: string, fiiled?: boolean, forceType?: number): void;
/**
* Render debug information about the Input object.
*
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
inputInfo(x: number, y: number, color?: string): void;
/**
* Renders Line information in the given color.
*
* @param line The Line to display the data for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
lineInfo(line: Phaser.Line, x: number, y: number, color?: string): void;
/**
* Renders Phaser.Key object information.
*
* @param key The Key to render the information for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
key(key: Phaser.Key, x?: number, y?: number, color?: string): void;
/**
* Internal method that outputs a single line of text split over as many columns as needed, one per parameter.
*/
line(...args: string[]): void;
/**
* Internal method that clears the canvas (if a Sprite) ready for a new debug session.
*/
preUpdate(): void;
/**
* Renders a single pixel at the given size.
*
* @param x X position of the pixel to be rendered.
* @param y Y position of the pixel to be rendered.
* @param color Color of the pixel (format is css color string).
* @param size The 'size' to render the pixel at. - Default: 2
*/
pixel(x: number, y: number, color?: string, size?: number): void;
/**
* Renders the Pointer.circle object onto the stage in green if down or 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)'
*/
pointer(pointer: Phaser.Pointer, hideIfUp?: boolean, downColor?: string, upColor?: string, color?: string): void;
/**
* Visually renders a QuadTree to the display.
*
* @param quadtree The quadtree to render.
* @param color The color of the lines in the quadtree.
*/
quadTree(quadtree: Phaser.QuadTree, color?: string): void;
/**
* Renders a Rectangle.
*
* @param object The rectangle to render.
* @param color Color of the debug info to be rendered (format is css color string).
* @param filled Render the rectangle as filled (default, true) or a stroked (false) - Default: true
*/
rectangle(object: Phaser.Rectangle, color?: string, filled?: boolean): void;
/**
* Prints a description of the {@link Phaser.Game#renderer renderer} and render session.
*
* @param x The X value the debug info will start from.
* @param y The Y value the debug info will start from.
* @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)'
*/
renderer(x?: number, y?: number, color?: string): void;
/**
* Clears the Debug canvas.
*/
reset(): void;
/**
* Renders the Rope's segments. Note: This is really expensive as it has to calculate new segments every time you call it
*
* @param rope The rope to display the segments of.
* @param color Color of the debug info to be rendered (format is css color string).
* @param filled Render the rectangle as a fillRect (default, true) or a strokeRect (false) - Default: true
*/
ropeSegments(rope: Phaser.Rope, color?: number, filled?: boolean): void;
/**
* Render Sound information, including decoded state, duration, volume and more.
*
* @param sound The sound object to debug.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
soundInfo(sound: Phaser.Sound, x: number, y: number, color?: string): void;
/**
* Renders the Sprites bounds. Note: This is really expensive as it has to calculate the bounds every time you call it!
*
* @param sprite The sprite to display the bounds of.
* @param color Color of the debug info to be rendered (format is css color string).
* @param filled Render the rectangle as a fillRect (default, true) or a strokeRect (false) - Default: true
*/
spriteBounds(sprite: any, color?: string, filled?: boolean): void;
/**
* Renders the sprite coordinates in local, positional and world space.
*
* @param sprite The sprite to display the coordinates for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
spriteCoords(sprite: any, x: number, y: number, color?: string): void;
/**
* Render debug infos (including name, bounds info, position and some other properties) about the Sprite.
*
* @param sprite The Sprite to display the information of.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
spriteInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void;
/**
* Render Sprite Input Debug information.
*
* @param sprite The sprite to display the input data for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
spriteInputInfo(sprite: Phaser.Sprite, x: number, y: number, color?: string): void;
/**
* Internal method that resets and starts the debug output values.
*
* @param x The X value the debug info will start from.
* @param y The Y value the debug info will start from.
* @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)'
* @param columnWidth The spacing between columns.
*/
start(x?: number, y?: number, color?: string, columnWidth?: number): void;
/**
* Internal method that stops the debug output.
*/
stop(): void;
/**
* Render a string of text.
*
* @param text The line of text to draw.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color Color of the debug info to be rendered (format is css color string).
* @param font The font of text to draw.
*/
text(text: string, x: number, y: number, color?: string, font?: string): void;
/**
* Render Timer information.
*
* @param timer The Phaser.Timer to show the debug information for.
* @param x X position of the debug info to be rendered.
* @param y Y position of the debug info to be rendered.
* @param color color of the debug info to be rendered. (format is css color string). - Default: 'rgb(255,255,255)'
*/
timer(timer: Phaser.Timer, x: number, y: number, color?: string): void;
}
}
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;
multiFire: boolean;
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, offsetX?: number, offsetY?: number): Phaser.Bullet;
fireAtPointer(pointer: Phaser.Pointer): Phaser.Bullet;
fireAtSprite(sprite: Phaser.Sprite): Phaser.Bullet;
fireAtXY(x: number, y: number): Phaser.Bullet;
fireMany(positions: any[], from?: any): Phaser.Bullet[];
fireOffset(offsetX?: number, offsetY?: 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;
}
/**
* "This world is but a canvas to our imagination." - Henry David Thoreau
*
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
* by stage limits and can be any size. You look into the world via cameras. All game objects live within
* the world at world-based coordinates. By default a world is created the same size as your Stage.
*/
class World extends Phaser.Group {
/**
* "This world is but a canvas to our imagination." - Henry David Thoreau
*
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
* by stage limits and can be any size. You look into the world via cameras. All game objects live within
* the world at world-based coordinates. By default a world is created the same size as your Stage.
*
* @param game Reference to the current game instance.
*/
constructor(game: Phaser.Game);
/**
* The World has no fixed size, but it does have a bounds outside of which objects are no longer considered as being "in world" and you should use this to clean-up the display list and purge dead objects.
* By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display.
* However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0.
* So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0. Bound of this world that objects can not escape from.
*/
bounds: Phaser.Rectangle;
/**
* Camera instance.
*/
camera: Phaser.Camera;
/**
* Gets the X position corresponding to the center point of the world.
*/
centerX: number;
/**
* Gets the Y position corresponding to the center point of the world.
*/
centerY: number;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
height: number;
isPaused: boolean;
/**
* Gets a random integer which is lesser than or equal to the current width of the game world.
*/
randomX: number;
/**
* Gets a random integer which is lesser than or equal to the current height of the game world.
*/
randomY: number;
stats: {
skipped: number;
ignored: number;
checked: number;
};
/**
* Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
width: number;
/**
* Initialises the game world.
*/
boot(): void;
getObjectsUnderPointer(pointer: Phaser.Pointer, group: Phaser.Group, callback?: Function, callbackContext?: any): Phaser.Sprite;
/**
* Updates 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.
*/
resize(width: number, height: number): void;
/**
* Updates the size of this world and sets World.x/y to the given values
* The Camera bounds and Physics bounds (if set) are also updated to match the new World bounds.
*
* @param x Top left most corner of the world.
* @param y Top left most corner of the world.
* @param width New width of the game world in pixels.
* @param height New height of the game world in pixels.
*/
setBounds(x: number, y: number, width: number, height: number): void;
sortLeftRight(a: Phaser.Sprite, b: Phaser.Sprite): number;
sortRightLeft(a: Phaser.Sprite, b: Phaser.Sprite): number;
sortTopBottom(a: Phaser.Sprite, b: Phaser.Sprite): number;
sortBottomTop(a: Phaser.Sprite, b: Phaser.Sprite): number;
/**
* Sort the children in the group according to a particular key and ordering.
*
* Call this function to sort the group according to a particular key value and order.
*
* For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`.
*
* Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including
* alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details.
*
* @param key The name of the property to sort on. Defaults to the objects z-depth value. - Default: 'z'
* @param order Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}). - Default: Phaser.Group.SORT_ASCENDING
*/
sort(group: Phaser.Group, sortDirection?: number): void;
/**
* Sort the children in the group according to a particular key and ordering.
*
* Call this function to sort the group according to a particular key value and order.
*
* For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`.
*
* Internally this uses a standard JavaScript Array sort, so everything that applies there also applies here, including
* alphabetical sorting, mixing strings and numbers, and Unicode sorting. See MDN for more details.
*
* @param key The name of the property to sort on. Defaults to the objects z-depth value. - Default: 'z'
* @param order Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}). - Default: Phaser.Group.SORT_ASCENDING
*/
sort(key?: string, order?: number): void;
/**
* Destroyer of worlds.
*/
shutdown(): void;
/**
* This will take the given game object and check if its x/y coordinates fall outside of the world bounds.
* If they do it will reposition the object to the opposite side of the world, creating a wrap-around effect.
* If sprite has a P2 body then the body (sprite.body) should be passed as first parameter to the function.
*
* Please understand there are limitations to this method. For example if you have scaled the World
* then objects won't always be re-positioned correctly, and you'll need to employ your own wrapping function.
*
* @param sprite The object you wish to wrap around the world bounds.
* @param padding Extra padding added equally to the sprite.x and y coordinates before checking if within the world bounds. Ignored if useBounds is true.
* @param useBounds If useBounds is false wrap checks the object.x/y coordinates. If true it does a more accurate bounds check, which is more expensive.
* @param horizontal If horizontal is false, wrap will not wrap the object.x coordinates horizontally. - Default: true
* @param vertical If vertical is false, wrap will not wrap the object.y coordinates vertically. - Default: true
*/
wrap(sprite: any, padding?: number, useBounds?: boolean, horizontal?: boolean, vertical?: boolean): void;
}
}