Refactoring ready for 1.0 release.

This commit is contained in:
Richard Davey
2013-05-25 04:21:24 +01:00
parent 4ef0750c07
commit 204ec46b2b
90 changed files with 15043 additions and 15223 deletions
-664
View File
@@ -1,664 +0,0 @@
/// <reference path="../gameobjects/Sprite.ts" />
/// <reference path="../Game.ts" />
/**
* Phaser - Camera
*
* A Camera is your view into the game world. It has a position, size, scale and rotation and renders only those objects
* within its field of view. The game automatically creates a single Stage sized camera on boot, but it can be changed and
* additional cameras created via the CameraManager.
*/
module Phaser {
export class Camera {
/**
*Sprite constructor
* Instantiates a new camera at the specified location, with the specified size and zoom level.
*
* @param game {Phaser.Game} Current game instance.
* @param id {number} Unique identity.
* @param x {number} X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
* @param y {number} Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
* @param width {number} The width of the camera display in pixels.
* @param height {number} The height of the camera display in pixels.
*/
constructor(game: Game, id: number, x: number, y: number, width: number, height: number) {
this._game = game;
this.ID = id;
this._stageX = x;
this._stageY = y;
this.fx = new FXManager(this._game, this);
// The view into the world canvas we wish to render
this.worldView = new Rectangle(0, 0, width, height);
this.checkClip();
}
/**
* Local private reference to Game.
*/
private _game: Game;
private _clip: bool = false;
private _stageX: number;
private _stageY: number;
private _rotation: number = 0;
private _target: Sprite = null;
private _sx: number = 0;
private _sy: number = 0;
/**
* Camera "follow" style preset: camera has no deadzone, just tracks the focus object directly.
* @type {number}
*/
public static STYLE_LOCKON: number = 0;
/**
* Camera "follow" style preset: camera deadzone is narrow but tall.
* @type {number}
*/
public static STYLE_PLATFORMER: number = 1;
/**
* Camera "follow" style preset: camera deadzone is a medium-size square around the focus object.
* @type {number}
*/
public static STYLE_TOPDOWN: number = 2;
/**
* Camera "follow" style preset: camera deadzone is a small square around the focus object.
* @type {number}
*/
public static STYLE_TOPDOWN_TIGHT: number = 3;
/**
* Identity of this camera.
*/
public ID: number;
/**
* Camera view rectangle in world coordinate.
* @type {Rectangle}
*/
public worldView: Rectangle;
/**
* How many sprites will be rendered by this camera.
* @type {number}
*/
public totalSpritesRendered: number;
/**
* Scale factor of the camera.
* @type {MicroPoint}
*/
public scale: MicroPoint = new MicroPoint(1, 1);
/**
* Scrolling factor.
* @type {MicroPoint}
*/
public scroll: MicroPoint = new MicroPoint(0, 0);
/**
* Camera bounds.
* @type {Rectangle}
*/
public bounds: Rectangle = null;
/**
* Sprite moving inside this rectangle will not cause camera moving.
* @type {Rectangle}
*/
public deadzone: Rectangle = null;
// Camera Border
public disableClipping: bool = false;
/**
* Whether render border of this camera or not. (default is false)
* @type {boolean}
*/
public showBorder: bool = false;
/**
* Color of border of this camera. (in css color string)
* @type {string}
*/
public borderColor: string = 'rgb(255,255,255)';
/**
* Whether the camera background is opaque or not. If set to true the Camera is filled with
* the value of Camera.backgroundColor every frame.
* @type {boolean}
*/
public opaque: bool = false;
/**
* Clears the camera every frame using a canvas clearRect call (default to true).
* Note that this erases anything below the camera as well, so do not use it in conjuction with a camera
* that uses alpha or that needs to be able to manage opacity. Equally if Camera.opaque is set to true
* then set Camera.clear to false to save rendering time.
* By default the Stage will clear itself every frame, so be sure not to double-up clear calls.
* @type {boolean}
*/
public clear: bool = false;
/**
* Background color in css color string.
* @type {string}
*/
private _bgColor: string = 'rgb(0,0,0)';
/**
* Background texture to be rendered if background is visible.
*/
private _bgTexture;
/**
* Background texture repeat style. (default is 'repeat')
* @type {string}
*/
private _bgTextureRepeat: string = 'repeat';
// Camera Shadow
/**
* Render camera shadow or not. (default is false)
* @type {boolean}
*/
public showShadow: bool = false;
/**
* Color of shadow, in css color string.
* @type {string}
*/
public shadowColor: string = 'rgb(0,0,0)';
/**
* Blur factor of shadow.
* @type {number}
*/
public shadowBlur: number = 10;
/**
* Offset of the shadow from camera's position.
* @type {MicroPoint}
*/
public shadowOffset: MicroPoint = new MicroPoint(4, 4);
/**
* Whether this camera visible or not. (default is true)
* @type {boolean}
*/
public visible: bool = true;
/**
* Alpha of the camera. (everything rendered to this camera will be affected)
* @type {number}
*/
public alpha: number = 1;
/**
* The x position of the current input event in world coordinates.
* @type {number}
*/
public inputX: number = 0;
/**
* The y position of the current input event in world coordinates.
* @type {number}
*/
public inputY: number = 0;
/**
* Effects manager.
* @type {FXManager}
*/
public fx: FXManager;
/**
* Tells this camera object what sprite to track.
* @param target {Sprite} The object you want the camera to track. Set to null to not follow anything.
* @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
*/
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
this._target = target;
var helper: number;
switch (style)
{
case Camera.STYLE_PLATFORMER:
var w: number = this.width / 8;
var h: number = this.height / 3;
this.deadzone = new Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
break;
case Camera.STYLE_TOPDOWN:
helper = Math.max(this.width, this.height) / 4;
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
break;
case Camera.STYLE_TOPDOWN_TIGHT:
helper = Math.max(this.width, this.height) / 8;
this.deadzone = new Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
break;
case Camera.STYLE_LOCKON:
default:
this.deadzone = null;
break;
}
}
/**
* Move the camera focus to this location instantly.
* @param x {number} X position.
* @param y {number} Y position.
*/
public focusOnXY(x: number, y: number) {
x += (x > 0) ? 0.0000001 : -0.0000001;
y += (y > 0) ? 0.0000001 : -0.0000001;
this.scroll.x = Math.round(x - this.worldView.halfWidth);
this.scroll.y = Math.round(y - this.worldView.halfHeight);
}
/**
* Move the camera focus to this location instantly.
* @param point {any} Point you want to focus.
*/
public focusOn(point) {
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
this.scroll.x = Math.round(point.x - this.worldView.halfWidth);
this.scroll.y = Math.round(point.y - this.worldView.halfHeight);
}
/**
* Specify the boundaries of the world or where the camera is allowed to move.
*
* @param x {number} The smallest X value of your world (usually 0).
* @param y {number} The smallest Y value of your world (usually 0).
* @param width {number} The largest X value of your world (usually the world width).
* @param height {number} The largest Y value of your world (usually the world height).
*/
public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
if (this.bounds == null)
{
this.bounds = new Rectangle();
}
this.bounds.setTo(x, y, width, height);
this.scroll.setTo(0, 0);
this.update();
}
/**
* Update focusing and scrolling.
*/
public update() {
this.fx.preUpdate();
if (this._target !== null)
{
if (this.deadzone == null)
{
this.focusOnXY(this._target.x, this._target.y);
}
else
{
var edge: number;
var targetX: number = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
var targetY: number = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
edge = targetX - this.deadzone.x;
if (this.scroll.x > edge)
{
this.scroll.x = edge;
}
edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
if (this.scroll.x < edge)
{
this.scroll.x = edge;
}
edge = targetY - this.deadzone.y;
if (this.scroll.y > edge)
{
this.scroll.y = edge;
}
edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
if (this.scroll.y < edge)
{
this.scroll.y = edge;
}
}
}
// Make sure we didn't go outside the cameras bounds
if (this.bounds !== null)
{
if (this.scroll.x < this.bounds.left)
{
this.scroll.x = this.bounds.left;
}
if (this.scroll.x > this.bounds.right - this.width)
{
this.scroll.x = (this.bounds.right - this.width) + 1;
}
if (this.scroll.y < this.bounds.top)
{
this.scroll.y = this.bounds.top;
}
if (this.scroll.y > this.bounds.bottom - this.height)
{
this.scroll.y = (this.bounds.bottom - this.height) + 1;
}
}
this.worldView.x = this.scroll.x;
this.worldView.y = this.scroll.y;
// Input values
this.inputX = this.worldView.x + this._game.input.x;
this.inputY = this.worldView.y + this._game.input.y;
this.fx.postUpdate();
}
/**
* Draw background, shadow, effects, and objects if this is visible.
*/
public render() {
if (this.visible === false || this.alpha < 0.1)
{
return;
}
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.save();
}
// It may be safer/quicker to just save the context every frame regardless (needs testing on mobile - sucked on Android 2.x)
//this._game.stage.context.save();
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
if (this.alpha !== 1)
{
this._game.stage.context.globalAlpha = this.alpha;
}
this._sx = this._stageX;
this._sy = this._stageY;
// Shadow
if (this.showShadow == true)
{
this._game.stage.context.shadowColor = this.shadowColor;
this._game.stage.context.shadowBlur = this.shadowBlur;
this._game.stage.context.shadowOffsetX = this.shadowOffset.x;
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
}
// Scale on
if (this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.scale(this.scale.x, this.scale.y);
this._sx = this._sx / this.scale.x;
this._sy = this._sy / this.scale.y;
}
// Rotation - translate to the mid-point of the camera
if (this._rotation !== 0)
{
this._game.stage.context.translate(this._sx + this.worldView.halfWidth, this._sy + this.worldView.halfHeight);
this._game.stage.context.rotate(this._rotation * (Math.PI / 180));
// now shift back to where that should actually render
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
}
if (this.clear == true)
{
this._game.stage.context.clearRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
}
// Background
if (this.opaque == true)
{
if (this._bgTexture)
{
this._game.stage.context.fillStyle = this._bgTexture;
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
}
else
{
this._game.stage.context.fillStyle = this._bgColor;
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
}
}
// Shadow off
if (this.showShadow == true)
{
this._game.stage.context.shadowBlur = 0;
this._game.stage.context.shadowOffsetX = 0;
this._game.stage.context.shadowOffsetY = 0;
}
this.fx.render(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
// Clip the camera so we don't get sprites appearing outside the edges
if (this._clip == true && this.disableClipping == false)
{
this._game.stage.context.beginPath();
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
this._game.stage.context.closePath();
this._game.stage.context.clip();
}
this._game.world.group.render(this, this._sx, this._sy);
if (this.showBorder == true)
{
this._game.stage.context.strokeStyle = this.borderColor;
this._game.stage.context.lineWidth = 1;
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
this._game.stage.context.stroke();
}
// Scale off
if (this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.scale(1, 1);
}
this.fx.postRender(this, this._sx, this._sy, this.worldView.width, this.worldView.height);
if (this._rotation !== 0 || (this._clip && this.disableClipping == false))
{
this._game.stage.context.translate(0, 0);
}
if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
{
this._game.stage.context.restore();
}
if (this.alpha !== 1)
{
this._game.stage.context.globalAlpha = 1;
}
}
public set backgroundColor(color: string) {
this._bgColor = color;
}
public get backgroundColor(): string {
return this._bgColor;
}
/**
* Set camera background texture.
* @param key {string} Asset key of the texture.
* @param [repeat] {string} what kind of repeat will this texture used for background.
*/
public setTexture(key: string, repeat?: string = 'repeat') {
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
this._bgTextureRepeat = repeat;
}
/**
* Set position of this camera.
* @param x {number} X position.
* @param y {number} Y position.
*/
public setPosition(x: number, y: number) {
this._stageX = x;
this._stageY = y;
this.checkClip();
}
/**
* Give this camera a new size.
* @param width {number} Width of new size.
* @param height {number} Height of new size.
*/
public setSize(width: number, height: number) {
this.worldView.width = width;
this.worldView.height = height;
this.checkClip();
}
/**
* Render debug infos. (including id, position, rotation, scrolling factor, bounds and some other properties)
* @param x {number} X position of the debug info to be rendered.
* @param y {number} Y position of the debug info to be rendered.
* @param [color] {number} color of the debug info to be rendered. (format is css color string)
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Camera ID: ' + this.ID + ' (' + this.worldView.width + ' x ' + this.worldView.height + ')', x, y);
this._game.stage.context.fillText('X: ' + this._stageX + ' Y: ' + this._stageY + ' Rotation: ' + this._rotation, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.scroll.x.toFixed(1) + ' World Y: ' + this.scroll.y.toFixed(1), x, y + 28);
if (this.bounds)
{
this._game.stage.context.fillText('Bounds: ' + this.bounds.width + ' x ' + this.bounds.height, x, y + 56);
}
}
public get x(): number {
return this._stageX;
}
public set x(value: number) {
this._stageX = value;
this.checkClip();
}
public get y(): number {
return this._stageY;
}
public set y(value: number) {
this._stageY = value;
this.checkClip();
}
public get width(): number {
return this.worldView.width;
}
public set width(value: number) {
if (value > this._game.stage.width)
{
value = this._game.stage.width;
}
this.worldView.width = value;
this.checkClip();
}
public get height(): number {
return this.worldView.height;
}
public set height(value: number) {
if (value > this._game.stage.height)
{
value = this._game.stage.height;
}
this.worldView.height = value;
this.checkClip();
}
public get rotation(): number {
return this._rotation;
}
public set rotation(value: number) {
this._rotation = this._game.math.wrap(value, 360, 0);
}
private checkClip() {
if (this._stageX !== 0 || this._stageY !== 0 || this.worldView.width < this._game.stage.width || this.worldView.height < this._game.stage.height)
{
this._clip = true;
}
else
{
this._clip = false;
}
}
}
}
-158
View File
@@ -1,158 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="../SoundManager.ts" />
/**
* Phaser - Sound
*
* A Sound file, used by the Game.SoundManager for playback.
*/
module Phaser {
export class Sound {
/**
* Sound constructor
* @param context {object} The AudioContext instance.
* @param gainNode {object} Gain node instance.
* @param data {object} Sound data.
* @param [volume] {number} volume of this sound when playing.
* @param [loop] {boolean} loop this sound when playing? (Default to false)
*/
constructor(context, gainNode, data, volume?: number = 1, loop?: bool = false) {
this._context = context;
this._gainNode = gainNode;
this._buffer = data;
this._volume = volume;
this.loop = loop;
// Local volume control
if (this._context !== null)
{
this._localGainNode = this._context.createGainNode();
this._localGainNode.connect(this._gainNode);
this._localGainNode.gain.value = this._volume;
}
if (this._buffer === null)
{
this.isDecoding = true;
}
else
{
this.play();
}
}
/**
* Local private reference to AudioContext.
*/
private _context;
/**
* Reference to gain node of SoundManager.
*/
private _gainNode;
/**
* GainNode of this sound.
*/
private _localGainNode;
/**
* Decoded data buffer.
*/
private _buffer;
/**
* Volume of this sound.
*/
private _volume: number;
/**
* The real sound object (buffer source).
*/
private _sound;
loop: bool = false;
duration: number;
isPlaying: bool = false;
isDecoding: bool = false;
public setDecodedBuffer(data) {
this._buffer = data;
this.isDecoding = false;
//this.play();
}
/**
* Play this sound.
*/
public play() {
if (this._buffer === null || this.isDecoding === true)
{
return;
}
this._sound = this._context.createBufferSource();
this._sound.buffer = this._buffer;
this._sound.connect(this._localGainNode);
if (this.loop)
{
this._sound.loop = true;
}
this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it
this.duration = this._sound.buffer.duration;
this.isPlaying = true;
}
/**
* Stop playing this sound.
*/
public stop() {
if (this.isPlaying === true)
{
this.isPlaying = false;
this._sound.noteOff(0);
}
}
/**
* Mute the sound.
*/
public mute() {
this._localGainNode.gain.value = 0;
}
/**
* Enable the sound.
*/
public unmute() {
this._localGainNode.gain.value = this._volume;
}
public set volume(value: number) {
this._volume = value;
this._localGainNode.gain.value = this._volume;
}
public get volume(): number {
return this._volume;
}
}
}
-330
View File
@@ -1,330 +0,0 @@
/// <reference path="../Game.ts" />
/// <reference path="easing/Back.ts" />
/// <reference path="easing/Bounce.ts" />
/// <reference path="easing/Circular.ts" />
/// <reference path="easing/Cubic.ts" />
/// <reference path="easing/Elastic.ts" />
/// <reference path="easing/Exponential.ts" />
/// <reference path="easing/Linear.ts" />
/// <reference path="easing/Quadratic.ts" />
/// <reference path="easing/Quartic.ts" />
/// <reference path="easing/Quintic.ts" />
/// <reference path="easing/Sinusoidal.ts" />
/**
* Phaser - Tween
*
* Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript and integrated into Phaser
*/
module Phaser {
export class Tween {
/**
* Tween constructor
* Create a new <code>Tween</code>.
*
* @param object {object} Target object will be affected by this tween.
* @param game {Phaser.Game} Current game instance.
*/
constructor(object, game:Phaser.Game) {
this._object = object;
this._game = game;
this._manager = this._game.tweens;
this._interpolationFunction = this._game.math.linearInterpolation;
this._easingFunction = Phaser.Easing.Linear.None;
this._chainedTweens = [];
this.onStart = new Phaser.Signal();
this.onUpdate = new Phaser.Signal();
this.onComplete = new Phaser.Signal();
}
/**
* Local private reference to game.
*/
private _game: Phaser.Game;
/**
* Manager of this tween.
* @type {Phaser.TweenManager}
*/
private _manager: Phaser.TweenManager;
/**
* Reference to the target object.
* @type {object}
*/
private _object = null;
private _pausedTime: number = 0;
/**
* Start values container.
* @type {object}
*/
private _valuesStart = {};
/**
* End values container.
* @type {object}
*/
private _valuesEnd = {};
/**
* How long this tween will perform.
* @type {number}
*/
private _duration = 1000;
private _delayTime = 0;
private _startTime = null;
/**
* Easing function which actually updating this tween.
* @type {function}
*/
private _easingFunction;
private _interpolationFunction;
/**
* Contains chained tweens.
* @type {Tweens[]}
*/
private _chainedTweens = [];
/**
* Signal to be dispatched when this tween start.
* @type {Phaser.Signal}
*/
public onStart: Phaser.Signal;
/**
* Signal to be dispatched when this tween updating.
* @type {Phaser.Signal}
*/
public onUpdate: Phaser.Signal;
/**
* Signal to be dispatched when this tween completed.
* @type {Phaser.Signal}
*/
public onComplete: Phaser.Signal;
/**
* Configure the Tween
* @param properties {object} Propertis you want to tween.
* @param [duration] {number} duration of this tween.
* @param [ease] {any} Easing function.
* @param [autoStart] {boolean} Whether this tween will start automatically or not.
* @param [delay] {number} delay before this tween will start, defaults to 0 (no delay)
* @return {Tween} Itself.
*/
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false, delay?:number = 0) {
this._duration = duration;
// If properties isn't an object this will fail, sanity check it here somehow?
this._valuesEnd = properties;
if (ease !== null)
{
this._easingFunction = ease;
}
if (delay > 0)
{
this._delayTime = delay;
}
if (autoStart === true)
{
return this.start();
}
else
{
return this;
}
}
/**
* Start to tween.
*/
public start() {
if (this._game === null || this._object === null)
{
return;
}
this._manager.add(this);
this.onStart.dispatch(this._object);
this._startTime = this._game.time.now + this._delayTime;
for (var property in this._valuesEnd)
{
// This prevents the interpolation of null values or of non-existing properties
if (this._object[property] === null || !(property in this._object))
{
throw Error('Phaser.Tween interpolation of null value of non-existing property');
continue;
}
// check if an Array was provided as property value
if (this._valuesEnd[property] instanceof Array)
{
if (this._valuesEnd[property].length === 0)
{
continue;
}
// create a local copy of the Array with the start value at the front
this._valuesEnd[property] = [this._object[property]].concat(this._valuesEnd[property]);
}
this._valuesStart[property] = this._object[property];
}
return this;
}
/**
* Stop tweening.
*/
public stop() {
if (this._manager !== null)
{
this._manager.remove(this);
}
this.onComplete.dispose();
return this;
}
public set parent(value:Phaser.Game) {
this._game = value;
this._manager = this._game.tweens;
}
public set delay(amount:number) {
this._delayTime = amount;
}
public get delay(): number {
return this._delayTime;
}
public set easing(easing) {
this._easingFunction = easing;
}
public get easing():any {
return this._easingFunction;
}
public set interpolation(interpolation) {
this._interpolationFunction = interpolation;
}
public get interpolation():any {
return this._interpolationFunction;
}
/**
* Add another chained tween, which will start automatically when the one before it completes.
* @param tween {Phaser.Tween} Tween object you want to chain with this.
* @return {Phaser.Tween} Itselfe.
*/
public chain(tween:Phaser.Tween) {
this._chainedTweens.push(tween);
return this;
}
/**
* Debug value?
*/
public debugValue;
/**
* Update tweening.
* @param time {number} Current time from game clock.
* @return {boolean} Return false if this completed and no need to update, otherwise return true.
*/
public update(time) {
if (this._game.paused == true)
{
if (this._pausedTime == 0)
{
this._pausedTime = time;
}
}
else
{
// Ok we aren't paused, but was there some time gained?
if (this._pausedTime > 0)
{
this._startTime += (time - this._pausedTime);
this._pausedTime = 0;
}
}
if (time < this._startTime)
{
return true;
}
var elapsed = (time - this._startTime) / this._duration;
elapsed = elapsed > 1 ? 1 : elapsed;
var value = this._easingFunction(elapsed);
for (var property in this._valuesStart)
{
// Add checks for object, array, numeric up front
if (this._valuesEnd[property] instanceof Array)
{
this._object[property] = this._interpolationFunction(this._valuesEnd[property], value);
}
else
{
this._object[property] = this._valuesStart[property] + (this._valuesEnd[property] - this._valuesStart[property]) * value;
}
}
this.onUpdate.dispatch(this._object, value);
if (elapsed == 1)
{
this.onComplete.dispatch(this._object);
for (var i = 0; i < this._chainedTweens.length; i++)
{
this._chainedTweens[i].start();
}
return false;
}
return true;
}
}
}
-27
View File
@@ -1,27 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Animation {
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool);
private _game;
private _parent;
private _frames;
private _frameData;
private _frameIndex;
private _timeLastFrame;
private _timeNextFrame;
public name: string;
public currentFrame: Frame;
public isFinished: bool;
public isPlaying: bool;
public looped: bool;
public delay: number;
public frameTotal : number;
public frame : number;
public play(frameRate?: number, loop?: bool): void;
public restart(): void;
public stop(): void;
public update(): bool;
public destroy(): void;
private onComplete();
}
}
-267
View File
@@ -1,267 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Animation
*
* An Animation is a single animation. It is created by the AnimationManager and belongs to Sprite objects.
*/
module Phaser {
export class Animation {
/**
* Animation constructor
* Create a new <code>Animation</code>.
*
* @param parent {Sprite} Owner sprite of this animation.
* @param frameData {FrameData} The FrameData object contains animation data.
* @param name {string} Unique name of this animation.
* @param frames {number[]/string[]} An array of numbers or strings indicating what frames to play in what order.
* @param delay {number} Time between frames in ms.
* @param looped {boolean} Whether or not the animation is looped or just plays once.
*/
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
this._game = game;
this._parent = parent;
this._frames = frames;
this._frameData = frameData;
this.name = name;
this.delay = 1000 / delay;
this.looped = looped;
this.isFinished = false;
this.isPlaying = false;
this._frameIndex = 0;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* Local private reference to its owner sprite.
* @type {Sprite}
*/
private _parent: Sprite;
/**
* Animation frame container.
* @type {number[]}
*/
private _frames: number[];
/**
* Frame data of this animation.(parsed from sprite sheet)
* @type {FrameData}
*/
private _frameData: FrameData;
/**
* Index of current frame.
* @type {number}
*/
private _frameIndex: number;
/**
* Time when switched to last frame (in ms).
* @type number
*/
private _timeLastFrame: number;
/**
* Time when this will switch to next frame (in ms).
* @type number
*/
private _timeNextFrame: number;
/**
* Name of this animation.
* @type {string}
*/
public name: string;
/**
* Currently played frame instance.
* @type {Frame}
*/
public currentFrame: Frame;
/**
* Whether or not this animation finished playing.
* @type {boolean}
*/
public isFinished: bool;
/**
* Whethor or not this animation is currently playing.
* @type {boolean}
*/
public isPlaying: bool;
/**
* Whether or not the animation is looped.
* @type {boolean}
*/
public looped: bool;
/**
* Time between frames in ms.
* @type {number}
*/
public delay: number;
public get frameTotal(): number {
return this._frames.length;
}
public get frame(): number {
if (this.currentFrame !== null)
{
return this.currentFrame.index;
}
else
{
return this._frameIndex;
}
}
public set frame(value: number) {
this.currentFrame = this._frameData.getFrame(value);
if (this.currentFrame !== null)
{
this._parent.frameBounds.width = this.currentFrame.width;
this._parent.frameBounds.height = this.currentFrame.height;
this._frameIndex = value;
}
}
/**
* Play this animation.
* @param frameRate {number} FrameRate you want to specify instead of using default.
* @param loop {boolean} Whether or not the animation is looped or just plays once.
*/
public play(frameRate?: number = null, loop?: bool) {
if (frameRate !== null)
{
this.delay = 1000 / frameRate;
}
if (loop !== undefined)
{
this.looped = loop;
}
this.isPlaying = true;
this.isFinished = false;
this._timeLastFrame = this._game.time.now;
this._timeNextFrame = this._game.time.now + this.delay;
this._frameIndex = 0;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
}
/**
* Play this animation from the first frame.
*/
public restart() {
this.isPlaying = true;
this.isFinished = false;
this._timeLastFrame = this._game.time.now;
this._timeNextFrame = this._game.time.now + this.delay;
this._frameIndex = 0;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
}
/**
* Stop playing animation and set it finished.
*/
public stop() {
this.isPlaying = false;
this.isFinished = true;
}
/**
* Update animation frames.
*/
public update(): bool {
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
{
this._frameIndex++;
if (this._frameIndex == this._frames.length)
{
if (this.looped)
{
this._frameIndex = 0;
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
}
else
{
this.onComplete();
}
}
else
{
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
}
this._timeLastFrame = this._game.time.now;
this._timeNextFrame = this._game.time.now + this.delay;
return true;
}
return false;
}
/**
* Clean up animation memory.
*/
public destroy() {
this._game = null;
this._parent = null;
this._frames = null;
this._frameData = null;
this.currentFrame = null;
this.isPlaying = false;
}
/**
* Animation complete callback method.
*/
private onComplete() {
this.isPlaying = false;
this.isFinished = true;
// callback goes here
}
}
}
-7
View File
@@ -1,7 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class AnimationLoader {
static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData;
static parseJSONData(game: Game, json): FrameData;
}
}
-139
View File
@@ -1,139 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - AnimationLoader
*
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
*/
module Phaser {
export class AnimationLoader {
/**
* Parse a sprite sheet from asset data.
* @param key {string} Asset key for the sprite sheet data.
* @param frameWidth {number} Width of animation frame.
* @param frameHeight {number} Height of animation frame.
* @param frameMax {number} Number of animation frames.
* @return {FrameData} Generated FrameData object.
*/
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
// How big is our image?
var img = game.cache.getImage(key);
if (img == null)
{
return null;
}
var width = img.width;
var height = img.height;
var row = Math.round(width / frameWidth);
var column = Math.round(height / frameHeight);
var total = row * column;
if (frameMax !== -1)
{
total = frameMax;
}
// Zero or smaller than frame sizes?
if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0)
{
return null;
}
// Let's create some frames then
var data: FrameData = new FrameData();
var x = 0;
var y = 0;
for (var i = 0; i < total; i++)
{
data.addFrame(new Frame(x, y, frameWidth, frameHeight, ''));
x += frameWidth;
if (x === width)
{
x = 0;
y += frameHeight;
}
}
return data;
}
/**
* Parse frame datas from json.
* @param json {object} Json data you want to parse.
* @return {FrameData} Generated FrameData object.
*/
public static parseJSONData(game: Game, json): FrameData {
// Malformed?
if (!json['frames'])
{
throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
}
// Let's create some frames then
var data: FrameData = new FrameData();
// By this stage frames is a fully parsed array
var frames = json;
var newFrame: Frame;
for (var i = 0; i < frames.length; i++)
{
newFrame = data.addFrame(new Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
}
return data;
}
public static parseXMLData(game: Game, xml, format: number): FrameData {
// Malformed?
if (!xml.getElementsByTagName('TextureAtlas'))
{
throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
}
// Let's create some frames then
var data: FrameData = new FrameData();
var frames = xml.getElementsByTagName('SubTexture');
var newFrame: Frame;
for (var i = 0; i < frames.length; i++)
{
var frame = frames[i].attributes;
newFrame = data.addFrame(new Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
// Trimmed?
if (frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0')
{
newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
}
}
return data;
}
}
}
-23
View File
@@ -1,23 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Frame {
constructor(x: number, y: number, width: number, height: number, name: string);
public x: number;
public y: number;
public width: number;
public height: number;
public index: number;
public name: string;
public rotated: bool;
public rotationDirection: string;
public trimmed: bool;
public sourceSizeW: number;
public sourceSizeH: number;
public spriteSourceSizeX: number;
public spriteSourceSizeY: number;
public spriteSourceSizeW: number;
public spriteSourceSizeH: number;
public setRotation(rotated: bool, rotationDirection: string): void;
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight): void;
}
}
-157
View File
@@ -1,157 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Frame
*
* A Frame is a single frame of an animation and is part of a FrameData collection.
*/
module Phaser {
export class Frame {
/**
* Frame constructor
* Create a new <code>Frame</code> with specific position, size and name.
*
* @param x {number} X position within the image to cut from.
* @param y {number} Y position within the image to cut from.
* @param width {number} Width of the frame.
* @param height {number} Height of the frame.
* @param name {string} Name of this frame.
*/
constructor(x: number, y: number, width: number, height: number, name: string) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.name = name;
this.rotated = false;
this.trimmed = false;
}
/**
* X position within the image to cut from.
* @type {number}
*/
public x: number;
/**
* Y position within the image to cut from.
* @type {number}
*/
public y: number;
/**
* Width of the frame.
* @type {number}
*/
public width: number;
/**
* Height of the frame.
* @type {number}
*/
public height: number;
/**
* Useful for Sprite Sheets.
* @type {number}
*/
public index: number;
/**
* Useful for Texture Atlas files. (is set to the filename value)
*/
public name: string = '';
/**
* Rotated? (not yet implemented)
*/
public rotated: bool = false;
/**
* Either cw or ccw, rotation is always 90 degrees.
*/
public rotationDirection: string = 'cw';
/**
* Was it trimmed when packed?
* @type {boolean}
*/
public trimmed: bool;
// The coordinates of the trimmed sprite inside the original sprite
/**
* Width of the original sprite.
* @type {number}
*/
public sourceSizeW: number;
/**
* Height of the original sprite.
* @type {number}
*/
public sourceSizeH: number;
/**
* X position of the trimmed sprite inside original sprite.
* @type {number}
*/
public spriteSourceSizeX: number;
/**
* Y position of the trimmed sprite inside original sprite.
* @type {number}
*/
public spriteSourceSizeY: number;
/**
* Width of the trimmed sprite.
* @type {number}
*/
public spriteSourceSizeW: number;
/**
* Height of the trimmed sprite.
* @type {number}
*/
public spriteSourceSizeH: number;
/**
* Set rotation of this frame. (Not yet supported!)
*/
public setRotation(rotated: bool, rotationDirection: string) {
// Not yet supported
}
/**
* Set trim of the frame.
* @param trimmed {boolean} Whether this frame trimmed or not.
* @param actualWidth {number} Actual width of this frame.
* @param actualHeight {number} Actual height of this frame.
* @param destX {number} Destiny x position.
* @param destY {number} Destiny y position.
* @param destWidth {number} Destiny draw width.
* @param destHeight {number} Destiny draw height.
*/
public setTrim(trimmed: bool, actualWidth: number, actualHeight: number, destX: number, destY: number, destWidth: number, destHeight: number) {
this.trimmed = trimmed;
this.sourceSizeW = actualWidth;
this.sourceSizeH = actualHeight;
this.spriteSourceSizeX = destX;
this.spriteSourceSizeY = destY;
this.spriteSourceSizeW = destWidth;
this.spriteSourceSizeH = destHeight;
}
}
}
-18
View File
@@ -1,18 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class FrameData {
constructor();
private _frames;
private _frameNames;
public total : number;
public addFrame(frame: Frame): Frame;
public getFrame(index: number): Frame;
public getFrameByName(name: string): Frame;
public checkFrameName(name: string): bool;
public getFrameRange(start: number, end: number, output?: Frame[]): Frame[];
public getFrameIndexes(output?: number[]): number[];
public getFrameIndexesByName(input: string[]): number[];
public getAllFrames(): Frame[];
public getFrames(range: number[]): Frame[];
}
}
-189
View File
@@ -1,189 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - FrameData
*
* FrameData is a container for Frame objects, the internal representation of animation data in Phaser.
*/
module Phaser {
export class FrameData {
/**
* FrameData constructor
*/
constructor() {
this._frames = [];
this._frameNames = [];
}
/**
* Local frame container.
*/
private _frames: Frame[];
/**
* Local frameName<->index container.
*/
private _frameNames;
public get total(): number {
return this._frames.length;
}
/**
* Add a new frame.
* @param frame {Frame} The frame you want to add.
* @return {Frame} The frame you just added.
*/
public addFrame(frame: Frame): Frame {
frame.index = this._frames.length;
this._frames.push(frame);
if (frame.name !== '')
{
this._frameNames[frame.name] = frame.index;
}
return frame;
}
/**
* Get a frame by its index.
* @param index {number} Index of the frame you want to get.
* @return {Frame} The frame you want.
*/
public getFrame(index: number): Frame {
if (this._frames[index])
{
return this._frames[index];
}
return null;
}
/**
* Get a frame by its name.
* @param name {string} Name of the frame you want to get.
* @return {Frame} The frame you want.
*/
public getFrameByName(name: string): Frame {
if (this._frameNames[name] >= 0)
{
return this._frames[this._frameNames[name]];
}
return null;
}
/**
* Check whether there's a frame with given name.
* @param name {string} Name of the frame you want to check.
* @return {boolean} True if frame with given name found, otherwise return false.
*/
public checkFrameName(name: string): bool {
if (this._frameNames[name] >= 0)
{
return true;
}
return false;
}
/**
* Get ranges of frames in an array.
* @param start {number} Start index of frames you want.
* @param end {number} End index of frames you want.
* @param [output] {Frame[]} result will be added into this array.
* @return {Frame[]} Ranges of specific frames in an array.
*/
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
for (var i = start; i <= end; i++)
{
output.push(this._frames[i]);
}
return output;
}
/**
* Get all indexes of frames by giving their name.
* @param [output] {number[]} result will be added into this array.
* @return {number[]} Indexes of specific frames in an array.
*/
public getFrameIndexes(output?: number[] = []): number[] {
output.length = 0;
for (var i = 0; i < this._frames.length; i++)
{
output.push(i);
}
return output;
}
/**
* Get all names of frames by giving their indexes.
* @param [output] {number[]} result will be added into this array.
* @return {number[]} Names of specific frames in an array.
*/
public getFrameIndexesByName(input: string[]): number[] {
var output: number[] = [];
for (var i = 0; i < input.length; i++)
{
if (this.getFrameByName(input[i]))
{
output.push(this.getFrameByName(input[i]).index);
}
}
return output;
}
/**
* Get all frames in this frame data.
* @return {Frame[]} All the frames in an array.
*/
public getAllFrames(): Frame[] {
return this._frames;
}
/**
* Get All frames with specific ranges.
* @param range {number[]} Ranges in an array.
* @return {Frame[]} All frames in an array.
*/
public getFrames(range: number[]) {
var output: Frame[] = [];
for (var i = 0; i < range.length; i++)
{
output.push(this._frames[i]);
}
return output;
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Back {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-37
View File
@@ -1,37 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Back
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Back {
public static In(k) {
var s = 1.70158;
return k * k * ((s + 1) * k - s);
}
public static Out(k) {
var s = 1.70158;
return --k * k * ((s + 1) * k + s) + 1;
}
public static InOut(k) {
var s = 1.70158 * 1.525;
if ((k *= 2) < 1) return 0.5 * (k * k * ((s + 1) * k - s));
return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Bounce {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-49
View File
@@ -1,49 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Bounce
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Bounce {
public static In(k) {
return 1 - Phaser.Easing.Bounce.Out(1 - k);
}
public static Out(k) {
if (k < (1 / 2.75))
{
return 7.5625 * k * k;
}
else if (k < (2 / 2.75))
{
return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
}
else if (k < (2.5 / 2.75))
{
return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
}
else
{
return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
}
}
public static InOut(k) {
if (k < 0.5) return Phaser.Easing.Bounce.In(k * 2) * 0.5;
return Phaser.Easing.Bounce.Out(k * 2 - 1) * 0.5 + 0.5;
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Circular {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-34
View File
@@ -1,34 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Circular
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Circular {
public static In(k) {
return 1 - Math.sqrt(1 - k * k);
}
public static Out(k) {
return Math.sqrt(1 - (--k * k));
}
public static InOut(k) {
if ((k *= 2) < 1) return -0.5 * (Math.sqrt(1 - k * k) - 1);
return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Cubic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-34
View File
@@ -1,34 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Cubic
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Cubic {
public static In(k) {
return k * k * k;
}
public static Out(k) {
return --k * k * k + 1;
}
public static InOut(k) {
if ((k *= 2) < 1) return 0.5 * k * k * k;
return 0.5 * ((k -= 2) * k * k + 2);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Elastic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-49
View File
@@ -1,49 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Elastic
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Elastic {
public static In(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
}
public static Out(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
return (a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
}
public static InOut(k) {
var s, a = 0.1, p = 0.4;
if (k === 0) return 0;
if (k === 1) return 1;
if (!a || a < 1) { a = 1; s = p / 4; }
else s = p * Math.asin(1 / a) / (2 * Math.PI);
if ((k *= 2) < 1) return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Exponential {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-36
View File
@@ -1,36 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Exponential
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Exponential {
public static In(k) {
return k === 0 ? 0 : Math.pow(1024, k - 1);
}
public static Out(k) {
return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
}
public static InOut(k) {
if (k === 0) return 0;
if (k === 1) return 1;
if ((k *= 2) < 1) return 0.5 * Math.pow(1024, k - 1);
return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
}
}
}
-6
View File
@@ -1,6 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Linear {
static None(k);
}
}
-21
View File
@@ -1,21 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Linear
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Linear {
public static None(k) {
return k;
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quadratic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-34
View File
@@ -1,34 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Quadratic
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Quadratic {
public static In(k) {
return k * k;
}
public static Out(k) {
return k * (2 - k);
}
public static InOut(k) {
if ((k *= 2) < 1) return 0.5 * k * k;
return -0.5 * (--k * (k - 2) - 1);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quartic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-34
View File
@@ -1,34 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Quartic
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Quartic {
public static In(k) {
return k * k * k * k;
}
public static Out(k) {
return 1 - (--k * k * k * k);
}
public static InOut(k) {
if ((k *= 2) < 1) return 0.5 * k * k * k * k;
return -0.5 * ((k -= 2) * k * k * k - 2);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quintic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-34
View File
@@ -1,34 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Quintic
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Quintic {
public static In(k) {
return k * k * k * k * k;
}
public static Out(k) {
return --k * k * k * k * k + 1;
}
public static InOut(k) {
if ((k *= 2) < 1) return 0.5 * k * k * k * k * k;
return 0.5 * ((k -= 2) * k * k * k * k + 2);
}
}
}
-8
View File
@@ -1,8 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Sinusoidal {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
-33
View File
@@ -1,33 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Easing - Sinusoidal
*
* For use with Phaser.Tween
*/
module Phaser.Easing {
export class Sinusoidal {
public static In(k) {
return 1 - Math.cos(k * Math.PI / 2);
}
public static Out(k) {
return Math.sin(k * Math.PI / 2);
}
public static InOut(k) {
return 0.5 * (1 - Math.cos(Math.PI * k));
}
}
}
-35
View File
@@ -1,35 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Finger {
constructor(game: Game);
private _game;
public identifier: number;
public active: bool;
public point: Point;
public circle: Circle;
public withinGame: bool;
public clientX: number;
public clientY: number;
public pageX: number;
public pageY: number;
public screenX: number;
public screenY: number;
public x: number;
public y: number;
public target;
public isDown: bool;
public isUp: bool;
public timeDown: number;
public duration: number;
public timeUp: number;
public justPressedRate: number;
public justReleasedRate: number;
public start(event): void;
public move(event): void;
public leave(event): void;
public stop(event): void;
public justPressed(duration?: number): bool;
public justReleased(duration?: number): bool;
public toString(): string;
}
}
-63
View File
@@ -1,63 +0,0 @@
/// <reference path="../../Game.ts" />
/// <reference path="Pointer.ts" />
/**
* Phaser - Gestures
*
* The Gesture class monitors for gestures and dispatches the resulting signals when they occur.
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
*/
module Phaser {
export class Gestures {
/**
* Constructor
* @param {Game} game.
* @return {Touch} This object.
*/
constructor(game: Game) {
this._game = game;
}
/**
* Local private reference to game.
* @property _game
* @type {Game}
* @private
**/
private _game: Game;
private _p1: Pointer;
private _p2: Pointer;
private _p3: Pointer;
private _p4: Pointer;
private _p5: Pointer;
private _p6: Pointer;
private _p7: Pointer;
private _p8: Pointer;
private _p9: Pointer;
private _p10: Pointer;
public start() {
// Local references to the Phaser.Input.pointer objects
this._p1 = this._game.input.pointer1;
this._p2 = this._game.input.pointer2;
this._p3 = this._game.input.pointer3;
this._p4 = this._game.input.pointer4;
this._p5 = this._game.input.pointer5;
this._p6 = this._game.input.pointer6;
this._p7 = this._game.input.pointer7;
this._p8 = this._game.input.pointer8;
this._p9 = this._game.input.pointer9;
this._p10 = this._game.input.pointer10;
}
}
}
-24
View File
@@ -1,24 +0,0 @@
/// <reference path="../../Game.d.ts" />
/// <reference path="../../Signal.d.ts" />
module Phaser {
class Input {
constructor(game: Game);
private _game;
public mouse: Mouse;
public keyboard: Keyboard;
public touch: Touch;
public x: number;
public y: number;
public scaleX: number;
public scaleY: number;
public worldX: number;
public worldY: number;
public onDown: Signal;
public onUp: Signal;
public update(): void;
public reset(): void;
public getWorldX(camera?: Camera): number;
public getWorldY(camera?: Camera): number;
public renderDebugInfo(x: number, y: number, color?: string): void;
}
}
-873
View File
@@ -1,873 +0,0 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../Signal.ts" />
/// <reference path="Pointer.ts" />
/// <reference path="MSPointer.ts" />
/// <reference path="Gestures.ts" />
/**
* Phaser - Input
*
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
* This is updated by the core game loop.
*/
module Phaser {
export class Input {
constructor(game: Game) {
this._game = game;
this.mousePointer = new Pointer(this._game, 0);
this.pointer1 = new Pointer(this._game, 1);
this.pointer2 = new Pointer(this._game, 2);
this.pointer3 = new Pointer(this._game, 3);
this.pointer4 = new Pointer(this._game, 4);
this.pointer5 = new Pointer(this._game, 5);
this.mouse = new Mouse(this._game);
this.keyboard = new Keyboard(this._game);
this.touch = new Touch(this._game);
this.mspointer = new MSPointer(this._game);
this.gestures = new Gestures(this._game);
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal();
this.position = new Vector2;
this.circle = new Circle(0, 0, 44);
this.currentPointers = 0;
}
/**
* Local private reference to game.
*/
private _game: Game;
/**
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
* @type {Boolean}
*/
public disabled: bool = false;
/**
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
*/
public multiInputOverride: number = Input.MOUSE_TOUCH_COMBINE;
/**
* Static defining the behaviour expected on a multi-input device system.
* With this setting when the mouse is used it updates the Input.x/y globals regardless if another pointer is active or not
*/
public static MOUSE_OVERRIDES_TOUCH: number = 0;
/**
* Static defining the behaviour expected on a multi-input device system.
* With this setting when the mouse is used it only updates the Input.x/y globals if no other pointer is active
*/
public static TOUCH_OVERRIDES_MOUSE: number = 1;
/**
* Static defining the behaviour expected on a multi-input device system.
* With this setting when the mouse is used it updates the Input.x/y globals at the same time as any active Pointer objects might
*/
public static MOUSE_TOUCH_COMBINE: number = 2;
/**
* Phaser.Mouse handler
* @type {Mouse}
*/
public mouse: Mouse;
/**
* Phaser.Keyboard handler
* @type {Keyboard}
*/
public keyboard: Keyboard;
/**
* Phaser.Touch handler
* @type {Touch}
*/
public touch: Touch;
/**
* Phaser.MSPointer handler
* @type {MSPointer}
*/
public mspointer: MSPointer;
/**
* Phaser.Gestures handler
* @type {Gestures}
*/
public gestures: Gestures;
/**
* A vector object representing the current position of the Pointer.
* @property vector
* @type {Vector2}
**/
public position: Vector2 = null;
/**
* A Circle object centered on the x/y screen coordinates of the Input.
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything
* @property circle
* @type {Circle}
**/
public circle: Circle = null;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _x: number = 0;
/**
* X coordinate of the most recent Pointer event
* @type {Number}
* @private
*/
private _y: number = 0;
/**
*
* @type {Number}
*/
public scaleX: number = 1;
/**
*
* @type {Number}
*/
public scaleY: number = 1;
/**
* The maximum number of Pointers allowed to be active at any one time.
* For lots of games it's useful to set this to 1
* @type {Number}
*/
public maxPointers: number = 10;
/**
* The current number of active Pointers.
* @type {Number}
*/
public currentPointers: number = 0;
/**
* A Signal dispatched when a mouse/Pointer object is pressed
* @type {Phaser.Signal}
*/
public onDown: Phaser.Signal;
/**
* A Signal dispatched when a mouse/Pointer object is released
* @type {Phaser.Signal}
*/
public onUp: Phaser.Signal;
/**
* A Signal dispatched when a Pointer object (including the mouse) is tapped: pressed and released quickly.
* The signal sends 2 parameters. The Pointer that caused it and a boolean depending if the tap was a single tap or a double tap.
* @type {Phaser.Signal}
*/
public onTap: Phaser.Signal;
/**
* A Signal dispatched when a Pointer object (including the mouse) is held down
* @type {Phaser.Signal}
*/
public onHold: Phaser.Signal;
/**
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
* @property tapRate
* @type {Number}
**/
public tapRate: number = 200;
/**
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
* @property doubleTapRate
* @type {Number}
**/
public doubleTapRate: number = 300;
/**
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
* @property holdRate
* @type {Number}
**/
public holdRate: number = 2000;
/**
* The number of milliseconds below which the Pointer is considered justPressed
* @property justPressedRate
* @type {Number}
**/
public justPressedRate: number = 200;
/**
* The number of milliseconds below which the Pointer is considered justReleased
* @property justReleasedRate
* @type {Number}
**/
public justReleasedRate: number = 200;
/**
* Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
* The history is cleared each time the Pointer is pressed down.
* The history is updated at the rate specified in Input.pollRate
* @property recordPointerHistory
* @type {Boolean}
**/
public recordPointerHistory: bool = true;
/**
* The rate in milliseconds at which the Pointer objects should update their tracking history
* @property recordRate
* @type {Number}
*/
public recordRate: number = 100;
/**
* The total number of entries that can be recorded into the Pointer objects tracking history.
* The the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
* @property recordLimit
* @type {Number}
*/
public recordLimit: number = 100;
/**
* A Pointer object specifically used by the Mouse
* @property mousePointer
* @type {Pointer}
**/
public mousePointer: Pointer;
/**
* A Pointer object
* @property pointer1
* @type {Pointer}
**/
public pointer1: Pointer;
/**
* A Pointer object
* @property pointer2
* @type {Pointer}
**/
public pointer2: Pointer;
/**
* A Pointer object
* @property pointer3
* @type {Pointer}
**/
public pointer3: Pointer;
/**
* A Pointer object
* @property pointer4
* @type {Pointer}
**/
public pointer4: Pointer;
/**
* A Pointer object
* @property pointer5
* @type {Pointer}
**/
public pointer5: Pointer;
/**
* A Pointer object
* @property pointer6
* @type {Pointer}
**/
public pointer6: Pointer = null;
/**
* A Pointer object
* @property pointer7
* @type {Pointer}
**/
public pointer7: Pointer = null;
/**
* A Pointer object
* @property pointer8
* @type {Pointer}
**/
public pointer8: Pointer = null;
/**
* A Pointer object
* @property pointer9
* @type {Pointer}
**/
public pointer9: Pointer = null;
/**
* A Pointer object
* @property pointer10
* @type {Pointer}
**/
public pointer10: Pointer = null;
/**
* The screen X coordinate
* @property x
* @type {Number}
**/
public get x(): number {
return this._x;
}
public set x(value: number) {
this._x = Math.round(value);
}
/**
* The screen Y coordinate
* @property y
* @type {Number}
**/
public get y(): number {
return this._y;
}
public set y(value: number) {
this._y = Math.round(value);
}
/**
* Add a new Pointer object to the Input Manager. By default Input creates 5 pointer objects for you. If you need more
* use this to create a new one, up to a maximum of 10.
* @method addPointer
* @return {Pointer} A reference to the new Pointer object
**/
public addPointer(): Pointer {
var next: number = 0;
if (this.pointer10 === null)
{
next = 10;
}
if (this.pointer9 === null)
{
next = 9;
}
if (this.pointer8 === null)
{
next = 8;
}
if (this.pointer7 === null)
{
next = 7;
}
if (this.pointer6 === null)
{
next = 6;
}
if (next == 0)
{
throw new Error("You can only have 10 Pointer objects");
return null;
}
else
{
this['pointer' + next] = new Pointer(this._game, next);
return this['pointer' + next];
}
}
/**
* Starts the Input Manager running
* @method start
**/
public start() {
this.mouse.start();
this.keyboard.start();
this.touch.start();
this.mspointer.start();
this.gestures.start();
}
/**
* Updates the Input Manager. Called by the core Game loop.
* @method update
**/
public update() {
this.mousePointer.update();
this.pointer1.update();
this.pointer2.update();
this.pointer3.update();
this.pointer4.update();
this.pointer5.update();
if (this.pointer6) { this.pointer6.update(); }
if (this.pointer7) { this.pointer7.update(); }
if (this.pointer8) { this.pointer8.update(); }
if (this.pointer9) { this.pointer9.update(); }
if (this.pointer10) { this.pointer10.update(); }
}
/**
* Reset all of the Pointers and Input states
* @method reset
* @param hard {Boolean} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
**/
public reset(hard?: bool = false) {
this.keyboard.reset();
this.pointer1.reset();
this.pointer2.reset();
this.pointer3.reset();
this.pointer4.reset();
this.pointer5.reset();
if (this.pointer6) { this.pointer6.reset(); }
if (this.pointer7) { this.pointer7.reset(); }
if (this.pointer8) { this.pointer8.reset(); }
if (this.pointer9) { this.pointer9.reset(); }
if (this.pointer10) { this.pointer10.reset(); }
this.currentPointers = 0;
if (hard == true)
{
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal();
}
}
/**
* Get the total number of inactive Pointers
* @method totalInactivePointers
* @return {Number} The number of Pointers currently inactive
**/
public get totalInactivePointers(): number {
return 10 - this.currentPointers;
}
/**
* Recalculates the total number of active Pointers
* @method totalActivePointers
* @return {Number} The number of Pointers currently active
**/
public get totalActivePointers(): number {
this.currentPointers = 0;
if (this.pointer1.active == true)
{
this.currentPointers++;
}
else if (this.pointer2.active == true)
{
this.currentPointers++;
}
else if (this.pointer3.active == true)
{
this.currentPointers++;
}
else if (this.pointer4.active == true)
{
this.currentPointers++;
}
else if (this.pointer5.active == true)
{
this.currentPointers++;
}
else if (this.pointer6 && this.pointer6.active == true)
{
this.currentPointers++;
}
else if (this.pointer7 && this.pointer7.active == true)
{
this.currentPointers++;
}
else if (this.pointer8 && this.pointer8.active == true)
{
this.currentPointers++;
}
else if (this.pointer9 && this.pointer9.active == true)
{
this.currentPointers++;
}
else if (this.pointer10 && this.pointer10.active == true)
{
this.currentPointers++;
}
return this.currentPointers;
}
/**
* Find the first free Pointer object and start it, passing in the event data.
* @method startPointer
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available
**/
public startPointer(event):Pointer {
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
{
return null;
}
// Unrolled for speed
if (this.pointer1.active == false)
{
return this.pointer1.start(event);
}
else if (this.pointer2.active == false)
{
return this.pointer2.start(event);
}
else if (this.pointer3.active == false)
{
return this.pointer3.start(event);
}
else if (this.pointer4.active == false)
{
return this.pointer4.start(event);
}
else if (this.pointer5.active == false)
{
return this.pointer5.start(event);
}
else if (this.pointer6 && this.pointer6.active == false)
{
return this.pointer6.start(event);
}
else if (this.pointer7 && this.pointer7.active == false)
{
return this.pointer7.start(event);
}
else if (this.pointer8 && this.pointer8.active == false)
{
return this.pointer8.start(event);
}
else if (this.pointer9 && this.pointer9.active == false)
{
return this.pointer9.start(event);
}
else if (this.pointer10 && this.pointer10.active == false)
{
return this.pointer10.start(event);
}
return null;
}
/**
* Updates the matching Pointer object, passing in the event data.
* @method updatePointer
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
**/
public updatePointer(event):Pointer {
// Unrolled for speed
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
{
return this.pointer1.move(event);
}
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
{
return this.pointer2.move(event);
}
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
{
return this.pointer3.move(event);
}
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
{
return this.pointer4.move(event);
}
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
{
return this.pointer5.move(event);
}
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
{
return this.pointer6.move(event);
}
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
{
return this.pointer7.move(event);
}
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
{
return this.pointer8.move(event);
}
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
{
return this.pointer9.move(event);
}
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
{
return this.pointer10.move(event);
}
return null;
}
/**
* Stops the matching Pointer object, passing in the event data.
* @method stopPointer
* @param {Any} event The event data from the Touch event
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
**/
public stopPointer(event):Pointer {
// Unrolled for speed
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
{
return this.pointer1.stop(event);
}
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
{
return this.pointer2.stop(event);
}
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
{
return this.pointer3.stop(event);
}
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
{
return this.pointer4.stop(event);
}
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
{
return this.pointer5.stop(event);
}
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
{
return this.pointer6.stop(event);
}
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
{
return this.pointer7.stop(event);
}
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
{
return this.pointer8.stop(event);
}
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
{
return this.pointer9.stop(event);
}
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
{
return this.pointer10.stop(event);
}
return null;
}
/**
* Get the next Pointer object whos active property matches the given state
* @method getPointer
* @param {Boolean} state The state the Pointer should be in (false for inactive, true for active)
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
**/
public getPointer(state: bool = false): Pointer {
// Unrolled for speed
if (this.pointer1.active == state)
{
return this.pointer1;
}
else if (this.pointer2.active == state)
{
return this.pointer2;
}
else if (this.pointer3.active == state)
{
return this.pointer3;
}
else if (this.pointer4.active == state)
{
return this.pointer4;
}
else if (this.pointer5.active == state)
{
return this.pointer5;
}
else if (this.pointer6 && this.pointer6.active == state)
{
return this.pointer6;
}
else if (this.pointer7 && this.pointer7.active == state)
{
return this.pointer7;
}
else if (this.pointer8 && this.pointer8.active == state)
{
return this.pointer8;
}
else if (this.pointer9 && this.pointer9.active == state)
{
return this.pointer9;
}
else if (this.pointer10 && this.pointer10.active == state)
{
return this.pointer10;
}
return null;
}
/**
* Get the Pointer object whos identified property matches the given identifier value
* @method getPointerFromIdentifier
* @param {Number} identifier The Pointer.identifier value to search for
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
**/
public getPointerFromIdentifier(identifier: number): Pointer {
// Unrolled for speed
if (this.pointer1.identifier == identifier)
{
return this.pointer1;
}
else if (this.pointer2.identifier == identifier)
{
return this.pointer2;
}
else if (this.pointer3.identifier == identifier)
{
return this.pointer3;
}
else if (this.pointer4.identifier == identifier)
{
return this.pointer4;
}
else if (this.pointer5.identifier == identifier)
{
return this.pointer5;
}
else if (this.pointer6 && this.pointer6.identifier == identifier)
{
return this.pointer6;
}
else if (this.pointer7 && this.pointer7.identifier == identifier)
{
return this.pointer7;
}
else if (this.pointer8 && this.pointer8.identifier == identifier)
{
return this.pointer8;
}
else if (this.pointer9 && this.pointer9.identifier == identifier)
{
return this.pointer9;
}
else if (this.pointer10 && this.pointer10.identifier == identifier)
{
return this.pointer10;
}
return null;
}
/**
* @param {Camera} [camera]
*/
public getWorldX(camera?: Camera = this._game.camera) {
return camera.worldView.x + this.x;
}
/**
* @param {Camera} [camera]
*/
public getWorldY(camera?: Camera = this._game.camera) {
return camera.worldView.y + this.y;
}
/**
* @param {Number} x
* @param {Number} y
* @param {String} [color]
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.font = '14px Courier';
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y);
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
this._game.stage.context.fillText('World X: ' + this.getWorldX() + ' World Y: ' + this.getWorldY(), x, y + 28);
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
}
/**
* Get the distance between two Pointer objects
* @method getDistance
* @param {Pointer} pointer1
* @param {Pointer} pointer2
**/
public getDistance(pointer1: Pointer, pointer2: Pointer): number {
return pointer1.position.distance(pointer2.position);
}
/**
* Get the angle between two Pointer objects
* @method getAngle
* @param {Pointer} pointer1
* @param {Pointer} pointer2
**/
public getAngle(pointer1: Pointer, pointer2: Pointer): number {
return pointer1.position.angle(pointer2.position);
}
}
}
-117
View File
@@ -1,117 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Keyboard {
constructor(game: Game);
private _game;
private _keys;
private _capture;
public start(): void;
public addKeyCapture(keycode): void;
public removeKeyCapture(keycode: number): void;
public clearCaptures(): void;
public onKeyDown(event: KeyboardEvent): void;
public onKeyUp(event: KeyboardEvent): void;
public reset(): void;
public justPressed(keycode: number, duration?: number): bool;
public justReleased(keycode: number, duration?: number): bool;
public isDown(keycode: number): bool;
static A: number;
static B: number;
static C: number;
static D: number;
static E: number;
static F: number;
static G: number;
static H: number;
static I: number;
static J: number;
static K: number;
static L: number;
static M: number;
static N: number;
static O: number;
static P: number;
static Q: number;
static R: number;
static S: number;
static T: number;
static U: number;
static V: number;
static W: number;
static X: number;
static Y: number;
static Z: number;
static ZERO: number;
static ONE: number;
static TWO: number;
static THREE: number;
static FOUR: number;
static FIVE: number;
static SIX: number;
static SEVEN: number;
static EIGHT: number;
static NINE: number;
static NUMPAD_0: number;
static NUMPAD_1: number;
static NUMPAD_2: number;
static NUMPAD_3: number;
static NUMPAD_4: number;
static NUMPAD_5: number;
static NUMPAD_6: number;
static NUMPAD_7: number;
static NUMPAD_8: number;
static NUMPAD_9: number;
static NUMPAD_MULTIPLY: number;
static NUMPAD_ADD: number;
static NUMPAD_ENTER: number;
static NUMPAD_SUBTRACT: number;
static NUMPAD_DECIMAL: number;
static NUMPAD_DIVIDE: number;
static F1: number;
static F2: number;
static F3: number;
static F4: number;
static F5: number;
static F6: number;
static F7: number;
static F8: number;
static F9: number;
static F10: number;
static F11: number;
static F12: number;
static F13: number;
static F14: number;
static F15: number;
static COLON: number;
static EQUALS: number;
static UNDERSCORE: number;
static QUESTION_MARK: number;
static TILDE: number;
static OPEN_BRACKET: number;
static BACKWARD_SLASH: number;
static CLOSED_BRACKET: number;
static QUOTES: number;
static BACKSPACE: number;
static TAB: number;
static CLEAR: number;
static ENTER: number;
static SHIFT: number;
static CONTROL: number;
static ALT: number;
static CAPS_LOCK: number;
static ESC: number;
static SPACEBAR: number;
static PAGE_UP: number;
static PAGE_DOWN: number;
static END: number;
static HOME: number;
static LEFT: number;
static UP: number;
static RIGHT: number;
static DOWN: number;
static INSERT: number;
static DELETE: number;
static HELP: number;
static NUM_LOCK: number;
}
}
-304
View File
@@ -1,304 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Keyboard
*
* The Keyboard class handles keyboard interactions with the game and the resulting events.
* The avoid stealing all browser input we don't use event.preventDefault. If you would like to trap a specific key however
* then use the addKeyCapture() method.
*/
module Phaser {
export class Keyboard {
constructor(game: Game) {
this._game = game;
}
private _game: Game;
private _keys = {};
private _capture = {};
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @type {Boolean}
*/
public disabled: bool = false;
public start() {
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
}
/**
* By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
* There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
* You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
* Pass in either a single keycode or an array of keycodes.
* @param {Any} keycode
*/
public addKeyCapture(keycode) {
if (typeof keycode === 'object')
{
for (var i:number = 0; i < keycode.length; i++)
{
this._capture[keycode[i]] = true;
}
}
else
{
this._capture[keycode] = true;
}
}
/**
* @param {Number} keycode
*/
public removeKeyCapture(keycode: number) {
delete this._capture[keycode];
}
public clearCaptures() {
this._capture = {};
}
/**
* @param {KeyboardEvent} event
*/
public onKeyDown(event: KeyboardEvent) {
if (this._game.input.disabled || this.disabled)
{
return;
}
if (this._capture[event.keyCode])
{
event.preventDefault();
}
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: true, timeDown: this._game.time.now, timeUp: 0 };
}
else
{
this._keys[event.keyCode].isDown = true;
this._keys[event.keyCode].timeDown = this._game.time.now;
}
}
/**
* @param {KeyboardEvent} event
*/
public onKeyUp(event: KeyboardEvent) {
if (this._game.input.disabled || this.disabled)
{
return;
}
if (this._capture[event.keyCode])
{
event.preventDefault();
}
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this._game.time.now };
}
else
{
this._keys[event.keyCode].isDown = false;
this._keys[event.keyCode].timeUp = this._game.time.now;
}
}
public reset() {
for (var key in this._keys)
{
this._keys[key].isDown = false;
}
}
/**
* @param {Number} keycode
* @param {Number} [duration]
* @return {Boolean}
*/
public justPressed(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this._game.time.now - this._keys[keycode].timeDown < duration))
{
return true;
}
else
{
return false;
}
}
/**
* @param {Number} keycode
* @param {Number} [duration]
* @return {Boolean}
*/
public justReleased(keycode: number, duration?: number = 250): bool {
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this._game.time.now - this._keys[keycode].timeUp < duration))
{
return true;
}
else
{
return false;
}
}
/**
* @param {Number} keycode
* @return {Boolean}
*/
public isDown(keycode: number): bool {
if (this._keys[keycode])
{
return this._keys[keycode].isDown;
}
else
{
return false;
}
}
// Letters
public static A: number = "A".charCodeAt(0);
public static B: number = "B".charCodeAt(0);
public static C: number = "C".charCodeAt(0);
public static D: number = "D".charCodeAt(0);
public static E: number = "E".charCodeAt(0);
public static F: number = "F".charCodeAt(0);
public static G: number = "G".charCodeAt(0);
public static H: number = "H".charCodeAt(0);
public static I: number = "I".charCodeAt(0);
public static J: number = "J".charCodeAt(0);
public static K: number = "K".charCodeAt(0);
public static L: number = "L".charCodeAt(0);
public static M: number = "M".charCodeAt(0);
public static N: number = "N".charCodeAt(0);
public static O: number = "O".charCodeAt(0);
public static P: number = "P".charCodeAt(0);
public static Q: number = "Q".charCodeAt(0);
public static R: number = "R".charCodeAt(0);
public static S: number = "S".charCodeAt(0);
public static T: number = "T".charCodeAt(0);
public static U: number = "U".charCodeAt(0);
public static V: number = "V".charCodeAt(0);
public static W: number = "W".charCodeAt(0);
public static X: number = "X".charCodeAt(0);
public static Y: number = "Y".charCodeAt(0);
public static Z: number = "Z".charCodeAt(0);
// Numbers
public static ZERO: number = "0".charCodeAt(0);
public static ONE: number = "1".charCodeAt(0);
public static TWO: number = "2".charCodeAt(0);
public static THREE: number = "3".charCodeAt(0);
public static FOUR: number = "4".charCodeAt(0);
public static FIVE: number = "5".charCodeAt(0);
public static SIX: number = "6".charCodeAt(0);
public static SEVEN: number = "7".charCodeAt(0);
public static EIGHT: number = "8".charCodeAt(0);
public static NINE: number = "9".charCodeAt(0);
// Numpad
public static NUMPAD_0: number = 96;
public static NUMPAD_1: number = 97;
public static NUMPAD_2: number = 98;
public static NUMPAD_3: number = 99;
public static NUMPAD_4: number = 100;
public static NUMPAD_5: number = 101;
public static NUMPAD_6: number = 102;
public static NUMPAD_7: number = 103;
public static NUMPAD_8: number = 104;
public static NUMPAD_9: number = 105;
public static NUMPAD_MULTIPLY: number = 106;
public static NUMPAD_ADD: number = 107;
public static NUMPAD_ENTER: number = 108;
public static NUMPAD_SUBTRACT: number = 109;
public static NUMPAD_DECIMAL: number = 110;
public static NUMPAD_DIVIDE: number = 111;
// Function Keys
public static F1: number = 112;
public static F2: number = 113;
public static F3: number = 114;
public static F4: number = 115;
public static F5: number = 116;
public static F6: number = 117;
public static F7: number = 118;
public static F8: number = 119;
public static F9: number = 120;
public static F10: number = 121;
public static F11: number = 122;
public static F12: number = 123;
public static F13: number = 124;
public static F14: number = 125;
public static F15: number = 126;
// Symbol Keys
public static COLON: number = 186;
public static EQUALS: number = 187;
public static UNDERSCORE: number = 189;
public static QUESTION_MARK: number = 191;
public static TILDE: number = 192;
public static OPEN_BRACKET: number = 219;
public static BACKWARD_SLASH: number = 220;
public static CLOSED_BRACKET: number = 221;
public static QUOTES: number = 222;
// Other Keys
public static BACKSPACE: number = 8;
public static TAB: number = 9;
public static CLEAR: number = 12;
public static ENTER: number = 13;
public static SHIFT: number = 16;
public static CONTROL: number = 17;
public static ALT: number = 18;
public static CAPS_LOCK: number = 20;
public static ESC: number = 27;
public static SPACEBAR: number = 32;
public static PAGE_UP: number = 33;
public static PAGE_DOWN: number = 34;
public static END: number = 35;
public static HOME: number = 36;
public static LEFT: number = 37;
public static UP: number = 38;
public static RIGHT: number = 39;
public static DOWN: number = 40;
public static INSERT: number = 45;
public static DELETE: number = 46;
public static HELP: number = 47;
public static NUM_LOCK: number = 144;
}
}
-130
View File
@@ -1,130 +0,0 @@
/// <reference path="../../Game.ts" />
/// <reference path="Pointer.ts" />
/**
* Phaser - MSPointer
*
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
*/
module Phaser {
export class MSPointer {
/**
* Constructor
* @param {Game} game.
* @return {MSPointer} This object.
*/
constructor(game: Game) {
this._game = game;
}
/**
* Local private reference to game.
* @property _game
* @type Game
* @private
**/
private _game: Game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @type {Boolean}
*/
public disabled: bool = false;
/**
* Starts the event listeners running
* @method start
*/
public start() {
if (this._game.device.mspointer == true)
{
this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
}
}
/**
*
* @method onPointerDown
* @param {Any} event
**/
private onPointerDown(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.startPointer(event);
}
/**
*
* @method onPointerMove
* @param {Any} event
**/
private onPointerMove(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.updatePointer(event);
}
/**
*
* @method onPointerUp
* @param {Any} event
**/
private onPointerUp(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.stopPointer(event);
}
/**
* Stop the event listeners
* @method stop
*/
public stop() {
if (this._game.device.mspointer == true)
{
//this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
//this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
//this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
}
}
}
}
-24
View File
@@ -1,24 +0,0 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Mouse {
constructor(game: Game);
private _game;
private _x;
private _y;
public button: number;
static LEFT_BUTTON: number;
static MIDDLE_BUTTON: number;
static RIGHT_BUTTON: number;
public isDown: bool;
public isUp: bool;
public timeDown: number;
public duration: number;
public timeUp: number;
public start(): void;
public reset(): void;
public onMouseDown(event: MouseEvent): void;
public update(): void;
public onMouseMove(event: MouseEvent): void;
public onMouseUp(event: MouseEvent): void;
}
}
-112
View File
@@ -1,112 +0,0 @@
/// <reference path="../../Game.ts" />
/**
* Phaser - Mouse
*
* The Mouse class handles mouse interactions with the game and the resulting events.
*/
module Phaser {
export class Mouse {
constructor(game: Game) {
this._game = game;
}
/**
* Local private reference to game.
* @property _game
* @type {Phaser.Game}
* @private
**/
private _game: Game;
public static LEFT_BUTTON: number = 0;
public static MIDDLE_BUTTON: number = 1;
public static RIGHT_BUTTON: number = 2;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @type {Boolean}
*/
public disabled: bool = false;
/**
* Starts the event listeners running
* @method start
*/
public start() {
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
}
/**
* @param {MouseEvent} event
*/
public onMouseDown(event: MouseEvent) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.start(event);
}
/**
* @param {MouseEvent} event
*/
public onMouseMove(event: MouseEvent) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.move(event);
}
/**
* @param {MouseEvent} event
*/
public onMouseUp(event: MouseEvent) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.stop(event);
}
/**
* Stop the event listeners
* @method stop
*/
public stop() {
//this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
//this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
//this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
}
}
}
-568
View File
@@ -1,568 +0,0 @@
/// <reference path="../../Game.ts" />
/// <reference path="../../geom/Vector2.ts" />
/**
* Phaser - Pointer
*
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
*/
module Phaser {
export class Pointer {
/**
* Constructor
* @param {Phaser.Game} game.
* @return {Phaser.Pointer} This object.
*/
constructor(game: Game, id: number) {
this._game = game;
this.id = id;
this.active = false;
this.position = new Vector2;
this.positionDown = new Vector2;
this.circle = new Circle(0, 0, 44);
if (id == 0)
{
this.isMouse = true;
}
}
/**
* Local private reference to game.
* @property _game
* @type {Phaser.Game}
* @private
**/
private _game: Game;
/**
* Local private variable to store the status of dispatching a hold event
* @property _holdSent
* @type {Boolean}
* @private
*/
private _holdSent: bool = false;
/**
* Local private variable storing the short-term history of pointer movements
* @property _history
* @type {Array}
* @private
*/
private _history = [];
/**
* Local private variable storing the time at which the next history drop should occur
* @property _lastDrop
* @type {Number}
* @private
*/
private _nextDrop: number = 0;
/**
* The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically)
* @property id
* @type {Number}
*/
public id: number;
/**
* An identification number for each touch point.
* When a touch point becomes active, it is assigned an identifier that is distinct from any other active touch point.
* While the touch point remains active, all events that refer to it are assigned the same identifier.
* @property identifier
* @type {Number}
*/
public identifier: number;
/**
* Is this Pointer active or not? An active Pointer is one that is in contact with the touch screen.
* @property active
* @type {Boolean}
*/
public active: bool;
/**
* A Vector object containing the initial position when the Pointer was engaged with the screen.
* @property positionDown
* @type {Vector2}
**/
public positionDown: Vector2 = null;
/**
* A Vector object containing the current position of the Pointer on the screen.
* @property position
* @type {Vector2}
**/
public position: Vector2 = null;
/**
* A Circle object centered on the x/y screen coordinates of the Pointer.
* Default size of 44px (Apple's recommended "finger tip" size)
* @property circle
* @type {Circle}
**/
public circle: Circle = null;
/**
*
* @property withinGame
* @type {Boolean}
*/
public withinGame: bool = false;
/**
* If this Pointer is a mouse the button property holds the value of which mouse button was pressed down
* @property button
* @type {Number}
*/
public button: number;
/**
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientX
* @type {Number}
*/
public clientX: number = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
* @property clientY
* @type {Number}
*/
public clientY: number = -1;
/**
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageX
* @type {Number}
*/
public pageX: number = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
* @property pageY
* @type {Number}
*/
public pageY: number = -1;
/**
* The horizontal coordinate of point relative to the screen in pixels
* @property screenX
* @type {Number}
*/
public screenX: number = -1;
/**
* The vertical coordinate of point relative to the screen in pixels
* @property screenY
* @type {Number}
*/
public screenY: number = -1;
/**
* The horizontal coordinate of point relative to the game element
* @property x
* @type {Number}
*/
public x: number = -1;
/**
* The vertical coordinate of point relative to the game element
* @property y
* @type {Number}
*/
public y: number = -1;
/**
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
* @property target
* @type {Any}
*/
public target;
/**
* If the Pointer is a mouse this is true, otherwise false
* @property isMouse
* @type {Boolean}
**/
public isMouse: bool = false;
/**
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
* @property isDown
* @type {Boolean}
**/
public isDown: bool = false;
/**
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
* @property isUp
* @type {Boolean}
**/
public isUp: bool = true;
/**
* A timestamp representing when the Pointer first touched the touchscreen.
* @property timeDown
* @type {Number}
**/
public timeDown: number = 0;
/**
* A timestamp representing when the Pointer left the touchscreen.
* @property timeUp
* @type {Number}
**/
public timeUp: number = 0;
/**
* A timestamp representing when the Pointer was last tapped or clicked
* @property previousTapTime
* @type {Number}
**/
public previousTapTime: number = 0;
/**
* The total number of times this Pointer has been touched to the touchscreen
* @property totalTouches
* @type {Number}
**/
public totalTouches: number = 0;
/**
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
* @property duration
* @type {Number}
**/
public get duration(): number {
if (this.isUp)
{
return -1;
}
return this._game.time.now - this.timeDown;
}
/**
* Gets the X value of this Pointer in world coordinate space
* @param {Camera} [camera]
*/
public getWorldX(camera?: Camera = this._game.camera) {
return camera.worldView.x + this.x;
}
/**
* Gets the Y value of this Pointer in world coordinate space
* @param {Camera} [camera]
*/
public getWorldY(camera?: Camera = this._game.camera) {
return camera.worldView.y + this.y;
}
/**
* Called when the Pointer is pressed onto the touchscreen
* @method start
* @param {Any} event
*/
public start(event): Pointer {
this.identifier = event.identifier;
this.target = event.target;
if (event.button)
{
this.button = event.button;
}
// Fix to stop rogue browser plugins from blocking the visibility state event
if (this._game.paused == true)
{
this._game.stage.resumeGame();
return this;
}
this._history.length = 0;
this.move(event);
this.positionDown.setTo(this.x, this.y);
this.active = true;
this.withinGame = true;
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
this._holdSent = false;
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
{
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this._game.input.onDown.dispatch(this);
}
this.totalTouches++;
if (this.isMouse == false)
{
this._game.input.currentPointers++;
}
return this;
}
public update() {
if (this.active)
{
if (this._holdSent == false && this.duration >= this._game.input.holdRate)
{
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
{
this._game.input.onHold.dispatch(this);
}
this._holdSent = true;
}
// Update the droppings history
if (this._game.input.recordPointerHistory && this._game.time.now >= this._nextDrop)
{
this._nextDrop = this._game.time.now + this._game.input.recordRate;
this._history.push({ x: this.position.x, y: this.position.y });
if (this._history.length > this._game.input.recordLimit)
{
this._history.shift();
}
}
}
}
/**
* Called when the Pointer is moved on the touchscreen
* @method move
* @param {Any} event
*/
public move(event): Pointer {
if (event.button)
{
this.button = event.button;
}
this.clientX = event.clientX;
this.clientY = event.clientY;
this.pageX = event.pageX;
this.pageY = event.pageY;
this.screenX = event.screenX;
this.screenY = event.screenY;
this.x = this.pageX - this._game.stage.offset.x;
this.y = this.pageY - this._game.stage.offset.y;
this.position.setTo(this.x, this.y);
this.circle.x = this.x;
this.circle.y = this.y;
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
{
this._game.input.x = this.x * this._game.input.scaleX;
this._game.input.y = this.y * this._game.input.scaleY;
this._game.input.position.setTo(this._game.input.x, this._game.input.y);
this._game.input.circle.x = this._game.input.x;
this._game.input.circle.y = this._game.input.y;
}
return this;
}
/**
* Called when the Pointer leaves the target area
* @method leave
* @param {Any} event
*/
public leave(event) {
this.withinGame = false;
this.move(event);
}
/**
* Called when the Pointer leaves the touchscreen
* @method stop
* @param {Any} event
*/
public stop(event): Pointer {
this.timeUp = this._game.time.now;
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
{
this._game.input.onUp.dispatch(this);
// Was it a tap?
if (this.duration >= 0 && this.duration <= this._game.input.tapRate)
{
// Was it a double-tap?
if (this.timeUp - this.previousTapTime < this._game.input.doubleTapRate)
{
// Yes, let's dispatch the signal then with the 2nd parameter set to true
this._game.input.onTap.dispatch(this, true);
}
else
{
// Wasn't a double-tap, so dispatch a single tap signal
this._game.input.onTap.dispatch(this, false);
}
this.previousTapTime = this.timeUp;
}
}
this.active = false;
this.withinGame = false;
this.isDown = false;
this.isUp = true;
if (this.isMouse == false)
{
this._game.input.currentPointers--;
}
return this;
}
/**
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
* @method justPressed
* @param {Number} [duration].
* @return {Boolean}
*/
public justPressed(duration?: number = this._game.input.justPressedRate): bool {
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
}
}
/**
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
* @method justReleased
* @param {Number} [duration].
* @return {Boolean}
*/
public justReleased(duration?: number = this._game.input.justReleasedRate): bool {
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
{
return true;
}
else
{
return false;
}
}
/**
* Resets the Pointer properties. Called by Input.reset when you perform a State change.
* @method reset
*/
public reset() {
this.active = false;
this.identifier = null;
this.isDown = false;
this.isUp = true;
this.totalTouches = 0;
this._holdSent = false;
this._history.length = 0;
}
/**
* Renders the Pointer.circle object onto the stage in green if down or red if up.
* @method renderDebug
*/
public renderDebug(hideIfUp: bool = false) {
if (hideIfUp == true && this.isUp == true)
{
return;
}
this._game.stage.context.beginPath();
this._game.stage.context.arc(this.x, this.y, this.circle.radius, 0, Math.PI * 2);
if (this.active)
{
this._game.stage.context.fillStyle = 'rgba(0,255,0,0.5)';
this._game.stage.context.strokeStyle = 'rgb(0,255,0)';
}
else
{
this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
this._game.stage.context.strokeStyle = 'rgb(100,0,0)';
}
this._game.stage.context.fill();
this._game.stage.context.closePath();
// Render the points
this._game.stage.context.beginPath();
this._game.stage.context.moveTo(this.positionDown.x, this.positionDown.y);
this._game.stage.context.lineTo(this.position.x, this.position.y);
this._game.stage.context.lineWidth = 2;
this._game.stage.context.stroke();
this._game.stage.context.closePath();
// Render the text
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
this._game.stage.context.font = 'Arial 16px';
this._game.stage.context.fillText('ID: ' + this.id + " Active: " + this.active, this.x, this.y - 100);
this._game.stage.context.fillText('Screen X: ' + this.x + " Screen Y: " + this.y, this.x, this.y - 80);
this._game.stage.context.fillText('Duration: ' + this.duration + " ms", this.x, this.y - 60);
}
/**
* Returns a string representation of this object.
* @method toString
* @return {String} a string representation of the instance.
**/
public toString(): string {
return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
}
}
}
-40
View File
@@ -1,40 +0,0 @@
/// <reference path="../../Game.d.ts" />
/// <reference path="Finger.d.ts" />
module Phaser {
class Touch {
constructor(game: Game);
private _game;
public x: number;
public y: number;
private _fingers;
public finger1: Finger;
public finger2: Finger;
public finger3: Finger;
public finger4: Finger;
public finger5: Finger;
public finger6: Finger;
public finger7: Finger;
public finger8: Finger;
public finger9: Finger;
public finger10: Finger;
public latestFinger: Finger;
public isDown: bool;
public isUp: bool;
public touchDown: Signal;
public touchUp: Signal;
public start(): void;
private consumeTouchMove(event);
private onTouchStart(event);
private onTouchCancel(event);
private onTouchEnter(event);
private onTouchLeave(event);
private onTouchMove(event);
private onTouchEnd(event);
public calculateDistance(finger1: Finger, finger2: Finger): void;
public calculateAngle(finger1: Finger, finger2: Finger): void;
public checkOverlap(finger1: Finger, finger2: Finger): void;
public update(): void;
public stop(): void;
public reset(): void;
}
}
-217
View File
@@ -1,217 +0,0 @@
/// <reference path="../../Game.ts" />
/// <reference path="Pointer.ts" />
/**
* Phaser - Touch
*
* The Touch class handles touch interactions with the game and the resulting Pointer objects.
* http://www.w3.org/TR/touch-events/
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
* http://www.html5rocks.com/en/mobile/touchandmouse/
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
*/
module Phaser {
export class Touch {
/**
* Constructor
* @param {Game} game.
* @return {Touch} This object.
*/
constructor(game: Game) {
this._game = game;
}
/**
* Local private reference to game.
* @property _game
* @type {Phaser.Game}
* @private
**/
private _game: Game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @type {Boolean}
*/
public disabled: bool = false;
/**
* Starts the event listeners running
* @method start
*/
public start() {
if (this._game.device.touch)
{
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
}
}
/**
* Prevent iOS bounce-back (doesn't work?)
* @method consumeTouchMove
* @param {Any} event
**/
private consumeTouchMove(event) {
event.preventDefault();
}
/**
*
* @method onTouchStart
* @param {Any} event
**/
private onTouchStart(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
this._game.input.startPointer(event.changedTouches[i]);
}
}
/**
* 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
* @method onTouchCancel
* @param {Any} event
**/
private onTouchCancel(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
for (var i = 0; i < event.changedTouches.length; i++)
{
this._game.input.stopPointer(event.changedTouches[i]);
}
}
/**
* 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 yet
* @method onTouchEnter
* @param {Any} event
**/
private onTouchEnter(event) {
if (this._game.input.disabled || this.disabled)
{
return;
}
event.preventDefault();
for (var i = 0; i < event.changedTouches.length; i++)
{
console.log('touch enter');
}
}
/**
* 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 yet
* @method onTouchLeave
* @param {Any} event
**/
private onTouchLeave(event) {
event.preventDefault();
for (var i = 0; i < event.changedTouches.length; i++)
{
console.log('touch leave');
}
}
/**
*
* @method onTouchMove
* @param {Any} event
**/
private onTouchMove(event) {
event.preventDefault();
for (var i = 0; i < event.changedTouches.length; i++)
{
this._game.input.updatePointer(event.changedTouches[i]);
}
}
/**
*
* @method onTouchEnd
* @param {Any} event
**/
private onTouchEnd(event) {
event.preventDefault();
// For touch end its a list of the touch points that have been removed from the surface
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
for (var i = 0; i < event.changedTouches.length; i++)
{
this._game.input.stopPointer(event.changedTouches[i]);
}
}
/**
* Stop the event listeners
* @method stop
*/
public stop() {
if (this._game.device.touch)
{
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
}
}
}
}