(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.
*
* @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. - Default: 0
* @param y The y coordinate of this Body. - Default: 0
* @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 effect Body shapes that already exist. If you then add further shapes to your Body
* after setting this it will *not* proactively set them to collide with the bounds. Should the Body collide with the World bounds?
*/
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;
/**
* -
*/
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 4 parameters: The body it is in contact with, the shape from this body that caused the contact, the shape from the contact body and 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 3 parameters: The body it is in contact with, the shape from this body that caused the contact and 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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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. - Default: false
* @param options.skipSimpleCheck Set to true if you already know that the path is not intersecting itself. - Default: false
* @param options.removeCollinearPoints Set to a number (angle threshold value) to remove collinear points, or false to keep all points. - Default: false
* @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 custom phaser export in.
*
* @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.
*/
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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @return The Rectangle 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.
*
* @param shape The shape to add to the body.
* @param offsetX Local horizontal offset of the shape relative to the body center of mass. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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;
/**
* 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;
/**
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
*
* @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 True on success, else false.
*/
loadPolygon(key: string, object: string): 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 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. - Default: false
* @param resetMass Sets the Body mass back to 1. - Default: false
*/
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.
*
* @param radius The radius of this circle (in pixels)
* @param offsetX Local horizontal offset of the shape relative to the body center of mass. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
*/
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.
*
* @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. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @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.
*
* @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;
/**
* 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.
*/
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.
*
* @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 - Default: 0
* @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. - Default: 0
* @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;
}
/**
* Constraint that only allows bodies to move along a line, relative to each other. See this tutorial.
*/
class PrismaticConstraint extends p2.PrismaticConstraint {
/**
* Constraint that only allows bodies to move along a line, relative to each other. See this tutorial.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.maxForce Max force to be applied by the constraint
* @param options.localAnchorA Body A's anchor point, defined in its own local frame.
* @param options.localAnchorB Body B's anchor point, defined in its own local frame.
* @param options.localAxisA An axis, defined in body A frame, that body B's anchor point may slide along.
* @param options.disableRotationalLock If set to true, bodyB will be free to rotate around its anchor point.
* @param options.upperLimit
* @param options.lowerLimit
*/
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.
*/
class RevoluteConstraint extends p2.RevoluteConstraint {
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.worldPivot A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
* @param options.localPivotA The point relative to the center of mass of bodyA which bodyA is constrained to.
* @param options.localPivotB See localPivotA.
* @param options.maxForce The maximum force that should be applied to constrain the bodies.
*/
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;
}
/**
* A spring, connecting two bodies. The Spring explicitly adds force and angularForce to the bodies and does therefore not put load on the constraint solver.
*/
class Spring {
/**
* A spring, connecting two bodies. The Spring explicitly adds force and angularForce to the bodies and does therefore not put load on the constraint solver.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.stiffness Spring constant (see Hookes Law). A number >= 0. - Default: 100
* @param options.damping A number >= 0. Default: 1 - Default: 1
* @param options.localAnchorA Where to hook the spring to body A, in local body coordinates. Defaults to the body center.
* @param options.localAnchorB
* @param options.worldAnchorA Where to hook the spring to body A, in world coordinates. Overrides the option "localAnchorA" if given.
* @param options.worldAnchorB
*/
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: any);
/**
* A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
* Default: false
*/
active: boolean;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* A flag to indicate if this plugin has a postRender method.
* Default: false
*/
hasPostRender: boolean;
/**
* A flag to indicate if this plugin has a postUpdate method.
* Default: false
*/
hasPostUpdate: boolean;
/**
* A flag to indicate if this plugin has a preUpdate method.
* Default: false
*/
hasPreUpdate: boolean;
/**
* A flag to indicate if this plugin has a render method.
* Default: false
*/
hasRender: boolean;
/**
* A flag to indicate if this plugin has an update method.
* Default: false
*/
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: any;
/**
* A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
* Default: false
*/
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 {
/**
* 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_ORTHAGONAL: number;
static COST_DIAGAONAL: number;
static DISTANCE_MANHATTEN: 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: any);
/**
* The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
parent: any;
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;
}
/**
* 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: Phaser.Plugin.AStar.AStarNode[], 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: Phaser.Plugin.AStar.AStarNode[];
/**
* 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: any);
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: any);
/**
* 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. - Default: 0
* @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: any);
/**
* 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. - Default: 0
* @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);
}
}
}
/**
* 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 parameters that will be passed to the Plugin.init method.
* @return The Plugin that was added to the manager.
*/
add(plugin: Phaser.Plugin | typeof Phaser.Plugin, ...parameter: any[]): Phaser.Plugin;
/**
* 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.
*/
remove(plugin: Phaser.Plugin): 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. - Default: 0
* @param y The vertical position of this Point. - Default: 0
*/
constructor(x?: number, y?: number);
/**
* The x value of the point.
*/
x: number;
/**
* The y value of the point.
*/
y: 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)? - Default: false
* @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 rotation 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;
/**
* 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)? - Default: false
* @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 rotation 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.setTo(2)` is the same as `Point.setTo(2, 2)`
*
* @param x The horizontal value of this point.
* @param y The vertical value of this point. If not given the x value will be used in its place.
* @return This Point object. Useful for chaining method calls.
*/
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)`
*
* @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;
/**
* 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.
*/
constructor(game: Phaser.Game, id: number);
/**
* An active pointer is one that is currently pressed down on the display. A Mouse is always active.
* Default: false
*/
active: boolean;
/**
* The button property of the Pointer as set by the DOM event when this Pointer is started.
* Default: null
*/
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.
* Default: false
*/
dirty: boolean;
/**
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
*/
duration: number;
/**
* A Pointer object that exists is allowed to be checked for physics collisions and overlaps.
* Default: true
*/
exists: boolean;
/**
* A reference to the currently running game.
*/
game: Phaser.Game;
/**
* 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.
* Default: 0
*/
identifier: number;
/**
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* Default: false
*/
isDown: boolean;
/**
* If the Pointer is a mouse this is true, otherwise false.
* Default: false
*/
isMouse: boolean;
/**
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true.
* Default: true
*/
isUp: boolean;
/**
* The horizontal processed relative movement of the Pointer in pixels since last event.
* Default: 0
*/
movementX: number;
/**
* The vertical processed relative movement of the Pointer in pixels since last event.
* Default: 0
*/
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.
* Default: null
*/
pointerId: 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.
* Default: 0
*/
previousTapTime: number;
/**
* The horizontal raw relative movement of the Pointer in pixels since last event.
* Default: 0
*/
rawMovementX: number;
/**
* The vertical raw relative movement of the Pointer in pixels since last event.
* Default: 0
*/
rawMovementY: number;
/**
* 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.
* Default: null
*/
target: any;
/**
* The Game Object this Pointer is currently over / touching / dragging.
* Default: null
*/
targetObject: any;
/**
* A timestamp representing when the Pointer first touched the touchscreen.
* Default: 0
*/
timeDown: number;
/**
* A timestamp representing when the Pointer left the touchscreen.
* Default: 0
*/
timeUp: number;
/**
* The total number of times this Pointer has been touched to the touchscreen.
* Default: 0
*/
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 reject 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? - Default: false
*/
move(event: any, fromClick?: boolean): void;
/**
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
*/
reset(): 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;
/**
* Called by the Input Manager.
*/
update(): 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: any[]);
/**
* The area of this Polygon.
*/
area: number;
/**
* 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: any[]; //number : 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;
/**
* 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, ...]`
* - 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: any[]): void;
}
/**
* 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? - Default: 0
*/
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? - Default: 0
*/
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.
*/
constructor(seeds: number[]);
/**
* 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;
/**
* 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: number[]): void;
/**
* 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(): number;
/**
* 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;
bottomRight: 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 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;
/**
* 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;
/**
* 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;
/**
* 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.RenderTexture {
/**
* 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 key Internal Phaser reference key for the render texture.
* @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;
/**
* The matrix that is applied when display objects are rendered to this RenderTexture.
*/
matrix: PIXI.Matrix;
/**
* Base Phaser object type.
*/
type: number;
/**
* This function will draw the display object to the texture.
*
* @param displayObject The display object to render to this texture.
* @param position A Point object containing the position to render the display object at.
* @param clear If true the texture will be cleared before the display object is drawn.
*/
render(displayObject: PIXI.DisplayObject, position: Phaser.Point, clear?: boolean): void;
/**
* This function will draw the display object to the texture.
*
* @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;
}
/**
* 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. - Default: false
*/
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.
* Default: 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(): 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. - Default: 0
* @param ySpacing If the characters in the font set have vertical spacing between them set the required amount here. - Default: 0
* @param xOffset If the font set doesn't start at the top left of the given image, specify the X coordinate offset here. - Default: 0
* @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. - Default: 0
*/
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.
* Default: 0
*/
customSpacingX: number;
/**
* Adds vertical spacing between each line of multi-line text, set in pixels.
* Default: 0
*/
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)
* Default: false
*/
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;
/**
* 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.
*/
smoothed: string;
/**
* 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. - Default: false
* @param characterSpacing To add horizontal spacing between each character specify the amount in pixels. - Default: 0
* @param lineSpacing To add vertical spacing between each line of text, set the amount in pixels. - Default: 0
* @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. - Default: false
*/
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. - Default: 0
* @param yOffset If the font set doesn't start at the top left of the given image, specify the Y coordinate offset here. - Default: 0
*/
updateOffset(x?: number, y?: number): void;
}
/**
* A Rope is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so.
* Please note that Ropes, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.
* Example usage: https://github.com/codevinsky/phaser-rope-demo/blob/master/dist/demo.js
*/
class Rope extends PIXI.Rope {
/**
* A Rope is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so.
* Please note that Ropes, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.
* Example usage: https://github.com/codevinsky/phaser-rope-demo/blob/master/dist/demo.js
*
* @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: any, frame?: any, points?: Phaser.Point[]);
/**
* Indicates the rotation of the Sprite, 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 use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle. The angle of this Sprite in degrees.
*/
angle: number;
/**
* This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
*/
animations: AnimationManager;
/**
* Should this Sprite be automatically culled if out of range of the camera?
* A culled sprite has its renderable property set to 'false'.
* Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it. A flag indicating if the Sprite should be automatically camera culled or not.
* Default: false
*/
autoCull: boolean;
/**
* By default Sprites won't add themselves to any physics system and their physics body will be `null`.
* To enable them for physics you need to call `game.physics.enable(sprite, system)` where `sprite` is this object
* and `system` is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via `Sprite.body`.
*
* Important: Enabling a Sprite for P2 or Ninja physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite.
* If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.
* Default: null
*/
body: any;
/**
* If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
*/
cameraOffset: Phaser.Point;
/**
* If true the Sprite checks if it is still within the world each frame, when it leaves the world it dispatches Sprite.events.onOutOfBounds
* and optionally kills the sprite (if Sprite.outOfBoundsKill is true). By default this is disabled because the Sprite has to calculate its
* bounds every frame to support it, and not all games need it. Enable it by setting the value to true.
* Default: false
*/
checkWorldBounds: boolean;
/**
* True if this object is currently being destroyed.
*/
destroyPhase: boolean;
/**
* Rope.exists controls if the core game loop and physics update this Rope or not.
* When you set Rope.exists to false it will remove its Body from the physics world (if it has one) and also set Rope.visible to false.
* Setting Rope.exists to true will re-add the Body to the physics world (if it has a body) and set Rope.visible to true. If the Rope is processed by the core game update and physics.
*/
exists: boolean;
/**
* The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
*/
events: Phaser.Events;
/**
* A Rope that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Rope.cameraOffset.
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Rope was in a Group that has x: 200, then this will be added to the cameraOffset.x Set to true to fix this Rope to the Camera at its current world coordinates.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index and updates the Texture Cache for display.
*/
frame: number;
/**
* Gets or sets the current frame name and updates the Texture Cache for display.
*/
frameName: string;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
*/
input: Phaser.InputHandler;
/**
* By default a Rope won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more. Set to true to allow this object to receive input events.
*/
inputEnabled: boolean;
/**
* 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, BitmapData or PIXI.Texture.
*/
key: any;
/**
* The user defined name given to this Sprite.
*/
name: string;
points: Phaser.Point[];
/**
* The coordinate of the object relative to the local coordinates of the parent.
*/
position: Phaser.Point;
/**
* The segments that make up the rope body as an array of Phaser.Rectangles
*/
segments: Phaser.Rectangle[];
/**
* The const type of this object.
*/
type: number;
/**
* A Rope will call it's 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 Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
*/
world: Phaser.Point;
/**
* The position of the Rope on the x axis relative to the local coordinates of the parent.
*/
x: number;
/**
* The position of the Rope on the y axis relative to the local coordinates of the parent.
*/
y: number;
/**
* The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
*/
z: number;
/**
* Destroys the Rope. 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 Texture the Rope is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
*
* @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, BitmapData 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.
*/
loadTexture(key: any, frame?: any): void;
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. - Default: null
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. - Default: false
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. - Default: false
* @return A reference to playing Animation instance.
*/
play(): void;
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): void;
/**
* Internal function called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Resets the Rope. This places the Rope 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 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 (Phaser.Rope) This instance.
*/
reset(x: number, y: number): void;
/**
* Sets the Texture frame the Rope uses for rendering.
* This is primarily an internal method used by Rope.loadTexture, although you may call it directly.
*
* @param frame The Frame to be used by the Rope texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*/
update(): void;
}
/**
* A Signal is an event dispatch mechansim than supports broadcasting to multiple listeners.
*
* Event listeners are uniquely identified by the listener/callback function and the context.
*/
class Signal {
/**
* Is the Signal active? Only active signal 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.
*
* @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)
* @return An Object representing the binding between the Signal and listener.
*/
add(listener: Function, listenerContext?: any, priority?: number): 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)
* @return An Object representing the binding between the Signal and listener.
*/
addOnce(listener: Function, listenerContext?: any, priority?: number): 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 other 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). - Default: null
* @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. - Default: null
*/
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). - Default: null
* @param priority The priority level of the event listener. (default = 0).
*/
constructor(signal: Phaser.Signal, listener: Function, isOnce: boolean, listenerContext?: any, priority?: number);
/**
* 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).
* Default: null
*/
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 GamepadButton object from this controller to be stored and referenced locally.
* The GamepadButton 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 GamepadButton object which you can store locally and reference directly.
*/
getButton(buttonCode: number): Phaser.GamepadButton;
/**
* 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. - Default: false
*/
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.
* Default: false
*/
allowMultiple: boolean;
/**
* Reference to the AudioContext instance.
*/
context: any;
/**
* The string ID of the currently playing marker, if any.
*/
currentMarker: string;
/**
* The current time the sound is at.
*/
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;
/**
* 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.
* Default: 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;
/**
* 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 onMouse 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.
* Default: false
*/
override: boolean;
/**
* true if the sound is paused, otherwise false.
* Default: false
*/
paused: boolean;
/**
* The position the sound had reached when it was paused.
*/
pausedPosition: number;
/**
* The game time 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.
*/
position: number;
/**
* The time the Sound starts at (typically 0 unless starting from a marker)
* Default: 0
*/
startTime: number;
/**
* The time the sound stopped.
*/
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;
/**
* The sound or sound marker volume. A value between 0 (silence) and 1 (full volume).
*/
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.
* @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. - Default: false
*/
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. - Default: false
*/
fadeIn(duration?: number, loop?: boolean): 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;
/**
* 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. - Default: 0
* @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 it finished playing? - Default: false
* @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. - Default: 0
* @param volume Volume of the sound you want to play. - Default: 1
* @param loop Loop when it finished playing? - Default: false
*/
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.
*/
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.
*
* @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.
* Default: null
*/
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;
/**
* Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead.
* Default: false
*/
noAudio: boolean;
/**
* The event dispatched when a sound decodes (typically only for mp3 files)
*/
onSoundDecode: Phaser.Signal;
/**
* true if the audio system is currently locked awaiting a touch event.
* Default: false
*/
touchLocked: boolean;
/**
* 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 global volume of the SoundManager, a value between 0 and 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. - Default: false
* @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 assets 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. - Default: false
* @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;
/**
* Stops all the sounds in the game.
*/
stopAll(): void;
/**
* Enables the audio, usually after the first touch.
*/
unlock(): void;
/**
* Updates every sound in the game.
*/
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.
* @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?: any, frame?: any);
/**
* A useful boolean to control if the Sprite is alive or dead (in terms of your gameplay, it doesn't effect rendering). Also linked to Sprite.health and Sprite.damage.
* Default: true
*/
alive: boolean;
/**
* The anchor sets the origin point of the texture.
* The default is 0,0 this means the texture's origin is the top left
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right corner
*/
anchor: Phaser.Point;
/**
* Indicates the rotation of the Sprite, 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 use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle. The angle of this Sprite in degrees.
*/
angle: number;
/**
* This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
*/
animations: Phaser.AnimationManager;
/**
* Should this Sprite be automatically culled if out of range of the camera?
* A culled sprite has its renderable property set to 'false'.
* Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it. A flag indicating if the Sprite should be automatically camera culled or not.
* Default: false
*/
autoCull: boolean;
/**
* By default Sprites won't add themselves to any physics system and their physics body will be `null`.
* To enable them for physics you need to call `game.physics.enable(sprite, system)` where `sprite` is this object
* and `system` is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via `Sprite.body`.
*
* Important: Enabling a Sprite for P2 or Ninja physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite.
* If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.
* Default: null
*/
body: any;
/**
* If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
*/
cameraOffset: Phaser.Point;
/**
* If true the Sprite checks if it is still within the world each frame, when it leaves the world it dispatches Sprite.events.onOutOfBounds
* and optionally kills the sprite (if Sprite.outOfBoundsKill is true). By default this is disabled because the Sprite has to calculate its
* bounds every frame to support it, and not all games need it. Enable it by setting the value to true.
* Default: false
*/
checkWorldBounds: boolean;
/**
* The Rectangle used to crop the texture. Set this via Sprite.crop. Any time you modify this property directly you must call Sprite.updateCrop.
* Default: null
*/
cropRect: Phaser.Rectangle;
/**
* Handy flag to use with Game.enableStep
* Default: false
*/
debug: boolean;
/**
* Returns the delta x value. The difference between world.x now and in the previous step. The delta value. Positive if the motion was to the right, negative if to the left.
*/
deltaX: number;
/**
* Returns the delta y value. The difference between world.y now and in the previous step. The delta value. Positive if the motion was downwards, negative if upwards.
*/
deltaY: number;
/**
* Returns the delta z value. The difference between rotation now and in the previous step. The delta value.
*/
deltaZ: number;
/**
* True if this object is currently being destroyed.
*/
destroyPhase: boolean;
/**
* The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
*/
events: Phaser.Events;
/**
* Sprite.exists controls if the core game loop and physics update this Sprite or not.
* When you set Sprite.exists to false it will remove its Body from the physics world (if it has one) and also set Sprite.visible to false.
* Setting Sprite.exists to true will re-add the Body to the physics world (if it has a body) and set Sprite.visible to true. If the Sprite is processed by the core game update and physics.
*/
exists: boolean;
/**
* An Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Sprite.cameraOffset.
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Sprite was in a Group that has x: 200, then this will be added to the cameraOffset.x Set to true to fix this Sprite to the Camera at its current world coordinates.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index and updates the Texture Cache for display.
*/
frame: number;
/**
* Gets or sets the current frame name and updates the Texture Cache for display.
*/
frameName: string;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* Health value. Used in combination with damage() to allow for quick killing of Sprites.
*/
health: number;
/**
* Checks if the Sprite bounds are within the game camera, otherwise false if fully outside of it. True if the Sprite bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
*/
inCamera: boolean;
/**
* The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
*/
input: Phaser.InputHandler;
/**
* By default a Sprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more. Set to true to allow this object to receive input events.
*/
inputEnabled: boolean;
/**
* Checks if the Sprite bounds are within the game world, otherwise false if fully outside of it. True if the Sprite bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
*/
inWorld: boolean;
/**
* 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, BitmapData or PIXI.Texture.
*/
key: any;
/**
* To given a Sprite a lifespan, in milliseconds, once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
*
* The lifespan is decremented by `game.time.physicsElapsed` (converted to milliseconds) each logic update,
* and {@link Phaser.Sprite.kill kill} is called once the lifespan reaches 0.
* Default: 0
*/
lifespan: number;
/**
* The user defined name given to this Sprite.
*/
name: string;
/**
* If true Sprite.kill is called as soon as Sprite.inWorld returns false, as long as Sprite.checkWorldBounds is true.
* Default: false
*/
outOfBoundsKill: boolean;
/**
* The coordinate of the object relative to the local coordinates of the parent.
*/
position: Phaser.Point;
physicsEnabled: boolean;
/**
* The render order ID, reset every frame.
*/
renderOrderID: number;
/**
* The scale factor of the object.
*/
scale: Phaser.Point;
/**
* Set the minimum scale this Sprite will scale down to. Prevents a parent from scaling this Sprite lower than the given value. Set to `null` to remove.
*/
scaleMin: Phaser.Point;
/**
* Set the maximum scale this Sprite will scale up to. Prevents a parent from scaling this Sprite higher than the given value. Set to `null` to remove.
*/
scaleMax: Phaser.Point;
/**
* Enable or disable texture smoothing for this Sprite. Only works for bitmap/image textures. Smoothing is enabled by default. Set to true to smooth the texture of this Sprite, or false to disable smoothing (great for pixel art)
*/
smoothed: boolean;
/**
* The const type of this object.
*/
type: number;
/**
* The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
*/
world: Phaser.Point;
/**
* The position of the Sprite on the x axis relative to the local coordinates of the parent.
*/
x: number;
/**
* The position of the Sprite on the y axis relative to the local coordinates of the parent.
*/
y: number;
/**
* The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
*/
z: number;
/**
* Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only
* bought to the top of that Group, not the entire display list.
* @return (Phaser.Sprite) This instance.
*/
bringToTop(): Phaser.Sprite;
/**
* Crop allows you to crop the texture used to display this Sprite.
* This modifies the core Sprite texture frame, so the Sprite width/height properties will adjust accordingly.
*
* Cropping takes place from the top-left of the Sprite and can be modified in real-time by either providing an updated rectangle object to Sprite.crop,
* or by modifying Sprite.cropRect (or a reference to it) and then calling Sprite.updateCrop.
*
* The rectangle object given to this method can be either a Phaser.Rectangle or any object so long as it has public x, y, width and height properties.
* A reference to the rectangle is stored in Sprite.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 Sprite.cropRect will be a reference to the given rect. If true it will copy the rect values into a local Sprite.cropRect object. - Default: false
*/
crop(rect: Phaser.Rectangle, copy: boolean): void;
/**
* Damages the Sprite, this removes the given amount from the Sprites health property.
* If health is then taken below or is equal to zero `Sprite.kill` is called.
*
* @param amount The amount to subtract from the Sprite.health value.
* @return (Phaser.Sprite) This instance.
*/
damage(amount: number): Phaser.Sprite;
/**
* Destroys the Sprite. 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.
*
* @param destroyChildren Should every child of this object have its destroy method called? - Default: true
*/
destroy(destroyChildren?: boolean): void;
drawPolygon(): void;
/**
* Kills a Sprite. A killed Sprite has its alive, exists and visible properties all set to false.
* It will dispatch the onKilled event, you can listen to Sprite.events.onKilled for the signal.
* Note that killing a Sprite is a way for you to quickly recycle it in a Sprite pool, it doesn't free it up from memory.
* If you don't need this Sprite any more you should call Sprite.destroy instead.
* @return (Phaser.Sprite) This instance.
*/
kill(): Phaser.Sprite;
/**
* Changes the Texture the Sprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
*
* @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, BitmapData 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: any, frame: any, stopAnimation?: boolean): void;
/**
* Checks to see if the bounds of this Sprite overlaps with the bounds of the given Display Object, which can be a Sprite, Image, TileSprite or anything that extends those such as a Button.
* This check ignores the Sprites hitArea property and runs a Sprite.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), but 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 Sprite intersects at any point with the bounds of the given display object.
*/
overlap(displayObject: any): boolean;
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. - Default: null
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. - Default: false
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. - Default: false
* @return A reference to playing Animation instance.
*/
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
/**
* Internal function 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 Sprite. This places the Sprite at the given x/y world coordinates and then
* sets alive, exists, visible and renderable all to true. Also resets the outOfBounds state and health values.
* If the Sprite 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.
* @param health The health to give the Sprite. - Default: 1
* @return (Phaser.Sprite) This instance.
*/
reset(x: number, y: number, health?: number): Phaser.Sprite;
/**
* Resets the Texture frame dimensions that the Sprite uses for rendering.
*/
resetFrame(): void;
/**
* Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
* A resurrected Sprite has its alive, exists and visible properties all set to true.
* It will dispatch the onRevived event, you can listen to Sprite.events.onRevived for the signal.
*
* @param health The health to give the Sprite. - Default: 1
* @return (Phaser.Sprite) This instance.
*/
revive(health?: number): Phaser.Sprite;
/**
* Sets the Texture frame the Sprite uses for rendering.
* This is primarily an internal method used by Sprite.loadTexture, although you may call it directly.
*
* @param frame The Frame to be used by the Sprite texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Sets the scaleMin and scaleMax values. These values are used to limit how far this Sprite will scale based on its parent.
* For example if this Sprite 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.
* By using these values you can carefully control how Sprites 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 Sprite.scaleMin directly, or pass `null` for the maxX and maxY parameters.
*
* Call setScaleMinMax(null) to clear both the scaleMin and scaleMax values.
*
* @param minX The minimum horizontal scale value this Sprite can scale down to.
* @param minY The minimum vertical scale value this Sprite can scale down to.
* @param maxX The maximum horizontal scale value this Sprite can scale up to.
* @param maxY The maximum vertical scale value this Sprite can scale up to.
*/
setScaleMinMax(minX?: number, minY?: number, maxX?: number, maxY?: number): void;
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
* Remember if this Sprite has any children you should call update on them too.
*/
update(): void;
/**
* If you have set a crop rectangle on this Sprite via Sprite.crop and since modified the Sprite.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.
*/
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.
*
* @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. - Default: false
*/
constructor(game: Phaser.Game, parent: any, 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.Stage {
/**
* 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);
/**
* 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;
/**
* Reset each frame, keeps a count of the total number of objects updated.
*/
currentRenderOrderID: number;
/**
* By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true.
* Default: false
*/
disableVisibilityChange: boolean;
/**
* If exists is true the Stage and all children are updated, otherwise it is skipped.
* Default: true
*/
exists: boolean;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The name of this object.
* Default: _stage_root
*/
name: string;
/**
* 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;
/**
* Initialises the stage and adds the event listeners.
*/
boot(): void;
/**
* Starts a page visibility event listener running, or window.blur/focus if not supported by the browser.
*/
checkVisibility(): void;
/**
* Destroys the Stage and removes event listeners.
*/
destroy(): void;
/**
* Parses a Game configuration object.
*
* @param config The configuration object to parse.
*/
parseConfig(config: any): void;
/**
* This is called automatically before the renderer runs and after the plugins have updated.
* In postUpdate this is where all the final physics calculatations and object positioning happens.
* The objects are processed in the order of the display list.
* The only exception to this is if the camera is following an object, in which case that is updated first.
*/
postUpdate(): 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;
/**
* 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.
*
* @param backgroundColor The color of the background.
*/
setBackgroundColor(backgroundColor: number): 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.
*
* @param backgroundColor The color of the background.
*/
setBackgroundColor(backgroundColor: string): void;
/**
* This is called automatically after the State.update, but before particles or plugins update.
*/
update(): 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;
/**
* 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: any): void;
}
interface ResizeCallback {
(width: number, height: number): 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.
*/
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, height: number);
/**
* 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: string, height: 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;
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;
/**
* This signal is dispatched when the browser enters fullscreen mode, if supported.
*/
enterFullScreen: Signal;
/**
* This signal is dispatched when the browser enters landscape orientation, having been in portrait.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
enterLandscape: Signal;
/**
* This signal is dispatched when the browser enters portrait orientation, having been in landscape.
*
* This is signaled from `preUpdate` (or `pauseUpdate`) _even when_ the game is paused.
*/
enterPortrait: 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}.
* Default: false
*/
forceLandscape: boolean;
/**
* If true, the game should only run in a portrait
* Change with {@link Phaser.ScaleManager#forceOrientation forceOrientation}.
* Default: false
*/
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;
/**
* This signal is dispatched when the browser fails to enter fullscreen mode;
* or if the device does not support fullscreen mode and {@link Phaser.ScaleManager#startFullScreen startFullScreen} is invoked.
*/
fullScreenFailed: Signal;
/**
* 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`.
* Default: null
*/
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;
/**
* 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; //readonly
/**
* 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; //readonly
/**
* 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 fullscreen mode.
*/
leaveFullScreen: Signal;
/**
* 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; };
/**
* The maximum number of times a canvas will be resized (in a row) in order to fill the browser.
*/
maxIterations: 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.
*
* 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;
/**
* The _last known_ orientation value of the screen. A value of 90 is landscape and 0 is portrait.
*/
orientation: number;
/**
* 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 mainted.
*
* - {@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: boolean;
right: boolean;
};
/**
* Start the ScaleManager.
*/
boot(): void;
/**
* Checks if the browser is in the correct orientation for the game,
* dependent upon {@link Phaser.ScaleManager#forceLandscape forceLandscape} and {@link Phaser.ScaleManager#forcePortrait forcePortrait}, and updates the state.
*
* The appropriate event is dispatched if the orientation became valid or invalid.
* @return True if the orientation state changed (consider a refresh)
*/
checkOrientationState(): boolean;
/**
* 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.
*
* @param forceLandscape true if the game should run in landscape mode only.
* @param forcePortrait true if the game should run in portrait mode only. - Default: false
*/
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.
*
* 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}.
*
* @param hScale Horizontal scaling factor.
* @param vScale Vertical scaling factor.
* @param hTrim Horizontal trim, applied after scaling. - Default: 0
* @param vTrim Vertical trim, applied after scaling. - Default: 0
*/
setUserScale(hScale: number, vScale: number, hTrim?: number, vTrim?: number): 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. - Default: false
* @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. - Default: false
* @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. - Default: undefined
* @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.
*/
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;
/**
* 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;
/**
* A reference to Math class with lots of helpful functions.
*/
math: Phaser.Math;
/**
* 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 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(): 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;
/**
* 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 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.
* If 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. - Default: null
*/
constructor(game: Phaser.Game, pendingState?: Phaser.State);
/**
* The current active State object (defaults to null).
*/
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;
/**
* 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. - Default: false
*/
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.
* @return Phaser.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. - Default: false
* @param args Additional parameters that will be passed to the State.init function if it has one.
*/
restart(clearWorld?: boolean, clearCache?: boolean): 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. - Default: false
* @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;
}
/**
* Create a new `Text` object. This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for renderning to the view.
* Because of this you can only display fonts that are currently loaded and available to the browser. It won't load the fonts for you.
* Here is a compatibility table showing the available default fonts across different mobile browsers: http://www.jordanm.co.uk/tinytype
*/
class Text extends PIXI.Text {
/**
* Create a new `Text` object. This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for renderning to the view.
* Because of this you can only display fonts that are currently loaded and available to the browser. It won't load the fonts for you.
* Here is a compatibility table showing the available default fonts across different mobile browsers: http://www.jordanm.co.uk/tinytype
*
* @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 object containing style attributes like font, font size, etc.
*/
constructor(game: Phaser.Game, x: number, y: number, text: string, style: any);
/**
* Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text.
*/
align: string;
/**
* Indicates the rotation of the Text, 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 use the property Sprite.rotation instead. Gets or sets the angle of rotation in degrees.
*/
angle: number;
/**
* If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
*/
cameraOffset: Phaser.Point;
/**
* An array of the color values as specified by `Text.addColor`.
*/
colors: string[];
/**
* True if this object is currently being destroyed.
*/
destroyPhase: boolean;
/**
* The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
*/
events: Phaser.Events;
/**
* If exists = false then the Text isn't updated by the core game loop.
* Default: true
*/
exists: boolean;
/**
* A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
*/
fill: any;
/**
* An Text that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Text.cameraOffset.
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Text was in a Group that has x: 200, then this will be added to the cameraOffset.x Set to true to fix this Text to the Camera at its current world coordinates.
*/
fixedToCamera: boolean;
/**
* The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
*/
font: string;
/**
* The size of the font in pixels.
*/
fontSize: number;
/**
* The weight of the font: 'normal', 'bold', 'italic'. You can combine settings too, such as 'bold italic'.
*/
fontWeight: string;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
*/
input: Phaser.InputHandler;
/**
* By default a Text object won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more. Set to true to allow this object to receive input events.
*/
inputEnabled: boolean;
/**
* Additional spacing (in pixels) between each line of text if multi-line.
*/
lineSpacing: number;
/**
* The user defined name given to this object.
*/
name: string;
/**
* The coordinate of the object relative to the local coordinates of the parent.
*/
position: Phaser.Point;
/**
* 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;
/**
* 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;
/**
* A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'.
*/
stroke: string;
/**
* A number that represents the thickness of the stroke. Default is 0 (no stroke)
*/
strokeThickness: number;
/**
* The scale factor of the object.
*/
scale: Phaser.Point;
/**
* The text string to be displayed by this Text object, taking into account the style settings.
*/
text: string;
/**
* The const type of this object.
*/
type: number;
/**
* The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
*/
world: Phaser.Point;
/**
* Indicates if word wrap should be used.
*/
wordWrap: boolean;
/**
* The width at which text will wrap.
*/
wordWrapWidth: number;
/**
* The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
*/
z: number;
/**
* This method allows you to set specific colors 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.
*
* @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.
*/
addColor(color: string, position: number): void;
/**
* Clears any previously set color stops.
*/
clearColors(): void;
/**
*
*
* @param destroyChildren Should every child of this object have its destroy method called? - Default: true
*/
destroy(destroyChildren?: boolean): void;
/**
* Automatically called by World.postUpdate.
*/
postUpdate(): void;
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): 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. - Default: 0
* @param y The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be. - Default: 0
* @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). - Default: 0
*/
setShadow(x?: number, y?: number, color?: any, blur?: number): void;
/**
* 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.fill A canvas fillstyle that will be used on the text eg 'red', '#00FF00'. - Default: 'black'
* @param style.align Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text. - Default: 'left'
* @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). - Default: 0
* @param style.wordWrap Indicates if word wrap should be used. - Default: false
* @param style.wordWrapWidth The width in pixels at which text will wrap. - Default: 100
*/
/**
* The font the text will be rendered in, i.e. 'Arial'. Must be loaded in the browser before use.
*/
/**
* A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
*/
/**
* Alignment for multiline text ('left', 'center' or 'right'), does not affect single line text.
*/
/**
* A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'.
*/
/**
* A number that represents the thickness of the stroke. Default is 0 (no stroke)
*/
/**
* Indicates if word wrap should be used.
*/
/**
* The width at which text will wrap.
*/
/**
* The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
*/
/**
* The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
*/
/**
* The color of the shadow, as given in CSS rgba format. Set the alpha component to 0 to disable the shadow.
*/
/**
* 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).
*/
setStyle(style?: { font?: string; fill?: any; align?: string; stroke?: string; strokeThickness?: number; wordWrap?: boolean; wordWrapWidth?: number; shadowOffsetX?: number; shadowOffsetY?: number; shadowColor?: string; shadowBlur?: number; }): void;
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*/
update(): void;
/**
* Updates texture size based on canvas size
*/
updateTexture(): void;
/**
* Updates a line of text.
*/
updateLine(text:string, x?:number, y?:number): 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.
* Default: false
*/
collideDown: boolean;
/**
* Indicating collide with any object on the left.
* Default: false
*/
collideLeft: boolean;
collideNone: boolean;
/**
* Indicating collide with any object on the right.
* Default: false
*/
collideRight: boolean;
/**
* Tile collision callback.
* Default: null
*/
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.
* Default: false
*/
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.
* 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.
* 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[];
/**
* 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[];
/**
* 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;
/**
* 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 not specified it will look for an image with a key matching the tileset parameter.
* @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. If not given it will default to the map.tileWidth value. - Default: 0
* @param tileSpacing The height of the tiles in the Tileset Image. If not given it will default to the map.tileHeight value. - Default: 0
* @param gid If adding multiple tilesets to a blank/dynamic map, specify the starting GID the set will use here. - Default: 0
* @return Returns the Tileset object that was created or updated, or null if it failed.
*/
addTilesetImage(tileset: string, key?: string, 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 object matching the given gid in the map data. You can optionally specify the group that the Sprite will be created in. If none is
* given it will be created in the World. All properties from the map data objectgroup are copied across to the Sprite, so you can use this as an easy way to
* configure Sprite properties from within the map editor. For example giving an object a property of alpha: 0.5 in the map editor will duplicate that when the
* Sprite is created. You could also give it a value like: body.velocity.x: 100 to set it moving automatically.
*
* @param name The name of the Object Group to create Sprites from.
* @param gid The layer array index value, or if a string is given the layer name within the map data.
* @param key The Game.cache key of the image that this Sprite will use.
* @param frame If the Sprite image contains multiple frames you can specify which one to use here.
* @param exists The default exists state of the Sprite. - Default: true
* @param autoCull The default autoCull state of the Sprite. Sprites that are autoCulled are culled from the camera if out of its range. - Default: false
* @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 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.
* @param layer The layer to operate on.
* @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;
/**
* Gets the object index based on its name.
*
* @param name The name of the object to get.
* @return The index of the object in this tilemap, or null if not found.
*/
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. - Default: false
* @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.
* @return The tile at the given coordinates.
*/
getTileWorldXY(x: number, y: number, tileWidth?: number, tileHeight?: number, layer?: any): 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 travelling up to the top-left.
*
* @param index The tile index value to search for.
* @param skip The number of times to skip a matching tile before returning. - Default: 0
* @param reverse If true it will scan the layer in reverse, starting at the bottom-right. Otherwise it scans from the top-left. - Default: false
* @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 the given tile or tiles. You can pass in either a single numeric index or an array of indexes: [ 2, 3, 15, 20].
* The `collides` parameter controls if collision will be enabled (true) or disabled (false).
*
* @param indexes Either a single tile index, or an array of tile IDs to be checked for collision.
* @param collides If true it will enable collision. If false it will clear collision. - Default: true
* @param layer The layer to operate on. If not given will default to this.currentLayer.
* @param recalculate Recalculates the tile faces after the update. - Default: true
*/
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.
*
* @param indexes Either a single tile index, or an array of tile indexes to have a collision callback set for.
* @param callback The callback that will be invoked when the tile is collided with.
* @param callbackContext The context under which the callback is called.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
*/
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.
*
* @param x X position of the top left of the area to copy (given in tiles, not pixels)
* @param y Y position of the top left of the area to copy (given in tiles, not pixels)
* @param width The width of the area to copy (given in tiles, not pixels)
* @param height The height of the area to copy (given in tiles, not pixels)
* @param callback The callback that will be invoked when the tile is collided with.
* @param callbackContext The context under which the callback is called.
* @param layer The layer to operate on. If not given will default to this.currentLayer.
*/
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 behaviour.
*/
class TilemapLayer extends Phaser.Image {
/**
* 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 behaviour.
*
* @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);
/**
* Required Pixi var.
*/
baseTexture: PIXI.BaseTexture;
/**
* If this object is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
*/
cameraOffset: Phaser.Point;
/**
* The canvas to which this TilemapLayer draws.
*/
canvas: HTMLCanvasElement;
collisionHeight: number;
collisionWidth: number;
/**
* The 2d context of the canvas.
*/
context: CanvasRenderingContext2D;
/**
* Enable an additional "debug rendering" pass to display collision information.
* Default: false
*/
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;
/**
* An object that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
* Default: true
*/
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;
/**
* The name of the layer.
*/
name: string;
/**
* When ray-casting against tiles this is the number of steps it will jump. For larger tile sizes you can increase this to improve performance.
* Default: 4
*/
rayStepRate: number;
/**
* Settings that control standard (non-diagnostic) rendering.
* Default: {"enableScrollDelta":true,"overdrawRatio":0.2,"copyCanvas":null}
*/
renderSettings: { enableScrollDelta: boolean; overdrawRatio: number; };
/**
* 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;
/**
* Required Pixi var.
*/
texture: PIXI.Texture;
/**
* Dimensions of the renderable area.
*/
textureFrame: Phaser.Frame;
tileColor: string;
/**
* The const type of this object.
* Default: Phaser.TILEMAPLAYER
*/
type: number;
wrap: boolean;
/**
* 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. - Default: false
* @param interestingFace If true, _only_ return tiles that have interesting faces. - Default: false
* @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. - Default: false
* @param interestingFace If true, _only_ return tiles that have interesting faces. - Default: false
* @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;
/**
* 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;
updateMax(): void;
}
/**
* Phaser.TilemapParser parses data objects from Phaser.Loader that need more preparation before they can be inserted into a Tilemap.
*/
class TilemapParser {
/**
* 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 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 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;
/**
* Parses a Tiled JSON file into valid map data.
*
* @param json The JSON map data.
* @return Generated and parsed map data.
*/
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). - Default: 0
* @param spacing The spacing between each tile in the sheet (in pixels). - Default: 0
* @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;
/**
* 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;
/**
* 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 tileMargin The margin around the tiles in the sheet (in pixels).
* @param tileSpacing 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 and will automatically wrap on the edges as it does so.
* Please note that TileSprites, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.
*/
class TileSprite extends PIXI.TilingSprite {
/**
* A TileSprite is a Sprite that has a repeating texture. The texture can be scrolled and scaled and will automatically wrap on the edges as it does so.
* Please note that TileSprites, as with normal Sprites, have no input handler or physics bodies by default. Both need enabling.
*
* @param game A reference to the currently running game.
* @param x The x coordinate (in world space) to position the TileSprite at.
* @param y The y coordinate (in world space) to position the TileSprite at.
* @param width The width of the TileSprite.
* @param height The height of the TileSprite.
* @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
* @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?: any, frame?: any);
/**
* A useful boolean to control if the TileSprite is alive or dead (in terms of your gameplay, it doesn't effect rendering).
* Default: true
*/
alive: boolean;
/**
* Indicates the rotation of the Sprite, 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 use the property Sprite.rotation instead. Working in radians is also a little faster as it doesn't have to convert the angle. The angle of this Sprite in degrees.
*/
angle: number;
/**
* This manages animations of the sprite. You can modify animations through it (see Phaser.AnimationManager)
*/
animations: Phaser.AnimationManager;
/**
* Should this Sprite be automatically culled if out of range of the camera?
* A culled sprite has its renderable property set to 'false'.
* Be advised this is quite an expensive operation, as it has to calculate the bounds of the object every frame, so only enable it if you really need it. A flag indicating if the Sprite should be automatically camera culled or not.
* Default: false
*/
autoCull: boolean;
/**
* By default Sprites won't add themselves to any physics system and their physics body will be `null`.
* To enable them for physics you need to call `game.physics.enable(sprite, system)` where `sprite` is this object
* and `system` is the Physics system you want to use to manage this body. Once enabled you can access all physics related properties via `Sprite.body`.
*
* Important: Enabling a Sprite for P2 or Ninja physics will automatically set `Sprite.anchor` to 0.5 so the physics body is centered on the Sprite.
* If you need a different result then adjust or re-create the Body shape offsets manually, and/or reset the anchor after enabling physics.
* Default: null
*/
body: any;
/**
* If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
*/
cameraOffset: Phaser.Point;
/**
* If true the Sprite checks if it is still within the world each frame, when it leaves the world it dispatches Sprite.events.onOutOfBounds
* and optionally kills the sprite (if Sprite.outOfBoundsKill is true). By default this is disabled because the Sprite has to calculate its
* bounds every frame to support it, and not all games need it. Enable it by setting the value to true.
* Default: false
*/
checkWorldBounds: boolean;
/**
* True if this object is currently being destroyed.
*/
destroyPhase: boolean;
/**
* The Events you can subscribe to that are dispatched when certain things happen on this Sprite or its components.
*/
events: Phaser.Events;
/**
* TileSprite.exists controls if the core game loop and physics update this TileSprite or not.
* When you set TileSprite.exists to false it will remove its Body from the physics world (if it has one) and also set TileSprite.visible to false.
* Setting TileSprite.exists to true will re-add the Body to the physics world (if it has a body) and set TileSprite.visible to true. If the TileSprite is processed by the core game update and physics.
*/
exists: boolean;
/**
* An TileSprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in TileSprite.cameraOffset.
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this TileSprite was in a Group that has x: 200, then this will be added to the cameraOffset.x Set to true to fix this TileSprite to the Camera at its current world coordinates.
*/
fixedToCamera: boolean;
/**
* Gets or sets the current frame index and updates the Texture Cache for display.
*/
frame: number;
/**
* Gets or sets the current frame name and updates the Texture Cache for display.
*/
frameName: string;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* The Input Handler for this object. Needs to be enabled with image.inputEnabled = true before you can use it.
*/
input: Phaser.InputHandler;
/**
* By default a TileSprite won't process any input events at all. By setting inputEnabled to true the Phaser.InputHandler is
* activated for this object and it will then start to process click/touch events and more. Set to true to allow this object to receive input events.
*/
inputEnabled: boolean;
/**
* 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, BitmapData or PIXI.Texture.
*/
key: any;
/**
* The user defined name given to this Sprite.
*/
name: string;
/**
* The coordinate of the object relative to the local coordinates of the parent.
*/
position: Phaser.Point;
/**
* The const type of this object.
*/
type: number;
/**
* The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
*/
world: Phaser.Point;
/**
* The z-depth value of this object within its Group (remember the World is a Group as well). No two objects in a Group can have the same z value.
*/
z: number;
/**
* 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.
*/
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 Texture the TileSprite is using entirely. The old texture is removed and the new one is referenced or fetched from the Cache.
* This causes a WebGL texture update, so use sparingly or in low-intensity portions of your game.
*
* @param key This is the image or texture used by the TileSprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
* @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.
*/
loadTexture(key: any, frame: any): void;
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @param name The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param frameRate The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. - Default: null
* @param loop Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. - Default: false
* @param killOnComplete If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. - Default: false
* @return A reference to playing Animation instance.
*/
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
/**
* Internal function called by the World postUpdate cycle.
*/
postUpdate(): void;
/**
* Automatically called by World.preUpdate.
*/
preUpdate(): void;
/**
* 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 (Phaser.TileSprite) This instance.
*/
reset(x: number, y: number): Phaser.TileSprite;
/**
* Sets the Texture frame the TileSprite uses for rendering.
* This is primarily an internal method used by TileSprite.loadTexture, although you may call it directly.
*
* @param frame The Frame to be used by the TileSprite texture.
*/
setFrame(frame: Phaser.Frame): void;
/**
* Stops an automatically scrolling TileSprite.
*/
stopScroll(): void;
/**
* Override and use this function in your own custom objects to handle any update requirements you may have.
*/
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 handlers the standard Timer pool.
*
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
*/
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 handlers the standard Timer pool.
*
* To create a general timed event, use the master {@link Phaser.Timer} accessible through {@link Phaser.Time.events events}.
*
* @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 and msMin/msMax are updated.
* Default: false
*/
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.
* Default: 60
*/
desiredFps: 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.
*
* _Note:_ This is not available until after a few frames have passed; use it after a few seconds (eg. after the menus)
* Default: null
*/
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 small re-usable (or disposable) objects that wait for a specific moment in time,
* and then run the specified callbacks.
*
* You can many events to a Timer, each with their own delays. A Timer uses milliseconds as its unit of time (there are 1000 ms in 1 second).
* So a delay to 250 would fire the event every quarter of a second.
*
* Timers are based on real-world (not physics) time, adjusted for game pause durations.
*/
class Timer {
/**
* A Timer is a way to create small re-usable (or disposable) objects that wait for a specific moment in time,
* and then run the specified callbacks.
*
* You can many events to a Timer, each with their own delays. A Timer uses milliseconds as its unit of time (there are 1000 ms in 1 second).
* So a delay to 250 would fire the event every quarter of a second.
*
* Timers are based on real-world (not physics) time, adjusted for game pause durations.
*
* @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.
* Default: false
*/
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.
* Default: false
*/
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.
* Default: false
*/
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 that should elapse before the callback is invoked.
* @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 that should elapse before the Timer will call the given callback.
* @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 that should elapse before the Timer will call the given callback.
* @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 that should elapse before the Timer will start. - Default: 0
*/
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.
*
* Use {@link Phaser.Timer#add}, {@link Phaser.Timer#add}, or {@link Phaser.Timer#add} 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.
*
* Use {@link Phaser.Timer#add}, {@link Phaser.Timer#add}, or {@link Phaser.Timer#add} 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.
*/
class Touch {
/**
* Phaser.Touch handles touch events with your game. Note: Android 2.x only supports 1 touch event at once, no multi-touch.
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* The context under which callbacks are called.
*/
callbackContext: any;
disabled: boolean;
/**
* Touch events will only be processed if enabled.
* Default: true
*/
enabled: boolean;
/**
* The browser touch DOM event. Will be set to null if no touch event has ever been received.
* Default: null
*/
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;
/**
* 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.
* Default: 0
*/
current: number;
/**
* A reference to the currently running Game.
*/
game: Phaser.Game;
/**
* If the tween is running this is set to true, otherwise false. Tweens that are in a delayed state or waiting to start are considered as being running.
* Default: false
*/
isRunning: boolean;
/**
* Is this Tween paused or not?
* Default: false
*/
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 tween loops.
* 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.
* Default: false
*/
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;
/**
* The amount of time in ms between repeats of this tween and any child tweens.
*/
repeatDelay: 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.
* Default: false
*/
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. - Default: 0
* @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. - Default: 0
* @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. - Default: 0
* @return This tween. Useful for method chaining.
*/
easing(ease: string, index?: number): Phaser.Tween;
/**
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. - Default: null
* @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). - Default: false
* @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. - Default: 0
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this induvidual tween, not any chained tweens. - Default: 0
* @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. - Default: false
* @return This Tween object.
*/
from(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `from` tween on the properties given. A `from` tween sets the target to the destination value and tweens to its current value.
* For example a Sprite with an `x` coordinate of 100 tweened from `x` 500 would be set to `x` 500 and then tweened to `x` 100 by giving a properties object of `{ x: 500 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. - Default: null
* @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). - Default: false
* @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. - Default: 0
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this induvidual tween, not any chained tweens. - Default: 0
* @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. - Default: false
* @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 it sets the interpolation function across all of them.
*
* @param interpolation The interpolation function to use (Phaser.Math.linearInterpolation by default)
* @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. - Default: 0
* @return This tween. Useful for method chaining.
*/
interpolation(interpolation: Function, index?: number): Phaser.Tween;
/**
* Enables the looping of this tween and all child tweens. If this tween has no children this setting has no effect.
* 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 and any child tweens will loop once they reach 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 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. - Default: 0
* @return This tween. Useful for method chaining.
*/
repeat(total: number, index?: number): Phaser.Tween;
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. - Default: 0
* @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. - Default: false
* @return This tween. Useful for method chaining.
*/
stop(complete?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. - Default: null
* @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). - Default: false
* @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. - Default: 0
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this induvidual tween, not any chained tweens. - Default: 0
* @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. - Default: false
* @return This Tween object.
*/
to(properties: any, duration?: number, ease?: Function, autoStart?: boolean, delay?: number, repeat?: number, yoyo?: boolean): Phaser.Tween;
/**
* Sets this tween to be a `to` tween on the properties given. A `to` tween starts at the current value and tweens to the destination value given.
* For example a Sprite with an `x` coordinate of 100 could be tweened to `x` 200 by giving a properties object of `{ x: 200 }`.
* The ease function allows you define the rate of change. You can pass either a function such as Phaser.Easing.Circular.Out or a string such as "Circ".
* ".easeIn", ".easeOut" and "easeInOut" variants are all supported for all ease types.
*
* @param properties An object containing the properties you want to tween., such as `Sprite.x` or `Sound.volume`. Given as a JavaScript object.
* @param duration Duration of this tween in ms. - Default: 1000
* @param ease Easing function. If not set it will default to Phaser.Easing.Default, which is Phaser.Easing.Linear.None by default but can be over-ridden. - Default: null
* @param autoStart Set to `true` to allow this tween to start automatically. Otherwise call Tween.start(). - Default: false
* @param delay Delay before this tween will start in milliseconds. Defaults to 0, no delay. - Default: 0
* @param repeat Should the tween automatically restart once complete? If you want it to run forever set as -1. This only effects this induvidual tween, not any chained tweens. - Default: 0
* @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. - Default: false
* @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;
/**
* 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 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. - Default: 0
* @return This tween. Useful for method chaining.
*/
yoyo(enable: boolean, 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).
* Default: 0
*/
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).
* Default: false
*/
inReverse: boolean;
/**
* 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.
* Default: false
*/
isRunning: boolean;
/**
* Is this a from tween or a to tween?
* Default: false
*/
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.
* Default: false
*/
yoyo: boolean;
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;
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.
* @return The current status of this Tween. One of the Phaser.TweenData constants: PENDING, RUNNING, LOOPED or COMPLETE.
*/
update(): number;
}
/**
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by http://soledadpenades.com.
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
*/
class TweenManager {
/**
* Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated.
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
*
* TweenManager is based heavily on tween.js by http://soledadpenades.com.
* The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object.
* It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors.
* Please see https://github.com/sole/tween.js for a full list of contributors.
*
* @param game A reference to the currently running game.
*/
constructor(game: Phaser.Game);
/**
* Local reference to game.
*/
game: Phaser.Game;
/**
* Add a new tween into the TweenManager.
*
* @param tween The tween object you want to add.
* @return The tween object you added to the manager.
*/
add(tween: Phaser.Tween): Phaser.Tween;
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @param object Object the tween will be run on.
* @return The newly created tween object.
*/
create(object: any): Phaser.Tween;
/**
* Get all the tween objects in an array.
* @return Array with all tween objects.
*/
getAll(): Phaser.Tween[];
/**
* Checks to see if a particular Sprite is currently being tweened.
*
* @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 {
/**
* 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): any;
/**
* Gets an objects property by string.
*
* @param obj The object to traverse.
* @param prop The property whose value will be returned.
* @return the value of the property or null if property isn't found .
*/
static getProperty(obj: any, prop: string): any;
/**
* 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;
/**
* 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: any, to: any): any;
/**
* Javascript string pad http://www.webtoolkit.info/.
*
* @param str The target string.
* @param len The number of characters to be added.
* @param pad The string to pad it out with (defaults to a space).
* @param dir The direction dir = 1 (left), 2 (right), 3 (both). - Default: 3
* @return The padded string
*/
static pad(str: string, len: number, pad: number, dir?: number): 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;
/**
* Choose between one of two values randomly.
*
* @param choice1
* @param choice2
* @return The randomly selected choice
*/
static randomChoice(choice1: any, choice2: any): any;
/**
* Rotates the given matrix (array of arrays).
*
* Based on the routine from {@link http://jsfiddle.net/MrPolywhirl/NH42z/}.
*
* @param matrix The array to rotate; this matrix _may_ be altered.
* @param direction The amount to rotate: the roation in degrees (90, -90, 270, -270, 180) or a string command ('rotateLeft', 'rotateRight' or 'rotate180').
* @return The rotated matrix. The source matrix should be discarded for the returned matrix.
*/
static rotateArray(array: T[], direction: any): T;
/**
* 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;
/**
* A standard Fisher-Yates Array shuffle implementation.
*
* @param array The array to shuffle.
* @return The shuffled array.
*/
static shuffle(array: T[]): T[];
/**
* Transposes the elements of the given matrix (array of arrays).
*
* @param array The matrix to transpose.
* @return A new transposed matrix
*/
static transposeArray(array: T[]): T[];
}
module Utils {
/**
* A collection of methods for displaying debug information about game objects.
* 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!
* If your game is using a Canvas renderer then the debug information is literally drawn on the top of the active game canvas and no Sprite is used.
*/
class Debug {
/**
* A collection of methods for displaying debug information about game objects.
* 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!
* If your game is using a Canvas renderer then the debug information is literally drawn on the top of the active game canvas and no Sprite is used.
*
* @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.
*/
columnWidth: number;
/**
* The 2d context of the canvas.
*/
context: CanvasRenderingContext2D;
/**
* The current alpha the debug information will be rendered at.
* Default: 1
*/
currentAlpha: number;
/**
* The current X position the debug information will be rendered at.
* Default: 0
*/
currentX: number;
/**
* The current Y position the debug information will be rendered at.
* Default: 0
*/
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.
*/
lineHeight: number;
/**
* Should the text be rendered with a slight shadow? Makes it easier to read on different types of background.
*/
renderShadow: boolean;
/**
* If debugging in WebGL mode we need this.
*/
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. Note this only works for Arcade and
* Ninja (AABB, circle only) Physics.
* To display a P2 body you should enable debug mode on the body when creating it.
*
* @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: 'rgba(0,255,0,0.4)'
* @param filled Render the objected as a filled (default, true) or a stroked (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;
/**
* 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;
/**
* 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. - Default: 0
*/
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(): 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. - Default: false
* @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;
rectangle(object: Phaser.Rectangle, color?: string, filled?: boolean): void;
/**
* Clears the Debug canvas.
*/
reset(): void;
/**
* Renders the Rope's segments. Note: This is really expensive as it has to calculate new segments everytime 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. - Default: 0
* @param y The Y value the debug info will start from. - Default: 0
* @param color The color the debug text will drawn in. - Default: 'rgb(255,255,255)'
* @param columnWidth The spacing between columns. - Default: 0
*/
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;
}
}
/**
* "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;
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;
/**
* 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;
/**
* 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. Note that this doesn't modify the world x/y coordinates, just the width and height.
* 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;
/**
* 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.
*
* @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. - Default: 0
* @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. - Default: false
* @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;
}
}
// Type definitions for p2.js v0.6.0
// Project: https://github.com/schteppe/p2.js/
declare module p2 {
/**
* Axis aligned bounding box class.
*/
export class AABB {
/**
* Axis aligned bounding box class.
*
* @param options
* @param options.upperBound
* @param options.lowerBound
*/
constructor(options?: {
/**
* The upper bound of the bounding box.
*/
upperBound?: number[];
/**
* The lower bound of the bounding box.
*/
lowerBound?: number[];
});
setFromPoints(points: number[][], position: number[], angle: number, skinSize: number): void;
copy(aabb: AABB): void;
extend(aabb: AABB): void;
overlaps(aabb: AABB): boolean;
}
/**
* Base class for broadphase implementations.
*/
export class Broadphase {
/**
* Axis aligned bounding box type.
*/
static AABB: number;
/**
* Bounding circle type.
*/
static BOUNDING_CIRCLE: number;
static NAIVE: number;
static SAP: number;
static boundingRadiusCheck(bodyA: Body, bodyB: Body): boolean;
static aabbCheck(bodyA: Body, bodyB: Body): boolean;
static canCollide(bodyA: Body, bodyB: Body): boolean;
/**
* Base class for broadphase implementations.
*/
constructor(type: number);
type: number;
/**
* The resulting overlapping pairs. Will be filled with results during .getCollisionPairs().
*/
result: Body[];
/**
* The world to search for collision pairs in. To change it, use .setWorld()
*/
world: World;
/**
* The bounding volume type to use in the broadphase algorithms.
*/
boundingVolumeType: number;
setWorld(world: World): void;
getCollisionPairs(world: World): Body[];
boundingVolumeCheck(bodyA: Body, bodyB: Body): boolean;
}
/**
* Broadphase that uses axis-aligned bins.
*/
export class GridBroadphase extends Broadphase {
/**
* Broadphase that uses axis-aligned bins.
*
* @param options
* @param options.xmin Lower x bound of the grid
* @param options.xmax Upper x bound
* @param options.ymin Lower y bound
* @param options.ymax Upper y bound
* @param options.nx Number of bins along x axis
* @param options.ny Number of bins along y axis
*/
constructor(options?: {
xmin?: number;
xmax?: number;
ymin?: number;
ymax?: number;
nx?: number;
ny?: number;
});
xmin: number;
xmax: number;
ymin: number;
ymax: number;
nx: number;
ny: number;
binsizeX: number;
binsizeY: number;
}
export class NativeBroadphase extends Broadphase {
}
/**
* Narrowphase. Creates contacts and friction given shapes and transforms.
*/
export class Narrowphase {
contactEquations: ContactEquation[];
frictionEquations: FrictionEquation[];
/**
* Whether to make friction equations in the upcoming contacts.
*/
enableFriction: boolean;
/**
* The friction slip force to use when creating friction equations.
*/
slipForce: number;
/**
* The friction value to use in the upcoming friction equations.
*/
frictionCoefficient: number;
/**
* Will be the .relativeVelocity in each produced FrictionEquation.
*/
surfaceVelocity: number;
reuseObjects: boolean;
resuableContactEquations: any[];
reusableFrictionEquations: any[];
/**
* The restitution value to use in the next contact equations.
*/
restitution: number;
/**
* The stiffness value to use in the next contact equations.
*/
stiffness: number;
/**
* The stiffness value to use in the next contact equations.
*/
relaxation: number;
/**
* The stiffness value to use in the next friction equations.
*/
frictionStiffness: number;
/**
* The relaxation value to use in the next friction equations.
*/
frictionRelaxation: number;
/**
* Enable reduction of friction equations. If disabled, a box on a plane will generate 2 contact equations and 2 friction equations. If enabled, there will be only one friction equation. Same kind of simplifications are made for all collision types.
* Default: true
*/
enableFrictionReduction: boolean;
/**
* Contact skin size value to use in the next contact equations.
* Default: 0.01
*/
contactSkinSize: number;
collidedLastStep(bodyA: Body, bodyB: Body): boolean;
reset(): void;
createContactEquation(bodyA: Body, bodyB: Body, shapeA: Shape, shapeB: Shape): ContactEquation;
createFrictionFromContact(c: ContactEquation): FrictionEquation;
}
/**
* Sweep and prune broadphase along one axis.
*/
export class SAPBroadphase extends Broadphase {
/**
* List of bodies currently in the broadphase.
*/
axisList: Body[];
/**
* The axis to sort along. 0 means x-axis and 1 y-axis. If your bodies are more spread out over the X axis, set axisIndex to 0, and you will gain some performance.
*/
axisIndex: number;
}
/**
* Base constraint class.
*/
export class Constraint {
static DISTANCE: number;
static GEAR: number;
static LOCK: number;
static PRISMATIC: number;
static REVOLUTE: number;
/**
* Base constraint class.
*
* @param bodyA
* @param bodyB
* @param type
* @param options
* @param options.collideConnected - Default: true
*/
constructor(bodyA: Body, bodyB: Body, type: number, options?: {
/**
* Set to true if you want the connected bodies to collide.
* Default: true
*/
collideConnected?: boolean;
wakeUpBodies?: boolean;
});
/**
* The type of constraint. May be one of Constraint.DISTANCE, Constraint.GEAR, Constraint.LOCK, Constraint.PRISMATIC or Constraint.REVOLUTE.
*/
type: number;
equeations: Equation[];
/**
* First body participating in the constraint.
*/
bodyA: Body;
/**
* Second body participating in the constraint.
*/
bodyB: Body;
/**
* Set to true if you want the connected bodies to collide.
* Default: true
*/
collideConnected: boolean;
update(): void;
setStiffness(stiffness: number): void;
setRelaxation(relaxation: number): void;
}
/**
* A constraint that tries to keep the distance between two bodies constant.
*/
export class DistanceConstraint extends Constraint {
/**
* 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(bodyA: Body, bodyB: Body, type: number, options?: {
collideConnected?: boolean;
wakeUpBodies?: boolean;
/**
* The distance to keep.
*/
distance?: number;
/**
* Local anchor in body A.
*/
localAnchorA?: number[];
/**
* Local anchor in body B.
*/
localAnchorB?: number[];
/**
* Max force to apply.
*/
maxForce?: number;
});
/**
* Local anchor in body A.
*/
localAnchorA: number[];
/**
* Local anchor in body B.
*/
localAnchorB: number[];
/**
* The distance to keep.
*/
distance: number;
/**
* Max force to apply.
*/
maxForce: number;
/**
* If the upper limit is enabled or not.
*/
upperLimitEnabled: boolean;
/**
* The upper constraint limit.
*/
upperLimit: number;
/**
* If the lower limit is enabled or not.
*/
lowerLimitEnabled: boolean;
/**
* The lower constraint limit.
*/
lowerLimit: number;
/**
* Current constraint position. This is equal to the current distance between the world anchor points.
*/
position: number;
setMaxForce(f: number): void;
getMaxForce(): number;
}
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
export class GearConstraint extends Constraint {
/**
* 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 - Default: 0
* @param ratio The gear ratio. - Default: 1
*/
constructor(bodyA: Body, bodyB: Body, type: number, options?: {
collideConnected?: boolean;
wakeUpBodies?: boolean;
/**
* The relative angle
*/
angle?: number;
/**
* The gear ratio.
*/
ratio?: number;
maxTorque?: number;
});
/**
* The gear ratio.
*/
ratio: number;
/**
* The relative angle
*/
angle: number;
setMaxTorque(torque: number): void;
getMaxTorque(): number;
}
/**
* Locks the relative position between two bodies.
*/
export class LockConstraint extends Constraint {
/**
* 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. - Default: 0
* @param maxForce The maximum force that should be applied to constrain the bodies.
*/
constructor(bodyA: Body, bodyB: Body, type: number, options?: {
collideConnected?: boolean;
wakeUpBodies?: boolean;
/**
* The offset of bodyB in bodyA's frame.
*/
localOffsetB?: number[];
/**
* The offset angle of bodyB in bodyA's frame.
*/
localAngleB?: number;
maxForce?: number;
});
setMaxForce(force: number): void;
getMaxForce(): number;
}
/**
* Constraint that only allows bodies to move along a line, relative to each other. See this tutorial.
*/
export class PrismaticConstraint extends Constraint {
/**
* Constraint that only allows bodies to move along a line, relative to each other. See this tutorial.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.maxForce Max force to be applied by the constraint
* @param options.localAnchorA Body A's anchor point, defined in its own local frame.
* @param options.localAnchorB Body B's anchor point, defined in its own local frame.
* @param options.localAxisA An axis, defined in body A frame, that body B's anchor point may slide along.
* @param options.disableRotationalLock If set to true, bodyB will be free to rotate around its anchor point.
* @param options.upperLimit
* @param options.lowerLimit
*/
constructor(bodyA: Body, bodyB: Body, type: number, options?: {
collideConnected?: boolean;
wakeUpBodies?: boolean;
maxForce?: number;
localAnchorA?: number[];
localAnchorB?: number[];
localAxisA?: number[];
disableRotationalLock?: boolean;
/**
* Upper constraint limit. The constraint position is forced to be smaller than this value.
*/
upperLimit?: number;
/**
* Lower constraint limit. The constraint position is forced to be larger than this value.
*/
lowerLimit?: number;
});
localAnchorA: number[];
localAnchorB: number[];
localAxisA: number[];
/**
* The position of anchor A relative to anchor B, along the constraint axis.
*/
position: number;
velocity: number;
/**
* Set to true to enable lower limit.
*/
lowerLimitEnabled: boolean;
/**
* Set to true to enable upper limit.
*/
upperLimitEnabled: boolean;
/**
* Lower constraint limit. The constraint position is forced to be larger than this value.
*/
lowerLimit: number;
/**
* Upper constraint limit. The constraint position is forced to be smaller than this value.
*/
upperLimit: number;
upperLimitEquation: ContactEquation;
lowerLimitEquation: ContactEquation;
/**
* Equation used for the motor.
*/
motorEquation: Equation;
/**
* The current motor state. Enable or disable the motor using .enableMotor
*/
motorEnabled: boolean;
/**
* Set the target speed for the motor.
*/
motorSpeed: number;
enableMotor(): void;
disableMotor(): void;
setLimits(lower: number, upper: number): void;
}
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*/
export class RevoluteConstraint extends Constraint {
/**
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.worldPivot A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
* @param options.localPivotA The point relative to the center of mass of bodyA which bodyA is constrained to.
* @param options.localPivotB See localPivotA.
* @param options.maxForce The maximum force that should be applied to constrain the bodies.
*/
constructor(bodyA: Body, bodyB: Body, type: number, options?: {
collideConnected?: boolean;
wakeUpBodies?: boolean;
worldPivot?: number[];
localPivotA?: number[];
localPivotB?: number[];
maxForce?: number;
});
pivotA: number[];
pivotB: number[];
motorEquation: RotationalVelocityEquation;
/**
* Indicates whether the motor is enabled. Use .enableMotor() to enable the constraint motor.
*/
motorEnabled: boolean;
/**
* The constraint position.
*/
angle: number;
/**
* Set to true to enable lower limit
*/
lowerLimitEnabled: boolean;
/**
* Set to true to enable upper limit
*/
upperLimitEnabled: boolean;
/**
* The lower limit on the constraint angle.
*/
lowerLimit: number;
/**
* The upper limit on the constraint angle.
*/
upperLimit: number;
upperLimitEquation: ContactEquation;
lowerLimitEquation: ContactEquation;
enableMotor(): void;
disableMotor(): void;
motorIsEnabled(): boolean;
setLimits(lower: number, upper: number): void;
setMotorSpeed(speed: number): void;
getMotorSpeed(): number;
}
/**
* Locks the relative angle between two bodies. The constraint tries to keep the dot product between two vectors, local in each body, to zero. The local angle in body i is a parameter.
*/
export class AngleLockEquation extends Equation {
/**
* Locks the relative angle between two bodies. The constraint tries to keep the dot product between two vectors, local in each body, to zero. The local angle in body i is a parameter.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.angle Angle to add to the local vector in body A.
* @param options.ratio Gear ratio
*/
constructor(bodyA: Body, bodyB: Body, options?: {
angle?: number;
/**
* The gear ratio.
*/
ratio?: number;
});
computeGq(): number;
setRatio(ratio: number): number;
setMaxTorque(torque: number): number;
}
/**
* Non-penetration constraint equation. Tries to make the contactPointA and contactPointB vectors coincide, while keeping the applied force repulsive.
*/
export class ContactEquation extends Equation {
/**
* Non-penetration constraint equation. Tries to make the contactPointA and contactPointB vectors coincide, while keeping the applied force repulsive.
*
* @param bodyA
* @param bodyB
*/
constructor(bodyA: Body, bodyB: Body);
/**
* Vector from body i center of mass to the contact point.
*/
contactPointA: number[];
penetrationVec: number[];
/**
* World-oriented vector from body A center of mass to the contact point.
*/
contactPointB: number[];
/**
* The normal vector, pointing out of body i
*/
normalA: number[];
/**
* The restitution to use (0=no bounciness, 1=max bounciness).
*/
restitution: number;
/**
* This property is set to true if this is the first impact between the bodies (not persistant contact).
*/
firstImpact: boolean;
/**
* The shape in body i that triggered this contact.
*/
shapeA: Shape;
/**
* The shape in body j that triggered this contact.
*/
shapeB: Shape;
computeB(a: number, b: number, h: number): number;
}
/**
* Base class for constraint equations.
*/
export class Equation {
/**
* The default stiffness when creating a new Equation.
* Default: 1e6
*/
static DEFAULT_STIFFNESS: number;
/**
* The default relaxation when creating a new Equation.
* Default: 4
*/
static DEFAULT_RELAXATION: number;
/**
* Base class for constraint equations.
*
* @param bodyA First body participating in the equation
* @param bodyB Second body participating in the equation
* @param minForce Minimum force to apply. Default: -Number.MAX_VALUE
* @param maxForce Maximum force to apply. Default: Number.MAX_VALUE
*/
constructor(bodyA: Body, bodyB: Body, minForce?: number, maxForce?: number);
/**
* Minimum force to apply when solving.
*/
minForce: number;
/**
* Max force to apply when solving.
*/
maxForce: number;
/**
* First body participating in the constraint
*/
bodyA: Body;
/**
* Second body participating in the constraint
*/
bodyB: Body;
/**
* The stiffness of this equation. Typically chosen to a large number (~1e7), but can be chosen somewhat freely to get a stable simulation.
*/
stiffness: number;
/**
* The number of time steps needed to stabilize the constraint equation. Typically between 3 and 5 time steps.
*/
relaxation: number;
/**
* The Jacobian entry of this equation. 6 numbers, 3 per body (x,y,angle).
*/
G: number[];
offset: number;
a: number;
b: number;
epsilon: number;
timeStep: number;
/**
* Indicates if stiffness or relaxation was changed.
*/
needsUpdate: boolean;
/**
* The resulting constraint multiplier from the last solve. This is mostly equivalent to the force produced by the constraint.
*/
multiplier: number;
/**
* Relative velocity.
*/
relativeVelocity: number;
/**
* Whether this equation is enabled or not. If true, it will be added to the solver.
*/
enabled: boolean;
gmult(G: number[], vi: number[], wi: number[], vj: number[], wj: number[]): number;
computeB(a: number, b: number, h: number): number;
computeGq(): number;
computeGW(): number;
computeGWlambda(): number;
computeGiMf(): number;
computeGiMGt(): number;
addToWlambda(deltalambda: number): number;
computeInvC(eps: number): number;
}
/**
* Constrains the slipping in a contact along a tangent
*/
export class FrictionEquation extends Equation {
/**
* Constrains the slipping in a contact along a tangent
*
* @param bodyA
* @param bodyB
* @param slipForce
*/
constructor(bodyA: Body, bodyB: Body, slipForce: number);
/**
* Relative vector from center of body A to the contact point, world oriented.
*/
contactPointA: number[];
/**
* Relative vector from center of body B to the contact point, world oriented.
*/
contactPointB: number[];
/**
* Tangent vector that the friction force will act along. World oriented.
*/
t: number[];
/**
* The shape in body i that triggered this friction.
*/
shapeA: Shape;
/**
* The shape in body j that triggered this friction.
*/
shapeB: Shape;
/**
* The friction coefficient to use.
*/
frictionCoefficient: number;
setSlipForce(slipForce: number): number;
getSlipForce(): number;
computeB(a: number, b: number, h: number): number;
}
/**
* Locks the relative angle between two bodies. The constraint tries to keep the dot product between two vectors, local in each body, to zero. The local angle in body i is a parameter.
*/
export class RotationalLockEquation extends Equation {
/**
* Locks the relative angle between two bodies. The constraint tries to keep the dot product between two vectors, local in each body, to zero. The local angle in body i is a parameter.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.angle Angle to add to the local vector in bodyA.
*/
constructor(bodyA: Body, bodyB: Body, options?: {
angle?: number;
});
angle: number;
computeGq(): number;
}
/**
* Syncs rotational velocity of two bodies, or sets a relative velocity (motor).
*/
export class RotationalVelocityEquation extends Equation {
/**
* Syncs rotational velocity of two bodies, or sets a relative velocity (motor).
*
* @param bodyA
* @param bodyB
*/
constructor(bodyA: Body, bodyB: Body);
computeB(a: number, b: number, h: number): number;
}
/**
* Base class for objects that dispatches events.
*/
export class EventEmitter {
on(type: string, listener: Function, context: any): EventEmitter;
has(type: string, listener: Function): boolean;
off(type: string, listener: Function): EventEmitter;
emit(event: any): EventEmitter;
}
export class ContactMaterialOptions {
friction: number;
restitution: number;
stiffness: number;
relaxation: number;
frictionStiffness: number;
frictionRelaxation: number;
surfaceVelocity: number;
}
/**
* Defines a physics material
*/
export class ContactMaterial {
static idCounter: number;
/**
* Defines a physics material
*
* @param materialA First material participating in the contact material.
* @param materialB Second material participating in the contact material.
* @param options Additional configuration options.
*/
constructor(materialA: Material, materialB: Material, options?: ContactMaterialOptions);
/**
* The contact material identifier
*/
id: number;
/**
* First material participating in the contact material
*/
materialA: Material;
/**
* Second material participating in the contact material
*/
materialB: Material;
/**
* Friction to use in the contact of these two materials
*/
friction: number;
/**
* Restitution to use in the contact of these two materials
*/
restitution: number;
/**
* Stiffness of the resulting ContactEquation that this ContactMaterial generate
*/
stiffness: number;
/**
* Relaxation of the resulting ContactEquation that this ContactMaterial generate
*/
relaxation: number;
frictionStuffness: number;
/**
* Relaxation of the resulting FrictionEquation that this ContactMaterial generate
*/
frictionRelaxation: number;
/**
* Will add surface velocity to this material. If bodyA rests on top if bodyB, and the surface velocity is positive, bodyA will slide to the right.
*/
surfaceVelocity: number;
/**
* Offset to be set on ContactEquations. A positive value will make the bodies penetrate more into each other. Can be useful in scenes where contacts need to be more persistent, for example when stacking. Aka "cure for nervous contacts".
*/
contactSkinSize: number;
}
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*/
export class Material {
static idCounter: number;
/**
* A P2 Material.
*
* \o/ ~ "Because I'm a Material girl"
*
* @param name The user defined name given to this Material.
*/
constructor(id: number);
/**
* The material identifier
*/
id: number;
}
/**
* The vec2 object from glMatrix, with some extensions and some removed methods. See http://glmatrix.net.
*/
export class vec2 {
static crossLength(a: number[], b: number[]): number;
static crossVZ(out: number[], vec: number[], zcomp: number): number;
static crossZV(out: number[], zcomp: number, vec: number[]): number;
static rotate(out: number[], a: number[], angle: number): void;
static rotate90cw(out: number[], a: number[]): number;
static centroid(out: number[], a: number[], b: number[], c: number[]): number[];
static create(): number[];
static clone(a: number[]): number[];
static fromValues(x: number, y: number): number[];
static copy(out: number[], a: number[]): number[];
static set(out: number[], x: number, y: number): number[];
static toLocalFrame(out: number[], worldPoint: number[], framePosition: number[], frameAngle: number): void;
static toGlobalFrame(out: number[], localPoint: number[], framePosition: number[], frameAngle: number): void;
static add(out: number[], a: number[], b: number[]): number[];
static subtract(out: number[], a: number[], b: number[]): number[];
static sub(out: number[], a: number[], b: number[]): number[];
static multiply(out: number[], a: number[], b: number[]): number[];
static mul(out: number[], a: number[], b: number[]): number[];
static divide(out: number[], a: number[], b: number[]): number[];
static div(out: number[], a: number[], b: number[]): number[];
static scale(out: number[], a: number[], b: number): number[];
static distance(a: number[], b: number[]): number;
static dist(a: number[], b: number[]): number;
static squaredDistance(a: number[], b: number[]): number;
static sqrDist(a: number[], b: number[]): number;
static length(a: number[]): number;
static len(a: number[]): number;
static squaredLength(a: number[]): number;
static sqrLen(a: number[]): number;
static negate(out: number[], a: number[]): number[];
static normalize(out: number[], a: number[]): number[];
static dot(a: number[], b: number[]): number;
static str(a: number[]): string;
}
export class BodyOptions {
mass: number;
position: number[];
velocity: number[];
angle: number;
angularVelocity: number;
force: number[];
angularForce: number;
fixedRotation: 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.
*/
export class Body extends EventEmitter {
sleepyEvent: {
/**
* The type of physics system this body belongs to.
*/
type: string;
};
sleepEvent: {
/**
* The type of physics system this body belongs to.
*/
type: string;
};
wakeUpEvent: {
/**
* The type of physics system this body belongs to.
*/
type: string;
};
/**
* 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;
static AWAKE: number;
static SLEEPY: number;
static SLEEPING: 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. - Default: 0
* @param y The y coordinate of this Body. - Default: 0
* @param mass The default mass of this Body (0 = static). - Default: 1
*/
constructor(options?: BodyOptions);
/**
* The Body ID. Each Body that has been added to the World has a unique ID.
*/
id: number;
/**
* Local reference to the P2 World.
*/
world: World;
/**
* The shapes of the body. The local transform of the shape in .shapes[i] is
* defined by .shapeOffsets[i] and .shapeAngles[i].
*/
shapes: Shape[];
/**
* The local shape offsets, relative to the body center of mass. This is an
* array of Array.
*/
shapeOffsets: number[][];
/**
* The body-local shape angle transforms. This is an array of numbers (angles).
*/
shapeAngles: number[];
/**
* -
*/
mass: number;
/**
* The inverse mass of the body.
*/
invMass: number;
/**
* The inertia of the body around the Z axis..
*/
inertia: number;
/**
* The inverse inertia of the body.
*/
invInertia: number;
invMassSolve: number;
invInertiaSolve: number;
/**
* -
*/
fixedRotation: number;
/**
* The position of the body
*/
position: number[];
/**
* The interpolated position of the body.
*/
interpolatedPosition: number[];
/**
* The interpolated angle of the body.
*/
interpolatedAngle: number;
/**
* The previous position of the body.
*/
previousPosition: number[];
/**
* The previous angle of the body.
*/
previousAngle: 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: number[];
/**
* Constraint velocity that was added to the body during the last step.
*/
vlambda: number[];
/**
* Angular constraint velocity that was added to the body during last step.
*/
wlambda: number[];
/**
* 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;
/**
* The angular velocity of the body.
*/
angularVelocity: number;
/**
* The force applied to the body.
*/
force: number[];
/**
* The angular force acting on the body.
*/
angularForce: number;
/**
* 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;
/**
* 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 type of physics system this body belongs to.
*/
type: number;
/**
* Bounding circle radius.
*/
boundingRadius: number;
/**
* Bounding box of this body.
*/
aabb: AABB;
/**
* Indicates if the AABB needs update. Update it with {{#crossLink "Body/updateAABB:method"}}.updateAABB(){{/crossLink}}.
*/
aabbNeedsUpdate: boolean;
/**
* -
*/
allowSleep: boolean;
wantsToSleep: boolean;
/**
* One of {{#crossLink "Body/AWAKE:property"}}Body.AWAKE{{/crossLink}}, {{#crossLink "Body/SLEEPY:property"}}Body.SLEEPY{{/crossLink}} and {{#crossLink "Body/SLEEPING:property"}}Body.SLEEPING{{/crossLink}}.
*
* The body is initially Body.AWAKE. If its velocity norm is below .sleepSpeedLimit, the sleepState will become Body.SLEEPY. If the body continues to be Body.SLEEPY for .sleepTimeLimit seconds, it will fall asleep (Body.SLEEPY).
* Default: Body.AWAKE
*/
sleepState: number;
/**
* .
*/
sleepSpeedLimit: number;
/**
* If the body has been sleepy for this sleepTimeLimit seconds, it is considered sleeping.
* Default: 1
*/
sleepTimeLimit: number;
/**
* Gravity scaling factor. If you want the body to ignore gravity, set this to zero. If you want to reverse gravity, set it to -1.
* Default: 1
*/
gravityScale: number;
updateSolveMassProperties(): void;
setDensity(density: number): void;
getArea(): number;
getAABB(): AABB;
updateAABB(): void;
updateBoundingRadius(): void;
/**
* 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.
*
* @param shape The shape to add to the body.
* @param offsetX Local horizontal offset of the shape relative to the body center of mass. - Default: 0
* @param offsetY Local vertical offset of the shape relative to the body center of mass. - Default: 0
* @param rotation Local rotation of the shape relative to the body center of mass, specified in radians. - Default: 0
* @return The shape that was added to the body.
*/
addShape(shape: Shape, offset?: number[], angle?: number): 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: Shape): boolean;
updateMassProperties(): 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[], worldPoint: number[]): 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;
/**
* 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;
fromPolygon(path: number[][], options?: {
optimalDecomp?: boolean;
skipSimpleCheck?: boolean;
removeCollinearPoints?: any; //boolean | number
}): boolean;
/**
* Moves the shape offsets so their center of mass becomes the body center of mass.
*/
adjustCenterOfMass(): void;
/**
* Sets the force on the body to zero.
*/
setZeroForce(): void;
resetConstraintVelocity(): void;
/**
* Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details.
*
* @param dt Current time step.
*/
applyDamping(dy: number): void;
wakeUp(): void;
sleep(): void;
sleepTick(time: number, dontSleep: boolean, dt: number): void;
getVelocityFromPosition(story: number[], dt: number): number[];
getAngularVelocityFromPosition(timeStep: number): number;
overlaps(body: Body): boolean;
}
/**
* A spring, connecting two bodies. The Spring explicitly adds force and angularForce to the bodies and does therefore not put load on the constraint solver.
*/
export class Spring {
/**
* A spring, connecting two bodies. The Spring explicitly adds force and angularForce to the bodies and does therefore not put load on the constraint solver.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.stiffness Spring constant (see Hookes Law). A number >= 0. - Default: 100
* @param options.damping A number >= 0. Default: 1 - Default: 1
* @param options.localAnchorA Where to hook the spring to body A, in local body coordinates. Defaults to the body center.
* @param options.localAnchorB
* @param options.worldAnchorA Where to hook the spring to body A, in world coordinates. Overrides the option "localAnchorA" if given.
* @param options.worldAnchorB
*/
constructor(bodyA: Body, bodyB: Body, options?: {
/**
* Stiffness of the spring.
*/
stiffness?: number;
/**
* Damping of the spring.
*/
damping?: number;
localAnchorA?: number[];
localAnchorB?: number[];
worldAnchorA?: number[];
worldAnchorB?: number[];
});
/**
* Stiffness of the spring.
*/
stiffness: number;
/**
* Damping of the spring.
*/
damping: number;
/**
* First connected body.
*/
bodyA: Body;
/**
* Second connected body.
*/
bodyB: Body;
applyForce(): void;
}
/**
* A spring, connecting two bodies.
*
* The Spring explicitly adds force and angularForce to the bodies.
*/
export class LinearSpring extends Spring {
/**
* Anchor for bodyA in local bodyA coordinates.
*/
localAnchorA: number[];
/**
* Anchor for bodyB in local bodyB coordinates.
*/
localAnchorB: number[];
/**
* Rest length of the spring.
*/
restLength: number;
setWorldAnchorA(worldAnchorA: number[]): void;
setWorldAnchorB(worldAnchorB: number[]): void;
getWorldAnchorA(result: number[]): number[];
getWorldAnchorB(result: number[]): number[];
applyForce(): void;
}
/**
* A rotational spring, connecting two bodies rotation. This spring explicitly adds angularForce (torque) to the bodies.
*
* The spring can be combined with a {{#crossLink "RevoluteConstraint"}}{{/crossLink}} to make, for example, a mouse trap.
*/
export class RotationalSpring extends Spring {
/**
* A rotational spring, connecting two bodies rotation. This spring explicitly adds angularForce (torque) to the bodies.
*
* The spring can be combined with a {{#crossLink "RevoluteConstraint"}}{{/crossLink}} to make, for example, a mouse trap.
*
* @param bodyA
* @param bodyB
* @param options
* @param options.restAngle The relative angle of bodies at which the spring is at rest. If not given, it's set to the current relative angle between the bodies.
* @param options.stiffness Spring constant (see Hookes Law). A number >= 0. - Default: 100
* @param options.damping A number >= 0. - Default: 1
*/
constructor(bodyA: Body, bodyB: Body, options?: {
/**
* Rest angle of the spring.
*/
restAngle?: number;
stiffness?: number;
damping?: number;
});
/**
* Rest angle of the spring.
*/
restAngle: number;
}
/**
* Capsule shape class.
*/
export class Capsule extends Shape {
/**
* Capsule shape class.
*
* @param length The distance between the end points - Default: 1
* @param radius Radius of the capsule - Default: 1
*/
constructor(length?: number, radius?: number);
/**
* The distance between the end points.
*/
length: number;
/**
* The radius of the capsule.
*/
radius: number;
}
/**
* Circle shape class.
*/
export class Circle extends Shape {
/**
* Circle shape class.
*
* @param radius The radius of this circle - Default: 1
*/
constructor(radius: number);
/**
* The radius of the circle.
*/
radius: number;
}
/**
* Convex shape class.
*/
export class Convex extends Shape {
static triangleArea(a: number[], b: number[], c: number[]): number;
/**
* Convex shape class.
*
* @param vertices An array of vertices that span this shape. Vertices are given in counter-clockwise (CCW) direction.
* @param axes An array of unit length vectors, representing the symmetry axes in the convex.
*/
constructor(vertices: number[][], axes: number[]);
/**
* Vertices defined in the local frame.
*/
vertices: number[][];
/**
* Axes defined in the local frame.
*/
axes: number[];
/**
* The center of mass of the Convex
*/
centerOfMass: number[];
/**
* Triangulated version of this convex. The structure is Array of 3-Arrays, and each subarray contains 3 integers, referencing the vertices.
*/
triangles: number[];
/**
* The bounding radius of the convex
*/
boundingRadius: number;
projectOntoLocalAxis(localAxis: number[], result: number[]): void;
projectOntoWorldAxis(localAxis: number[], shapeOffset: number[], shapeAngle: number, result: number[]): void;
updateCenterOfMass(): void;
}
/**
* Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a distance "elementWidth".
*/
export class Heightfield extends Shape {
/**
* Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a distance "elementWidth".
*
* @param data An array of Y values that will be used to construct the terrain.
* @param options
* @param options.minValue Minimum value of the data points in the data array. Will be computed automatically if not given.
* @param options.maxValue Maximum value.
* @param options.elementWidth World spacing between the data points in X direction. - Default: 0.1
*/
constructor(data: number[], options?: {
/**
* Max value of the data
*/
minValue?: number;
/**
* Max value of the data
*/
maxValue?: number;
/**
* The width of each element
*/
elementWidth: number;
});
/**
* An array of numbers, or height values, that are spread out along the x axis.
*/
data: number[];
/**
* Max value of the data
*/
maxValue: number;
/**
* Max value of the data
*/
minValue: number;
/**
* The width of each element
*/
elementWidth: number;
}
/**
* Base class for shapes.
*/
export class Shape {
static idCounter: number;
static CIRCLE: number;
static PARTICLE: number;
static PLANE: number;
static CONVEX: number;
static LINE: number;
static RECTANGLE: number;
static CAPSULE: number;
static HEIGHTFIELD: number;
/**
* Base class for shapes.
*
* @param type
*/
constructor(type: number);
/**
* The type of the shape. One of:
*
* * {{#crossLink "Shape/CIRCLE:property"}}Shape.CIRCLE{{/crossLink}}
* * {{#crossLink "Shape/PARTICLE:property"}}Shape.PARTICLE{{/crossLink}}
* * {{#crossLink "Shape/PLANE:property"}}Shape.PLANE{{/crossLink}}
* * {{#crossLink "Shape/CONVEX:property"}}Shape.CONVEX{{/crossLink}}
* * {{#crossLink "Shape/LINE:property"}}Shape.LINE{{/crossLink}}
* * {{#crossLink "Shape/RECTANGLE:property"}}Shape.RECTANGLE{{/crossLink}}
* * {{#crossLink "Shape/CAPSULE:property"}}Shape.CAPSULE{{/crossLink}}
* * {{#crossLink "Shape/HEIGHTFIELD:property"}}Shape.HEIGHTFIELD{{/crossLink}}
*/
type: number;
/**
* Shape object identifier.
*/
id: number;
/**
* Bounding circle radius of this shape
*/
boundingRadius: number;
/**
* Collision group that this shape belongs to (bit mask). See this tutorial.
*/
collisionGroup: number;
/**
* Collision mask of this shape. See .collisionGroup.
*/
collisionMask: number;
/**
* Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.
*/
material: Material;
/**
* Area of this shape.
*/
area: number;
/**
* Set to true if you want this shape to be a sensor. A sensor does not generate contacts, but it still reports contact events. This is good if you want to know if a shape is overlapping another shape, without them generating contacts.
*/
sensor: boolean;
computeMomentOfInertia(mass: number): number;
updateBoundingRadius(): number;
updateArea(): void;
computeAABB(out: AABB, position: number[], angle: number): void;
}
/**
* Container for line-related functions
*/
export class Line extends Shape {
/**
* Container for line-related functions
*/
constructor(length?: number);
/**
* Length of this line
*/
length: number;
}
/**
* Particle shape class.
*/
export class Particle extends Shape {
}
/**
* Plane shape class. The plane is facing in the Y direction.
*/
export class Plane extends Shape {
}
/**
* Rectangle shape class.
*/
export class Rectangle extends Shape {
static sameDimensions(a: Rectangle, b: Rectangle): boolean;
/**
* Rectangle shape class.
*
* @param width Width - Default: 1
* @param height Height - Default: 1
*/
constructor(width?: number, height?: number);
/**
* Total width of the rectangle
*/
width: number;
/**
* Total height of the rectangle
*/
height: number;
}
/**
* Base class for constraint solvers.
*/
export class Solver extends EventEmitter {
static GS: number;
static ISLAND: number;
/**
* Base class for constraint solvers.
*/
constructor(options?: {}, type?: number);
type: number;
/**
* Current equations in the solver.
*/
equations: Equation[];
/**
* Function that is used to sort all equations before each solve.
*/
equationSortFunction: Equation; //Equation | boolean
solve(dy: number, world: World): void;
solveIsland(dy: number, island: Island): void;
sortEquations(): void;
addEquation(eq: Equation): void;
addEquations(eqs: Equation[]): void;
removeEquation(eq: Equation): void;
removeAllEquations(): void;
}
/**
* Iterative Gauss-Seidel constraint equation solver.
*/
export class GSSolver extends Solver {
/**
* Iterative Gauss-Seidel constraint equation solver.
*
* @param options
* @param options.iterations - Default: 10
* @param options.tolerance - Default: 0
*/
constructor(options?: {
/**
* The number of iterations to do when solving. More gives better results, but is more expensive.
*/
iterations?: number;
/**
* The error tolerance, per constraint. If the total error is below this limit, the solver will stop iterating. Set to zero for as good solution as possible, but to something larger than zero to make computations faster.
*/
tolerance?: number;
});
/**
* The number of iterations to do when solving. More gives better results, but is more expensive.
*/
iterations: number;
/**
* The error tolerance, per constraint. If the total error is below this limit, the solver will stop iterating. Set to zero for as good solution as possible, but to something larger than zero to make computations faster.
*/
tolerance: number;
/**
* Set to true to set all right hand side terms to zero when solving. Can be handy for a few applications.
*/
useZeroRHS: boolean;
/**
* Number of solver iterations that are done to approximate normal forces. When these iterations are done, friction force will be computed from the contact normal forces. These friction forces will override any other friction forces set from the World for example.
* The solver will use less iterations if the solution is below the .tolerance.
*/
frictionIterations: number;
/**
* The number of iterations that were made during the last solve. If .tolerance is zero, this value will always be equal to .iterations, but if .tolerance is larger than zero, and the solver can quit early, then this number will be somewhere between 1 and .iterations.
*/
usedIterations: number;
solve(h: number, world: World): void;
}
/**
* Keeps track of overlaps in the current state and the last step state.
*/
export class OverlapKeeper {
/**
* Keeps track of overlaps in the current state and the last step state.
*/
constructor(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape);
shapeA: Shape;
shapeB: Shape;
bodyA: Body;
bodyB: Body;
tick(): void;
setOverlapping(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Body): void;
bodiesAreOverlapping(bodyA: Body, bodyB: Body): boolean;
set(bodyA: Body, shapeA: Shape, bodyB: Body, shapeB: Shape): void;
}
export class TupleDictionary {
/**
* The data storage
*/
data: number[];
/**
* Keys that are currently used.
*/
keys: number[];
getKey(id1: number, id2: number): string;
getByKey(key: number): number;
get(i: number, j: number): number;
set(i: number, j: number, value: number): number;
reset(): void;
copy(dict: TupleDictionary): void;
}
/**
* Misc utility functions
*/
export class Utils {
static appendArray(a: Array, b: Array): Array;
static chanceRoll(chance: number): boolean;
static defaults(options: any, defaults: any): any;
static extend(a: any, b: any): void;
static randomChoice(choice1: any, choice2: any): any;
static rotateArray(matrix: any[], direction: any): any[];
static splice(array: Array, index: number, howMany: number): void;
static shuffle(array: T[]): T[];
static transposeArray(array: T[]): T[];
}
/**
* An island of bodies connected with equations.
*/
export class Island {
/**
* Current equations in this island.
*/
equations: Equation[];
/**
* Current bodies in this island.
*/
bodies: Body[];
reset(): void;
getBodies(result: any): Body[];
wantsToSleep(): boolean;
sleep(): boolean;
}
/**
* Splits the system of bodies and equations into independent islands
*/
export class IslandManager extends Solver {
static getUnvisitedNode(nodes: Node[]): IslandNode; // IslandNode | boolean
/**
* The equations to split. Manually fill this array before running .split().
*/
equations: Equation[];
/**
* The resulting {{#crossLink "Island"}}{{/crossLink}}s.
*/
islands: Island[];
/**
* The resulting graph nodes.
*/
nodes: IslandNode[];
visit(node: IslandNode, bds: Body[], eqs: Equation[]): void;
bfs(root: IslandNode, bds: Body[], eqs: Equation[]): void;
split(world: World): Island[];
}
/**
* Holds a body and keeps track of some additional properties needed for graph traversal.
*/
export class IslandNode {
/**
* Holds a body and keeps track of some additional properties needed for graph traversal.
*
* @param body
*/
constructor(body: Body);
/**
* The body that is contained in this node.
*/
body: Body;
/**
* Neighboring IslandNodes
*/
neighbors: IslandNode[];
/**
* Equations connected to this node.
*/
equations: Equation[];
/**
* If this node was visiting during the graph traversal.
*/
visited: boolean;
reset(): void;
}
/**
* The dynamics world, where all bodies and constraints lives.
*/
export class World extends EventEmitter {
postStepEvent: {
type: string;
};
addBodyEvent: {
type: string;
};
removeBodyEvent: {
type: string;
};
addSpringEvent: {
type: string;
};
impactEvent: {
type: string;
bodyA: Body;
bodyB: Body;
shapeA: Shape;
shapeB: Shape;
contactEquation: ContactEquation;
};
postBroadphaseEvent: {
type: string;
pairs: Body[];
};
beginContactEvent: {
type: string;
shapeA: Shape;
shapeB: Shape;
bodyA: Body;
bodyB: Body;
contactEquations: ContactEquation[];
};
endContactEvent: {
type: string;
shapeA: Shape;
shapeB: Shape;
bodyA: Body;
bodyB: Body;
};
preSolveEvent: {
type: string;
contactEquations: ContactEquation[];
frictionEquations: FrictionEquation[];
};
/**
* Never deactivate bodies.
*/
static NO_SLEEPING: number;
/**
* Deactivate individual bodies if they are sleepy.
*/
static BODY_SLEEPING: number;
/**
* Deactivates bodies that are in contact, if all of them are sleepy. Note that you must enable {{#crossLink "World/islandSplit:property"}}.islandSplit{{/crossLink}} for this to work.
*/
static ISLAND_SLEEPING: number;
static integrateBody(body: Body, dy: number): void;
/**
* The dynamics world, where all bodies and constraints lives.
*
* @param options
* @param options.solver Defaults to GSSolver.
* @param options.gravity Defaults to [0,-9.78]
* @param options.broadphase Defaults to NaiveBroadphase
* @param options.islandSplit - Default: false
* @param options.doProfiling - Default: false
*/
constructor(options?: {
/**
* The solver used to satisfy constraints and contacts. Default is {{#crossLink "GSSolver"}}{{/crossLink}}.
*/
solver?: Solver;
/**
* Gravity in the world. This is applied on all bodies in the beginning of each step().
*/
gravity?: number[];
/**
* The broadphase algorithm to use.
*/
broadphase?: Broadphase;
/**
* Whether to enable island splitting. Island splitting can be an advantage for many things, including solver performance. See {{#crossLink "IslandManager"}}{{/crossLink}}.
*/
islandSplit?: boolean;
/**
* Whether to do timing measurements during the step() or not.
*/
doProfiling?: boolean;
});
/**
* All springs in the world. To add a spring to the world, use {{#crossLink "World/addSpring:method"}}{{/crossLink}}.
*/
springs: Spring[];
/**
* All bodies in the world. To add a body to the world, use {{#crossLink "World/addBody:method"}}{{/crossLink}}.
*/
bodies: Body[];
/**
* The solver used to satisfy constraints and contacts. Default is {{#crossLink "GSSolver"}}{{/crossLink}}.
*/
solver: Solver;
/**
* The narrowphase to use to generate contacts.
*/
narrowphase: Narrowphase;
/**
* The island manager of this world.
*/
islandManager: IslandManager;
/**
* Gravity in the world. This is applied on all bodies in the beginning of each step().
*/
gravity: number[];
/**
* Gravity to use when approximating the friction max force (mu*mass*gravity).
*/
frictionGravity: number;
/**
* Set to true if you want .frictionGravity to be automatically set to the length of .gravity.
*/
useWorldGravityAsFrictionGravity: boolean;
/**
* If the length of .gravity is zero, and .useWorldGravityAsFrictionGravity=true, then switch to using .frictionGravity for friction instead. This fallback is useful for gravityless games.
*/
useFrictionGravityOnZeroGravity: boolean;
/**
* Whether to do timing measurements during the step() or not.
*/
doProfiling: boolean;
/**
* How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.
*/
lastStepTime: number;
/**
* The broadphase algorithm to use.
*/
broadphase: Broadphase;
/**
* User-added constraints.
*/
constraints: Constraint[];
/**
* Dummy default material in the world, used in .defaultContactMaterial
*/
defaultMaterial: Material;
/**
* The default contact material to use, if no contact material was set for the colliding materials.
*/
defaultContactMaterial: ContactMaterial;
/**
* For keeping track of what time step size we used last step
*/
lastTimeStep: number;
/**
* Enable to automatically apply spring forces each step.
*/
applySpringForces: boolean;
/**
* Enable to automatically apply body damping each step.
*/
applyDamping: boolean;
/**
* Enable to automatically apply gravity each step.
*/
applyGravity: boolean;
/**
* Enable/disable constraint solving in each step.
*/
solveConstraints: boolean;
/**
* The ContactMaterials added to the World.
*/
contactMaterials: ContactMaterial[];
/**
* World time.
*/
time: number;
/**
* Is true during the step().
*/
stepping: boolean;
/**
* Whether to enable island splitting. Island splitting can be an advantage for many things, including solver performance. See {{#crossLink "IslandManager"}}{{/crossLink}}.
*/
islandSplit: boolean;
/**
* Set to true if you want to the world to emit the "impact" event. Turning this off could improve performance.
*/
emitImpactEvent: boolean;
/**
* How to deactivate bodies during simulation. Possible modes are: {{#crossLink "World/NO_SLEEPING:property"}}World.NO_SLEEPING{{/crossLink}}, {{#crossLink "World/BODY_SLEEPING:property"}}World.BODY_SLEEPING{{/crossLink}} and {{#crossLink "World/ISLAND_SLEEPING:property"}}World.ISLAND_SLEEPING{{/crossLink}}.
* If sleeping is enabled, you might need to {{#crossLink "Body/wakeUp:method"}}wake up{{/crossLink}} the bodies if they fall asleep when they shouldn't. If you want to enable sleeping in the world, but want to disable it for a particular body, see {{#crossLink "Body/allowSleep:property"}}Body.allowSleep{{/crossLink}}.
* Default: World.NO_SLEEPING
*/
sleepMode: number;
addConstraint(c: Constraint): void;
addContactMaterial(contactMaterial: ContactMaterial): void;
removeContactMaterial(cm: ContactMaterial): void;
getContactMaterial(materialA: Material, materialB: Material): ContactMaterial; // ContactMaterial | boolean
removeConstraint(c: Constraint): void;
step(dy: number, timeSinceLastCalled?: number, maxSubSteps?: number): void;
runNarrowphase(np: Narrowphase, bi: Body, si: Shape, xi: any[], ai: number, bj: Body, sj: Shape, xj: any[], aj: number, cm: number, glen: number): void;
addSpring(s: Spring): void;
removeSpring(s: Spring): void;
addBody(body: Body): void;
removeBody(body: Body): void;
getBodyByID(id: number): Body; //Body | boolean
disableBodyCollision(bodyA: Body, bodyB: Body): void;
enableBodyCollision(bodyA: Body, bodyB: Body): void;
clear(): void;
clone(): World;
hitTest(worldPoint: number[], bodies: Body[], precision: number): Body[];
setGlobalEquationParameters(parameters: {
relaxation?: number;
stiffness?: number;
}): void;
setGlobalStiffness(stiffness: number): void;
setGlobalRelaxation(relaxation: number): void;
}
}