mirror of
https://github.com/wassname/phaser.git
synced 2026-08-14 12:40:17 +08:00
Preparing for new release
This commit is contained in:
+623
-617
File diff suppressed because it is too large
Load Diff
+522
-514
File diff suppressed because it is too large
Load Diff
+38
-29
@@ -1,45 +1,54 @@
|
||||
/// <reference path="../Basic.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* A miniature linked list class.
|
||||
* Useful for optimizing time-critical or highly repetitive tasks!
|
||||
* See <code>QuadTree</code> for how to use it, IF YOU DARE.
|
||||
*/
|
||||
class LinkedList {
|
||||
|
||||
/**
|
||||
* Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
this.object = null;
|
||||
this.next = null;
|
||||
module Phaser {
|
||||
|
||||
}
|
||||
export class LinkedList {
|
||||
|
||||
/**
|
||||
* Stores a reference to an <code>Basic</code>.
|
||||
*/
|
||||
public object: Basic;
|
||||
/**
|
||||
* Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* Stores a reference to the next link in the list.
|
||||
*/
|
||||
public next: LinkedList;
|
||||
this.object = null;
|
||||
this.next = null;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
this.object = null;
|
||||
|
||||
if (this.next != null)
|
||||
{
|
||||
this.next.destroy();
|
||||
}
|
||||
|
||||
this.next = null;
|
||||
/**
|
||||
* Stores a reference to an <code>Basic</code>.
|
||||
*/
|
||||
public object: Basic;
|
||||
|
||||
/**
|
||||
* Stores a reference to the next link in the list.
|
||||
*/
|
||||
public next: LinkedList;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
this.object = null;
|
||||
|
||||
if (this.next != null)
|
||||
{
|
||||
this.next.destroy();
|
||||
}
|
||||
|
||||
this.next = null;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+678
-670
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* Repeatable Random Data Generator
|
||||
*
|
||||
@@ -10,273 +12,281 @@
|
||||
* @author Richard Davey, TypeScript conversion and additional methods
|
||||
*/
|
||||
|
||||
class RandomDataGenerator {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Array} seeds
|
||||
* @return {Kiwi.Utils.RandomDataGenerator}
|
||||
*/
|
||||
constructor(seeds?: string[] = []) {
|
||||
module Phaser {
|
||||
|
||||
this.sow(seeds);
|
||||
export class RandomDataGenerator {
|
||||
|
||||
}
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Array} seeds
|
||||
* @return {Phaser.RandomDataGenerator}
|
||||
*/
|
||||
constructor(seeds?: string[] = []) {
|
||||
|
||||
/**
|
||||
* @property s0
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s0;
|
||||
this.sow(seeds);
|
||||
|
||||
/**
|
||||
* @property s1
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s1;
|
||||
|
||||
/**
|
||||
* @property s2
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s2;
|
||||
|
||||
/**
|
||||
* @property c
|
||||
* @type Number
|
||||
* @private
|
||||
*/
|
||||
private c: number = 1;
|
||||
|
||||
/**
|
||||
* @method uint32
|
||||
* @private
|
||||
*/
|
||||
private uint32() {
|
||||
|
||||
return this.rnd.apply(this) * 0x100000000; // 2^32
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @method fract32
|
||||
* @private
|
||||
*/
|
||||
private fract32() {
|
||||
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
|
||||
|
||||
}
|
||||
|
||||
// private random helper
|
||||
/**
|
||||
* @method rnd
|
||||
* @private
|
||||
*/
|
||||
private rnd() {
|
||||
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
|
||||
return this.s2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
*/
|
||||
private hash(data) {
|
||||
|
||||
var h, i, n;
|
||||
|
||||
n = 0xefc8249d;
|
||||
|
||||
data = data.toString();
|
||||
|
||||
for (i = 0; i < data.length; i++)
|
||||
{
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000; // 2^32
|
||||
}
|
||||
|
||||
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
|
||||
/**
|
||||
* @property s0
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s0;
|
||||
|
||||
}
|
||||
/**
|
||||
* @property s1
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s1;
|
||||
|
||||
/**
|
||||
* Reset the seed of the random data generator
|
||||
* @method sow
|
||||
* @param {Array} seeds
|
||||
*/
|
||||
public sow(seeds?: string[] = []) {
|
||||
/**
|
||||
* @property s2
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
private s2;
|
||||
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
/**
|
||||
* @property c
|
||||
* @type Number
|
||||
* @private
|
||||
*/
|
||||
private c: number = 1;
|
||||
|
||||
var seed;
|
||||
/**
|
||||
* @method uint32
|
||||
* @private
|
||||
*/
|
||||
private uint32() {
|
||||
|
||||
for (var i = 0; seed = seeds[i++];)
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
return this.rnd.apply(this) * 0x100000000; // 2^32
|
||||
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @method fract32
|
||||
* @private
|
||||
*/
|
||||
private fract32() {
|
||||
|
||||
return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
|
||||
|
||||
}
|
||||
|
||||
// private random helper
|
||||
/**
|
||||
* @method rnd
|
||||
* @private
|
||||
*/
|
||||
private rnd() {
|
||||
|
||||
var t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10; // 2^-32
|
||||
|
||||
this.c = t | 0;
|
||||
this.s0 = this.s1;
|
||||
this.s1 = this.s2;
|
||||
this.s2 = t - this.c;
|
||||
|
||||
return this.s2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method hash
|
||||
* @param {Any} data
|
||||
* @private
|
||||
*/
|
||||
private hash(data) {
|
||||
|
||||
var h, i, n;
|
||||
|
||||
n = 0xefc8249d;
|
||||
|
||||
data = data.toString();
|
||||
|
||||
for (i = 0; i < data.length; i++)
|
||||
{
|
||||
n += data.charCodeAt(i);
|
||||
h = 0.02519603282416938 * n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = h >>> 0;
|
||||
h -= n;
|
||||
n += h * 0x100000000; // 2^32
|
||||
}
|
||||
|
||||
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the seed of the random data generator
|
||||
* @method sow
|
||||
* @param {Array} seeds
|
||||
*/
|
||||
public sow(seeds?: string[] = []) {
|
||||
|
||||
this.s0 = this.hash(' ');
|
||||
this.s1 = this.hash(this.s0);
|
||||
this.s2 = this.hash(this.s1);
|
||||
|
||||
var seed;
|
||||
|
||||
for (var i = 0; seed = seeds[i++];)
|
||||
{
|
||||
this.s0 -= this.hash(seed);
|
||||
this.s0 += ~~(this.s0 < 0);
|
||||
|
||||
this.s1 -= this.hash(seed);
|
||||
this.s1 += ~~(this.s1 < 0);
|
||||
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32
|
||||
* @method integer
|
||||
* @return {Number}
|
||||
*/
|
||||
public get integer(): number {
|
||||
|
||||
return this.uint32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 1
|
||||
* @method frac
|
||||
* @return {Number}
|
||||
*/
|
||||
public get frac(): number {
|
||||
|
||||
return this.fract32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32
|
||||
* @method real
|
||||
* @return {Number}
|
||||
*/
|
||||
public get real(): number {
|
||||
|
||||
return this.uint32() + this.fract32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max
|
||||
* @method integerInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
public integerInRange(min: number, max: number): number {
|
||||
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between min and max
|
||||
* @method realInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
public realInRange(min: number, max: number): number {
|
||||
|
||||
min = min || 0;
|
||||
max = max || 0;
|
||||
|
||||
return this.frac * (max - min) + min;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between -1 and 1
|
||||
* @method normal
|
||||
* @return {Number}
|
||||
*/
|
||||
public get normal(): number {
|
||||
|
||||
return 1 - 2 * this.frac;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a valid v4 UUID hex string (from https://gist.github.com/1308368)
|
||||
* @method uuid
|
||||
* @return {String}
|
||||
*/
|
||||
public get uuid(): string {
|
||||
|
||||
var a, b;
|
||||
|
||||
for (
|
||||
b = a = '';
|
||||
a++ < 36;
|
||||
b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-'
|
||||
);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`
|
||||
* @method pick
|
||||
* @param {Any} array
|
||||
*/
|
||||
public pick(array) {
|
||||
|
||||
return array[this.integerInRange(0, array.length)];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries
|
||||
* @method weightedPick
|
||||
* @param {Any} array
|
||||
*/
|
||||
public weightedPick(array) {
|
||||
|
||||
return array[~~(Math.pow(this.frac, 2) * array.length)];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
|
||||
* @method timestamp
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
*/
|
||||
public timestamp(min?: number = 946684800000, max?: number = 1577862000000): number {
|
||||
|
||||
return this.realInRange(min, max);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random angle between -180 and 180
|
||||
* @method angle
|
||||
*/
|
||||
public get angle(): number {
|
||||
|
||||
return this.integerInRange(-180, 180);
|
||||
|
||||
this.s2 -= this.hash(seed);
|
||||
this.s2 += ~~(this.s2 < 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random integer between 0 and 2^32
|
||||
* @method integer
|
||||
* @return {Number}
|
||||
*/
|
||||
public get integer(): number {
|
||||
|
||||
return this.uint32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 1
|
||||
* @method frac
|
||||
* @return {Number}
|
||||
*/
|
||||
public get frac(): number {
|
||||
|
||||
return this.fract32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between 0 and 2^32
|
||||
* @method real
|
||||
* @return {Number}
|
||||
*/
|
||||
public get real(): number {
|
||||
|
||||
return this.uint32() + this.fract32();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max
|
||||
* @method integerInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
public integerInRange(min: number, max: number): number {
|
||||
|
||||
return Math.floor(this.realInRange(min, max));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between min and max
|
||||
* @method realInRange
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
*/
|
||||
public realInRange(min: number, max: number): number {
|
||||
|
||||
min = min || 0;
|
||||
max = max || 0;
|
||||
|
||||
return this.frac * (max - min) + min;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random real number between -1 and 1
|
||||
* @method normal
|
||||
* @return {Number}
|
||||
*/
|
||||
public get normal(): number {
|
||||
|
||||
return 1 - 2 * this.frac;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a valid v4 UUID hex string (from https://gist.github.com/1308368)
|
||||
* @method uuid
|
||||
* @return {String}
|
||||
*/
|
||||
public get uuid(): string {
|
||||
|
||||
var a, b;
|
||||
|
||||
for (
|
||||
b = a = '';
|
||||
a++ < 36;
|
||||
b += ~a % 5 | a * 3 & 4 ? (a ^ 15 ? 8 ^ this.frac * (a ^ 20 ? 16 : 4) : 4).toString(16) : '-'
|
||||
);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`
|
||||
* @method pick
|
||||
* @param {Any} array
|
||||
*/
|
||||
public pick(array) {
|
||||
|
||||
return array[this.integerInRange(0, array.length)];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random member of `array`, favoring the earlier entries
|
||||
* @method weightedPick
|
||||
* @param {Any} array
|
||||
*/
|
||||
public weightedPick(array) {
|
||||
|
||||
return array[~~(Math.pow(this.frac, 2) * array.length)];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified
|
||||
* @method timestamp
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
*/
|
||||
public timestamp(min?: number = 946684800000, max?: number = 1577862000000):number {
|
||||
|
||||
return this.realInRange(min, max);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random angle between -180 and 180
|
||||
* @method angle
|
||||
*/
|
||||
public get angle():number {
|
||||
|
||||
return this.integerInRange(-180, 180);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* RequestAnimationFrame
|
||||
*
|
||||
@@ -7,199 +9,207 @@
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class RequestAnimationFrame {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Any} callback
|
||||
* @return {RequestAnimationFrame} This object.
|
||||
*/
|
||||
constructor(callback, callbackContext) {
|
||||
module Phaser {
|
||||
|
||||
this._callback = callback;
|
||||
this._callbackContext = callbackContext;
|
||||
export class RequestAnimationFrame {
|
||||
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Any} callback
|
||||
* @return {RequestAnimationFrame} This object.
|
||||
*/
|
||||
constructor(callback, callbackContext) {
|
||||
|
||||
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
|
||||
{
|
||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
||||
}
|
||||
|
||||
this.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _callback
|
||||
* @type Any
|
||||
* @private
|
||||
**/
|
||||
private _callback;
|
||||
private _callbackContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method callback
|
||||
* @param {Any} callback
|
||||
**/
|
||||
public setCallback(callback) {
|
||||
|
||||
this._callback = callback;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _timeOutID
|
||||
* @type Any
|
||||
* @private
|
||||
**/
|
||||
private _timeOutID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _isSetTimeOut
|
||||
* @type Boolean
|
||||
* @private
|
||||
**/
|
||||
private _isSetTimeOut: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method usingSetTimeOut
|
||||
* @return Boolean
|
||||
**/
|
||||
public isUsingSetTimeOut(): bool {
|
||||
|
||||
return this._isSetTimeOut;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method usingRAF
|
||||
* @return Boolean
|
||||
**/
|
||||
public isUsingRAF(): bool {
|
||||
|
||||
if (this._isSetTimeOut === true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property lastTime
|
||||
* @type Number
|
||||
**/
|
||||
public lastTime: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property currentTime
|
||||
* @type Number
|
||||
**/
|
||||
public currentTime: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isRunning
|
||||
* @type Boolean
|
||||
**/
|
||||
public isRunning: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
* @param {Any} [callback]
|
||||
**/
|
||||
public start(callback? = null) {
|
||||
|
||||
if (callback)
|
||||
{
|
||||
this._callback = callback;
|
||||
this._callbackContext = callbackContext;
|
||||
|
||||
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
||||
|
||||
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; x++)
|
||||
{
|
||||
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
||||
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'];
|
||||
}
|
||||
|
||||
this.start();
|
||||
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame)
|
||||
{
|
||||
this._isSetTimeOut = true;
|
||||
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), 0);
|
||||
/**
|
||||
*
|
||||
* @property _callback
|
||||
* @type Any
|
||||
* @private
|
||||
**/
|
||||
private _callback;
|
||||
private _callbackContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method callback
|
||||
* @param {Any} callback
|
||||
**/
|
||||
public setCallback(callback) {
|
||||
|
||||
this._callback = callback;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this._isSetTimeOut = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _timeOutID
|
||||
* @type Any
|
||||
* @private
|
||||
**/
|
||||
private _timeOutID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _isSetTimeOut
|
||||
* @type Boolean
|
||||
* @private
|
||||
**/
|
||||
private _isSetTimeOut: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method usingSetTimeOut
|
||||
* @return Boolean
|
||||
**/
|
||||
public isUsingSetTimeOut(): bool {
|
||||
|
||||
return this._isSetTimeOut;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method usingRAF
|
||||
* @return Boolean
|
||||
**/
|
||||
public isUsingRAF(): bool {
|
||||
|
||||
if (this._isSetTimeOut === true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property lastTime
|
||||
* @type Number
|
||||
**/
|
||||
public lastTime: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property currentTime
|
||||
* @type Number
|
||||
**/
|
||||
public currentTime: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isRunning
|
||||
* @type Boolean
|
||||
**/
|
||||
public isRunning: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
* @param {Any} [callback]
|
||||
**/
|
||||
public start(callback? = null) {
|
||||
|
||||
if (callback)
|
||||
{
|
||||
this._callback = callback;
|
||||
}
|
||||
|
||||
if (!window.requestAnimationFrame)
|
||||
{
|
||||
this._isSetTimeOut = true;
|
||||
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._isSetTimeOut = false;
|
||||
window.requestAnimationFrame(() => this.RAFUpdate());
|
||||
}
|
||||
|
||||
this.isRunning = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
**/
|
||||
public stop() {
|
||||
|
||||
if (this._isSetTimeOut)
|
||||
{
|
||||
clearTimeout(this._timeOutID);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.cancelAnimationFrame;
|
||||
}
|
||||
|
||||
this.isRunning = false;
|
||||
|
||||
}
|
||||
|
||||
public RAFUpdate() {
|
||||
|
||||
// Not in IE8 (but neither is RAF) also doesn't use a high performance timer (window.performance.now)
|
||||
this.currentTime = Date.now();
|
||||
|
||||
if (this._callback)
|
||||
{
|
||||
this._callback.call(this._callbackContext);
|
||||
}
|
||||
|
||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
||||
|
||||
window.requestAnimationFrame(() => this.RAFUpdate());
|
||||
|
||||
this.lastTime = this.currentTime + timeToCall;
|
||||
|
||||
}
|
||||
|
||||
this.isRunning = true;
|
||||
/**
|
||||
*
|
||||
* @method SetTimeoutUpdate
|
||||
**/
|
||||
public SetTimeoutUpdate() {
|
||||
|
||||
// Not in IE8
|
||||
this.currentTime = Date.now();
|
||||
|
||||
if (this._callback)
|
||||
{
|
||||
this._callback.call(this._callbackContext);
|
||||
}
|
||||
|
||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
||||
|
||||
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), timeToCall);
|
||||
|
||||
this.lastTime = this.currentTime + timeToCall;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
**/
|
||||
public stop() {
|
||||
|
||||
if (this._isSetTimeOut)
|
||||
{
|
||||
clearTimeout(this._timeOutID);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.cancelAnimationFrame;
|
||||
}
|
||||
|
||||
this.isRunning = false;
|
||||
|
||||
}
|
||||
|
||||
public RAFUpdate() {
|
||||
|
||||
// Not in IE8 (but neither is RAF) also doesn't use a high performance timer (window.performance.now)
|
||||
this.currentTime = Date.now();
|
||||
|
||||
if (this._callback)
|
||||
{
|
||||
this._callback.call(this._callbackContext);
|
||||
}
|
||||
|
||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
||||
|
||||
window.requestAnimationFrame(() => this.RAFUpdate());
|
||||
|
||||
this.lastTime = this.currentTime + timeToCall;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method SetTimeoutUpdate
|
||||
**/
|
||||
public SetTimeoutUpdate() {
|
||||
|
||||
// Not in IE8
|
||||
this.currentTime = Date.now();
|
||||
|
||||
if (this._callback)
|
||||
{
|
||||
this._callback.call(this._callbackContext);
|
||||
}
|
||||
|
||||
var timeToCall: number = Math.max(0, 16 - (this.currentTime - this.lastTime));
|
||||
|
||||
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), timeToCall);
|
||||
|
||||
this.lastTime = this.currentTime + timeToCall;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+119
-111
@@ -9,157 +9,165 @@
|
||||
* https://raw.github.com/zynga/viewporter/master/MIT-LICENSE.txt
|
||||
*/
|
||||
|
||||
class StageScaleMode {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
export class StageScaleMode {
|
||||
|
||||
this.orientation = window['orientation'];
|
||||
constructor(game: Game) {
|
||||
|
||||
window.addEventListener('orientationchange', (event) => this.checkOrientation(event), false);
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
private _startHeight: number = 0;
|
||||
private _iterations: number;
|
||||
private _check;
|
||||
|
||||
// Specifies that the game be visible in the specified area without trying to preserve the original aspect ratio.
|
||||
public static EXACT_FIT:number = 0;
|
||||
|
||||
// Specifies that the size of the game be fixed, so that it remains unchanged even if the size of the window changes.
|
||||
public static NO_SCALE:number = 1;
|
||||
|
||||
// Specifies that the entire game be visible in the specified area without distortion while maintaining the original aspect ratio.
|
||||
public static SHOW_ALL:number = 2;
|
||||
|
||||
public width: number = 0;
|
||||
public height: number = 0;
|
||||
|
||||
public orientation;
|
||||
|
||||
public update() {
|
||||
|
||||
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
|
||||
{
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public get isLandscape(): bool {
|
||||
return window['orientation'] === 90 || window['orientation'] === -90;
|
||||
}
|
||||
|
||||
private checkOrientation(event) {
|
||||
|
||||
if (window['orientation'] !== this.orientation)
|
||||
{
|
||||
this.refresh();
|
||||
this.orientation = window['orientation'];
|
||||
|
||||
window.addEventListener('orientationchange', (event) => this.checkOrientation(event), false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private _game: Game;
|
||||
private _startHeight: number = 0;
|
||||
private _iterations: number;
|
||||
private _check;
|
||||
|
||||
private refresh() {
|
||||
// Specifies that the game be visible in the specified area without trying to preserve the original aspect ratio.
|
||||
public static EXACT_FIT: number = 0;
|
||||
|
||||
// We can't do anything about the status bars in iPads, web apps or desktops
|
||||
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
||||
{
|
||||
document.documentElement.style.minHeight = '5000px';
|
||||
// Specifies that the size of the game be fixed, so that it remains unchanged even if the size of the window changes.
|
||||
public static NO_SCALE: number = 1;
|
||||
|
||||
this._startHeight = window.innerHeight;
|
||||
// Specifies that the entire game be visible in the specified area without distortion while maintaining the original aspect ratio.
|
||||
public static SHOW_ALL: number = 2;
|
||||
|
||||
if (this._game.device.android && this._game.device.chrome == false)
|
||||
{
|
||||
window.scrollTo(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
public width: number = 0;
|
||||
public height: number = 0;
|
||||
|
||||
if (this._check == null)
|
||||
{
|
||||
this._iterations = 40;
|
||||
this._check = window.setInterval(() => this.setScreenSize(), 10);
|
||||
}
|
||||
public orientation;
|
||||
|
||||
}
|
||||
public update() {
|
||||
|
||||
private setScreenSize() {
|
||||
|
||||
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
||||
{
|
||||
if (this._game.device.android && this._game.device.chrome == false)
|
||||
if (this._game.stage.scaleMode !== StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
|
||||
{
|
||||
window.scrollTo(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.scrollTo(0, 0);
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this._iterations--;
|
||||
public get isLandscape(): bool {
|
||||
return window['orientation'] === 90 || window['orientation'] === -90;
|
||||
}
|
||||
|
||||
if (window.innerHeight > this._startHeight || this._iterations < 0)
|
||||
{
|
||||
// Set minimum height of content to new window height
|
||||
document.documentElement.style.minHeight = window.innerHeight + 'px';
|
||||
private checkOrientation(event) {
|
||||
|
||||
if (this._game.stage.scaleMode == StageScaleMode.EXACT_FIT)
|
||||
if (window['orientation'] !== this.orientation)
|
||||
{
|
||||
if (this._game.stage.maxScaleX && window.innerWidth > this._game.stage.maxScaleX)
|
||||
this.refresh();
|
||||
this.orientation = window['orientation'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private refresh() {
|
||||
|
||||
// We can't do anything about the status bars in iPads, web apps or desktops
|
||||
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
||||
{
|
||||
document.documentElement.style.minHeight = '5000px';
|
||||
|
||||
this._startHeight = window.innerHeight;
|
||||
|
||||
if (this._game.device.android && this._game.device.chrome == false)
|
||||
{
|
||||
this.width = this._game.stage.maxScaleX;
|
||||
window.scrollTo(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.width = window.innerWidth;
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._game.stage.maxScaleY && window.innerHeight > this._game.stage.maxScaleY)
|
||||
if (this._check == null)
|
||||
{
|
||||
this._iterations = 40;
|
||||
this._check = window.setInterval(() => this.setScreenSize(), 10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private setScreenSize() {
|
||||
|
||||
if (this._game.device.iPad == false && this._game.device.webApp == false && this._game.device.desktop == false)
|
||||
{
|
||||
if (this._game.device.android && this._game.device.chrome == false)
|
||||
{
|
||||
this.height = this._game.stage.maxScaleY;
|
||||
window.scrollTo(0, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.height = window.innerHeight;
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
else if (this._game.stage.scaleMode == StageScaleMode.SHOW_ALL)
|
||||
|
||||
this._iterations--;
|
||||
|
||||
if (window.innerHeight > this._startHeight || this._iterations < 0)
|
||||
{
|
||||
var multiplier = Math.min((window.innerHeight / this._game.stage.height), (window.innerWidth / this._game.stage.width));
|
||||
// Set minimum height of content to new window height
|
||||
document.documentElement.style.minHeight = window.innerHeight + 'px';
|
||||
|
||||
this.width = Math.round(this._game.stage.width * multiplier);
|
||||
this.height = Math.round(this._game.stage.height * multiplier);
|
||||
if (this._game.stage.scaleMode == StageScaleMode.EXACT_FIT)
|
||||
{
|
||||
if (this._game.stage.maxScaleX && window.innerWidth > this._game.stage.maxScaleX)
|
||||
{
|
||||
this.width = this._game.stage.maxScaleX;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.width = window.innerWidth;
|
||||
}
|
||||
|
||||
if (this._game.stage.maxScaleX && this.width > this._game.stage.maxScaleX)
|
||||
{
|
||||
this.width = this._game.stage.maxScaleX;
|
||||
}
|
||||
|
||||
if (this._game.stage.maxScaleY && this.height > this._game.stage.maxScaleY)
|
||||
{
|
||||
this.height = this._game.stage.maxScaleY;
|
||||
if (this._game.stage.maxScaleY && window.innerHeight > this._game.stage.maxScaleY)
|
||||
{
|
||||
this.height = this._game.stage.maxScaleY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.height = window.innerHeight;
|
||||
}
|
||||
}
|
||||
else if (this._game.stage.scaleMode == StageScaleMode.SHOW_ALL)
|
||||
{
|
||||
var multiplier = Math.min((window.innerHeight / this._game.stage.height), (window.innerWidth / this._game.stage.width));
|
||||
|
||||
this.width = Math.round(this._game.stage.width * multiplier);
|
||||
this.height = Math.round(this._game.stage.height * multiplier);
|
||||
|
||||
if (this._game.stage.maxScaleX && this.width > this._game.stage.maxScaleX)
|
||||
{
|
||||
this.width = this._game.stage.maxScaleX;
|
||||
}
|
||||
|
||||
if (this._game.stage.maxScaleY && this.height > this._game.stage.maxScaleY)
|
||||
{
|
||||
this.height = this._game.stage.maxScaleY;
|
||||
}
|
||||
}
|
||||
|
||||
this._game.stage.canvas.style.width = this.width + 'px';
|
||||
this._game.stage.canvas.style.height = this.height + 'px';
|
||||
|
||||
this._game.input.scaleX = this._game.stage.width / this.width;
|
||||
this._game.input.scaleY = this._game.stage.height / this.height;
|
||||
|
||||
clearInterval(this._check);
|
||||
|
||||
this._check = null;
|
||||
|
||||
}
|
||||
|
||||
this._game.stage.canvas.style.width = this.width + 'px';
|
||||
this._game.stage.canvas.style.height = this.height + 'px';
|
||||
|
||||
this._game.input.scaleX = this._game.stage.width / this.width;
|
||||
this._game.input.scaleY = this._game.stage.height / this.height;
|
||||
|
||||
clearInterval(this._check);
|
||||
|
||||
this._check = null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+78
-70
@@ -1,5 +1,4 @@
|
||||
/// <reference path="../GameObject.ts" />
|
||||
/// <reference path="../Tilemap.ts" />
|
||||
/// <reference path="../Game.ts" />
|
||||
|
||||
/**
|
||||
* A simple helper object for <code>Tilemap</code> that helps expand collision opportunities and control.
|
||||
@@ -9,79 +8,88 @@
|
||||
* @author Adam Atomic
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class Tile extends GameObject {
|
||||
|
||||
/**
|
||||
* Instantiate this new tile object. This is usually called from <code>FlxTilemap.loadMap()</code>.
|
||||
*
|
||||
* @param Tilemap A reference to the tilemap object creating the tile.
|
||||
* @param Index The actual core map data index for this tile type.
|
||||
* @param Width The width of the tile.
|
||||
* @param Height The height of the tile.
|
||||
* @param Visible Whether the tile is visible or not.
|
||||
* @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
|
||||
*/
|
||||
constructor(game: Game, Tilemap: Tilemap, Index: number, Width: number, Height: number, Visible: bool, AllowCollisions: number) {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
super(game, 0, 0, Width, Height);
|
||||
module Phaser {
|
||||
|
||||
this.immovable = true;
|
||||
this.moves = false;
|
||||
this.callback = null;
|
||||
this.filter = null;
|
||||
export class Tile extends GameObject {
|
||||
|
||||
this.tilemap = Tilemap;
|
||||
this.index = Index;
|
||||
this.visible = Visible;
|
||||
this.allowCollisions = AllowCollisions;
|
||||
/**
|
||||
* Instantiate this new tile object. This is usually called from <code>FlxTilemap.loadMap()</code>.
|
||||
*
|
||||
* @param Tilemap A reference to the tilemap object creating the tile.
|
||||
* @param Index The actual core map data index for this tile type.
|
||||
* @param Width The width of the tile.
|
||||
* @param Height The height of the tile.
|
||||
* @param Visible Whether the tile is visible or not.
|
||||
* @param AllowCollisions The collision flags for the object. By default this value is ANY or NONE depending on the parameters sent to loadMap().
|
||||
*/
|
||||
constructor(game: Game, Tilemap: Tilemap, Index: number, Width: number, Height: number, Visible: bool, AllowCollisions: number) {
|
||||
|
||||
this.mapIndex = 0;
|
||||
super(game, 0, 0, Width, Height);
|
||||
|
||||
this.immovable = true;
|
||||
this.moves = false;
|
||||
this.callback = null;
|
||||
this.filter = null;
|
||||
|
||||
this.tilemap = Tilemap;
|
||||
this.index = Index;
|
||||
this.visible = Visible;
|
||||
this.allowCollisions = AllowCollisions;
|
||||
|
||||
this.mapIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called whenever an object hits a tile of this type.
|
||||
* This function should take the form <code>myFunction(Tile:FlxTile,Object:FlxObject)</code>.
|
||||
* Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>.
|
||||
*/
|
||||
public callback;
|
||||
|
||||
/**
|
||||
* Each tile can store its own filter class for their callback functions.
|
||||
* That is, the callback will only be triggered if an object with a class
|
||||
* type matching the filter touched it.
|
||||
* Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>.
|
||||
*/
|
||||
public filter;
|
||||
|
||||
/**
|
||||
* A reference to the tilemap this tile object belongs to.
|
||||
*/
|
||||
public tilemap: Tilemap;
|
||||
|
||||
/**
|
||||
* The index of this tile type in the core map data.
|
||||
* For example, if your map only has 16 kinds of tiles in it,
|
||||
* this number is usually between 0 and 15.
|
||||
*/
|
||||
public index: number;
|
||||
|
||||
/**
|
||||
* The current map index of this tile object at this moment.
|
||||
* You can think of tile objects as moving around the tilemap helping with collisions.
|
||||
* This value is only reliable and useful if used from the callback function.
|
||||
*/
|
||||
public mapIndex: number;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
super.destroy();
|
||||
this.callback = null;
|
||||
this.tilemap = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called whenever an object hits a tile of this type.
|
||||
* This function should take the form <code>myFunction(Tile:FlxTile,Object:FlxObject)</code>.
|
||||
* Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>.
|
||||
*/
|
||||
public callback;
|
||||
|
||||
/**
|
||||
* Each tile can store its own filter class for their callback functions.
|
||||
* That is, the callback will only be triggered if an object with a class
|
||||
* type matching the filter touched it.
|
||||
* Defaults to null, set through <code>FlxTilemap.setTileProperties()</code>.
|
||||
*/
|
||||
public filter;
|
||||
|
||||
/**
|
||||
* A reference to the tilemap this tile object belongs to.
|
||||
*/
|
||||
public tilemap: Tilemap;
|
||||
|
||||
/**
|
||||
* The index of this tile type in the core map data.
|
||||
* For example, if your map only has 16 kinds of tiles in it,
|
||||
* this number is usually between 0 and 15.
|
||||
*/
|
||||
public index: number;
|
||||
|
||||
/**
|
||||
* The current map index of this tile object at this moment.
|
||||
* You can think of tile objects as moving around the tilemap helping with collisions.
|
||||
* This value is only reliable and useful if used from the callback function.
|
||||
*/
|
||||
public mapIndex: number;
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
public destroy() {
|
||||
|
||||
super.destroy();
|
||||
this.callback = null;
|
||||
this.tilemap = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+139
-138
@@ -1,172 +1,173 @@
|
||||
/// <reference path="../Game.ts" />
|
||||
/// <reference path="../GameObject.ts" />
|
||||
/// <reference path="../Tilemap.ts" />
|
||||
/// <reference path="../geom/Rectangle.ts" />
|
||||
/// <reference path="Camera.ts" />
|
||||
|
||||
/**
|
||||
* A Tilemap Buffer
|
||||
*
|
||||
* @author Richard Davey
|
||||
*/
|
||||
class TilemapBuffer {
|
||||
|
||||
constructor(game: Game, camera:Camera, tilemap:Tilemap, texture, tileOffsets) {
|
||||
module Phaser {
|
||||
|
||||
//console.log('New TilemapBuffer created for Camera ' + camera.ID);
|
||||
export class TilemapBuffer {
|
||||
|
||||
this._game = game;
|
||||
this.camera = camera;
|
||||
this._tilemap = tilemap;
|
||||
this._texture = texture;
|
||||
this._tileOffsets = tileOffsets;
|
||||
constructor(game: Game, camera: Camera, tilemap: Tilemap, texture, tileOffsets) {
|
||||
|
||||
//this.createCanvas();
|
||||
//console.log('New TilemapBuffer created for Camera ' + camera.ID);
|
||||
|
||||
}
|
||||
this._game = game;
|
||||
this.camera = camera;
|
||||
this._tilemap = tilemap;
|
||||
this._texture = texture;
|
||||
this._tileOffsets = tileOffsets;
|
||||
|
||||
private _game: Game;
|
||||
private _tilemap: Tilemap;
|
||||
private _texture;
|
||||
private _tileOffsets;
|
||||
//this.createCanvas();
|
||||
|
||||
private _startX: number = 0;
|
||||
private _maxX: number = 0;
|
||||
private _startY: number = 0;
|
||||
private _maxY: number = 0;
|
||||
private _tx: number = 0;
|
||||
private _ty: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _oldCameraX: number = 0;
|
||||
private _oldCameraY: number = 0;
|
||||
private _dirty: bool = true;
|
||||
private _columnData;
|
||||
|
||||
public camera: Camera;
|
||||
public canvas: HTMLCanvasElement;
|
||||
public context: CanvasRenderingContext2D;
|
||||
|
||||
private createCanvas() {
|
||||
|
||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
||||
this.canvas.width = this._game.stage.width;
|
||||
this.canvas.height = this._game.stage.height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
/*
|
||||
if (this.camera.worldView.x !== this._oldCameraX || this.camera.worldView.y !== this._oldCameraY)
|
||||
{
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
this._oldCameraX = this.camera.worldView.x;
|
||||
this._oldCameraY = this.camera.worldView.y;
|
||||
*/
|
||||
private _game: Game;
|
||||
private _tilemap: Tilemap;
|
||||
private _texture;
|
||||
private _tileOffsets;
|
||||
|
||||
}
|
||||
private _startX: number = 0;
|
||||
private _maxX: number = 0;
|
||||
private _startY: number = 0;
|
||||
private _maxY: number = 0;
|
||||
private _tx: number = 0;
|
||||
private _ty: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _oldCameraX: number = 0;
|
||||
private _oldCameraY: number = 0;
|
||||
private _dirty: bool = true;
|
||||
private _columnData;
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
public camera: Camera;
|
||||
public canvas: HTMLCanvasElement;
|
||||
public context: CanvasRenderingContext2D;
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('TilemapBuffer', x, y);
|
||||
this._game.stage.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||
this._game.stage.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||
this._game.stage.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||
this._game.stage.context.fillText('Dirty: ' + this._dirty, x, y + 56);
|
||||
|
||||
}
|
||||
private createCanvas() {
|
||||
|
||||
public render(dx, dy): bool {
|
||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
||||
this.canvas.width = this._game.stage.width;
|
||||
this.canvas.height = this._game.stage.height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
/*
|
||||
if (this._dirty == false)
|
||||
{
|
||||
this._game.stage.context.drawImage(this.canvas, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
// Work out how many tiles we can fit into our camera and round it up for the edges
|
||||
this._maxX = this._game.math.ceil(this.camera.width / this._tilemap.tileWidth) + 1;
|
||||
this._maxY = this._game.math.ceil(this.camera.height / this._tilemap.tileHeight) + 1;
|
||||
|
||||
// And now work out where in the tilemap the camera actually is
|
||||
this._startX = this._game.math.floor(this.camera.worldView.x / this._tilemap.tileWidth);
|
||||
this._startY = this._game.math.floor(this.camera.worldView.y / this._tilemap.tileHeight);
|
||||
|
||||
// Tilemap bounds check
|
||||
if (this._startX < 0)
|
||||
{
|
||||
this._startX = 0;
|
||||
}
|
||||
|
||||
if (this._startY < 0)
|
||||
{
|
||||
this._startY = 0;
|
||||
}
|
||||
public update() {
|
||||
|
||||
if (this._startX + this._maxX > this._tilemap.widthInTiles)
|
||||
{
|
||||
this._startX = this._tilemap.widthInTiles - this._maxX;
|
||||
}
|
||||
|
||||
if (this._startY + this._maxY > this._tilemap.heightInTiles)
|
||||
{
|
||||
this._startY = this._tilemap.heightInTiles - this._maxY;
|
||||
}
|
||||
|
||||
// Finally get the offset to avoid the blocky movement
|
||||
this._dx = dx;
|
||||
this._dy = dy;
|
||||
|
||||
this._dx += -(this.camera.worldView.x - (this._startX * this._tilemap.tileWidth));
|
||||
this._dy += -(this.camera.worldView.y - (this._startY * this._tilemap.tileHeight));
|
||||
|
||||
this._tx = this._dx;
|
||||
this._ty = this._dy;
|
||||
|
||||
for (var row = this._startY; row < this._startY + this._maxY; row++)
|
||||
{
|
||||
this._columnData = this._tilemap.mapData[row];
|
||||
|
||||
for (var tile = this._startX; tile < this._startX + this._maxX; tile++)
|
||||
/*
|
||||
if (this.camera.worldView.x !== this._oldCameraX || this.camera.worldView.y !== this._oldCameraY)
|
||||
{
|
||||
if (this._tileOffsets[this._columnData[tile]])
|
||||
{
|
||||
//this.context.drawImage(
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
||||
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
||||
this._tilemap.tileWidth, // Source Width
|
||||
this._tilemap.tileHeight, // Source Height
|
||||
this._tx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._ty, // Destination Y
|
||||
this._tilemap.tileWidth, // Destination Width (always same as Source Width unless scaled)
|
||||
this._tilemap.tileHeight // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
this._dirty = true;
|
||||
}
|
||||
|
||||
this._oldCameraX = this.camera.worldView.x;
|
||||
this._oldCameraY = this.camera.worldView.y;
|
||||
*/
|
||||
|
||||
this._tx += this._tilemap.tileWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('TilemapBuffer', x, y);
|
||||
this._game.stage.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14);
|
||||
this._game.stage.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28);
|
||||
this._game.stage.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42);
|
||||
this._game.stage.context.fillText('Dirty: ' + this._dirty, x, y + 56);
|
||||
|
||||
}
|
||||
|
||||
public render(dx, dy): bool {
|
||||
|
||||
/*
|
||||
if (this._dirty == false)
|
||||
{
|
||||
this._game.stage.context.drawImage(this.canvas, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
// Work out how many tiles we can fit into our camera and round it up for the edges
|
||||
this._maxX = this._game.math.ceil(this.camera.width / this._tilemap.tileWidth) + 1;
|
||||
this._maxY = this._game.math.ceil(this.camera.height / this._tilemap.tileHeight) + 1;
|
||||
|
||||
// And now work out where in the tilemap the camera actually is
|
||||
this._startX = this._game.math.floor(this.camera.worldView.x / this._tilemap.tileWidth);
|
||||
this._startY = this._game.math.floor(this.camera.worldView.y / this._tilemap.tileHeight);
|
||||
|
||||
// Tilemap bounds check
|
||||
if (this._startX < 0)
|
||||
{
|
||||
this._startX = 0;
|
||||
}
|
||||
|
||||
if (this._startY < 0)
|
||||
{
|
||||
this._startY = 0;
|
||||
}
|
||||
|
||||
if (this._startX + this._maxX > this._tilemap.widthInTiles)
|
||||
{
|
||||
this._startX = this._tilemap.widthInTiles - this._maxX;
|
||||
}
|
||||
|
||||
if (this._startY + this._maxY > this._tilemap.heightInTiles)
|
||||
{
|
||||
this._startY = this._tilemap.heightInTiles - this._maxY;
|
||||
}
|
||||
|
||||
// Finally get the offset to avoid the blocky movement
|
||||
this._dx = dx;
|
||||
this._dy = dy;
|
||||
|
||||
this._dx += -(this.camera.worldView.x - (this._startX * this._tilemap.tileWidth));
|
||||
this._dy += -(this.camera.worldView.y - (this._startY * this._tilemap.tileHeight));
|
||||
|
||||
this._tx = this._dx;
|
||||
this._ty += this._tilemap.tileHeight;
|
||||
this._ty = this._dy;
|
||||
|
||||
for (var row = this._startY; row < this._startY + this._maxY; row++)
|
||||
{
|
||||
this._columnData = this._tilemap.mapData[row];
|
||||
|
||||
for (var tile = this._startX; tile < this._startX + this._maxX; tile++)
|
||||
{
|
||||
if (this._tileOffsets[this._columnData[tile]])
|
||||
{
|
||||
//this.context.drawImage(
|
||||
this._game.stage.context.drawImage(
|
||||
this._texture, // Source Image
|
||||
this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image)
|
||||
this._tileOffsets[this._columnData[tile]].y, // Source Y
|
||||
this._tilemap.tileWidth, // Source Width
|
||||
this._tilemap.tileHeight, // Source Height
|
||||
this._tx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._ty, // Destination Y
|
||||
this._tilemap.tileWidth, // Destination Width (always same as Source Width unless scaled)
|
||||
this._tilemap.tileHeight // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
|
||||
this._tx += this._tilemap.tileWidth;
|
||||
}
|
||||
}
|
||||
|
||||
this._tx = this._dx;
|
||||
this._ty += this._tilemap.tileHeight;
|
||||
|
||||
}
|
||||
|
||||
//this._game.stage.context.drawImage(this.canvas, 0, 0);
|
||||
//console.log('dirty cleaned');
|
||||
//this._dirty = false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//this._game.stage.context.drawImage(this.canvas, 0, 0);
|
||||
//console.log('dirty cleaned');
|
||||
//this._dirty = false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
/// <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
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js) converted to TypeScript and integrated into Phaser
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Tween {
|
||||
|
||||
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.onStart = new Phaser.Signal();
|
||||
this.onUpdate = new Phaser.Signal();
|
||||
this.onComplete = new Phaser.Signal();
|
||||
|
||||
}
|
||||
|
||||
private _game: Phaser.Game;
|
||||
private _manager: Phaser.TweenManager;
|
||||
private _object = null;
|
||||
private _pausedTime: number = 0;
|
||||
|
||||
private _valuesStart = {};
|
||||
private _valuesEnd = {};
|
||||
private _duration = 1000;
|
||||
private _delayTime = 0;
|
||||
private _startTime = null;
|
||||
private _easingFunction;
|
||||
private _interpolationFunction;
|
||||
private _chainedTweens = [];
|
||||
|
||||
public onStart: Phaser.Signal;
|
||||
public onUpdate: Phaser.Signal;
|
||||
public onComplete: Phaser.Signal;
|
||||
|
||||
public to(properties, duration?: number = 1000, ease?: any = null, autoStart?: bool = false) {
|
||||
|
||||
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 (autoStart === true)
|
||||
{
|
||||
return this.start();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public stop() {
|
||||
|
||||
if (this._manager !== null)
|
||||
{
|
||||
this._manager.remove(this);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public chain(tween:Phaser.Tween) {
|
||||
|
||||
this._chainedTweens.push(tween);
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public debugValue;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
/**
|
||||
* Animation
|
||||
@@ -13,142 +9,150 @@
|
||||
* @author Richard Davey
|
||||
*/
|
||||
|
||||
class Animation {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game, parent: Sprite, frameData: FrameData, name, frames, delay, looped) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
this._frames = frames;
|
||||
this._frameData = frameData;
|
||||
export class Animation {
|
||||
|
||||
this.name = name;
|
||||
this.delay = 1000 / delay;
|
||||
this.looped = looped;
|
||||
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool) {
|
||||
|
||||
this.isFinished = false;
|
||||
this.isPlaying = false;
|
||||
this._game = game;
|
||||
this._parent = parent;
|
||||
this._frames = frames;
|
||||
this._frameData = frameData;
|
||||
|
||||
}
|
||||
this.name = name;
|
||||
this.delay = 1000 / delay;
|
||||
this.looped = looped;
|
||||
|
||||
private _game: Game;
|
||||
private _parent: Sprite;
|
||||
private _frames: number[];
|
||||
private _frameData: FrameData;
|
||||
private _frameIndex: number;
|
||||
this.isFinished = false;
|
||||
this.isPlaying = false;
|
||||
|
||||
private _timeLastFrame: number;
|
||||
private _timeNextFrame: number;
|
||||
|
||||
public name: string;
|
||||
public currentFrame: Frame;
|
||||
|
||||
public isFinished: bool;
|
||||
public isPlaying: bool;
|
||||
public looped: bool;
|
||||
public delay: number;
|
||||
|
||||
public get frameTotal(): number {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
public get frame(): number {
|
||||
return this._frameIndex;
|
||||
}
|
||||
|
||||
public set frame(value: number) {
|
||||
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
|
||||
if (this.currentFrame !== null)
|
||||
{
|
||||
this._parent.bounds.width = this.currentFrame.width;
|
||||
this._parent.bounds.height = this.currentFrame.height;
|
||||
this._frameIndex = value;
|
||||
}
|
||||
|
||||
}
|
||||
private _game: Game;
|
||||
private _parent: Sprite;
|
||||
private _frames: number[];
|
||||
private _frameData: FrameData;
|
||||
private _frameIndex: number;
|
||||
|
||||
public play(frameRate?: number = null, loop?: bool) {
|
||||
private _timeLastFrame: number;
|
||||
private _timeNextFrame: number;
|
||||
|
||||
if (frameRate !== null)
|
||||
{
|
||||
this.delay = 1000 / frameRate;
|
||||
public name: string;
|
||||
public currentFrame: Frame;
|
||||
|
||||
public isFinished: bool;
|
||||
public isPlaying: bool;
|
||||
public looped: bool;
|
||||
public delay: number;
|
||||
|
||||
public get frameTotal(): number {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
if (loop !== undefined)
|
||||
{
|
||||
this.looped = loop;
|
||||
public get frame(): number {
|
||||
return this._frameIndex;
|
||||
}
|
||||
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
public set frame(value: number) {
|
||||
|
||||
this._timeLastFrame = this._game.time.now;
|
||||
this._timeNextFrame = this._game.time.now + this.delay;
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
}
|
||||
|
||||
private onComplete() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// callback
|
||||
|
||||
}
|
||||
|
||||
public stop() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
|
||||
}
|
||||
|
||||
public update():bool {
|
||||
|
||||
if (this.isPlaying == true && this._game.time.now >= this._timeNextFrame)
|
||||
{
|
||||
this._frameIndex++;
|
||||
|
||||
if (this._frameIndex == this._frames.length)
|
||||
if (this.currentFrame !== null)
|
||||
{
|
||||
if (this.looped)
|
||||
{
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.onComplete();
|
||||
}
|
||||
this._parent.bounds.width = this.currentFrame.width;
|
||||
this._parent.bounds.height = this.currentFrame.height;
|
||||
this._frameIndex = value;
|
||||
}
|
||||
else
|
||||
|
||||
}
|
||||
|
||||
public play(frameRate?: number = null, loop?: bool) {
|
||||
|
||||
if (frameRate !== null)
|
||||
{
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
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;
|
||||
|
||||
return true;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
private onComplete() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
// callback
|
||||
|
||||
}
|
||||
|
||||
public stop() {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
this._game = null;
|
||||
this._parent = null;
|
||||
this._frames = null;
|
||||
this._frameData = null;
|
||||
this.currentFrame = null;
|
||||
this.isPlaying = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
this._game = null;
|
||||
this._parent = null;
|
||||
this._frames = null;
|
||||
this._frameData = null;
|
||||
this.currentFrame = null;
|
||||
this.isPlaying = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,83 +1,86 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
class AnimationLoader {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax:number): FrameData {
|
||||
module Phaser {
|
||||
|
||||
// How big is our image?
|
||||
export class AnimationLoader {
|
||||
|
||||
var img = game.cache.getImage(key);
|
||||
public static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData {
|
||||
|
||||
if (img == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// How big is our image?
|
||||
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
var img = game.cache.getImage(key);
|
||||
|
||||
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)
|
||||
if (img == null)
|
||||
{
|
||||
x = 0;
|
||||
y += frameHeight;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
public static parseJSONData(game: Game, json): FrameData {
|
||||
|
||||
// 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 parseJSONData(game: Game, json): FrameData {
|
||||
|
||||
// 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +1,72 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="FrameData.ts" />
|
||||
|
||||
class Frame {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(x: number, y: number, width: number, height: number, name: string) {
|
||||
module Phaser {
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.name = name;
|
||||
export class Frame {
|
||||
|
||||
this.rotated = false;
|
||||
this.trimmed = false;
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
// Position within the image to cut from
|
||||
public x: number;
|
||||
public y: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
|
||||
// Useful for Sprite Sheets
|
||||
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?
|
||||
public trimmed: bool;
|
||||
|
||||
// The coordinates of the trimmed sprite inside the original sprite
|
||||
public sourceSizeW: number;
|
||||
public sourceSizeH: number;
|
||||
public spriteSourceSizeX: number;
|
||||
public spriteSourceSizeY: number;
|
||||
public spriteSourceSizeW: number;
|
||||
public spriteSourceSizeH: number;
|
||||
|
||||
public setRotation(rotated: bool, rotationDirection: string) {
|
||||
// Not yet supported
|
||||
}
|
||||
|
||||
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight, ) {
|
||||
|
||||
this.trimmed = trimmed;
|
||||
|
||||
this.sourceSizeW = actualWidth;
|
||||
this.sourceSizeH = actualHeight;
|
||||
this.spriteSourceSizeX = destX;
|
||||
this.spriteSourceSizeY = destY;
|
||||
this.spriteSourceSizeW = destWidth;
|
||||
this.spriteSourceSizeH = destHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Position within the image to cut from
|
||||
public x: number;
|
||||
public y: number;
|
||||
public width: number;
|
||||
public height: number;
|
||||
|
||||
// Useful for Sprite Sheets
|
||||
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?
|
||||
public trimmed: bool;
|
||||
|
||||
// The coordinates of the trimmed sprite inside the original sprite
|
||||
public sourceSizeW: number;
|
||||
public sourceSizeH: number;
|
||||
public spriteSourceSizeX: number;
|
||||
public spriteSourceSizeY: number;
|
||||
public spriteSourceSizeW: number;
|
||||
public spriteSourceSizeH: number;
|
||||
|
||||
public setRotation(rotated: bool, rotationDirection: string) {
|
||||
// Not yet supported
|
||||
}
|
||||
|
||||
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight, ) {
|
||||
|
||||
this.trimmed = trimmed;
|
||||
|
||||
this.sourceSizeW = actualWidth;
|
||||
this.sourceSizeH = actualHeight;
|
||||
this.spriteSourceSizeX = destX;
|
||||
this.spriteSourceSizeY = destY;
|
||||
this.spriteSourceSizeW = destWidth;
|
||||
this.spriteSourceSizeH = destHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,100 +1,131 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Sprite.ts" />
|
||||
/// <reference path="Animation.ts" />
|
||||
/// <reference path="AnimationLoader.ts" />
|
||||
/// <reference path="Frame.ts" />
|
||||
|
||||
class FrameData {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor() {
|
||||
module Phaser {
|
||||
|
||||
this._frames = [];
|
||||
this._frameNames = [];
|
||||
export class FrameData {
|
||||
|
||||
}
|
||||
constructor() {
|
||||
|
||||
private _frames: Frame[];
|
||||
private _frameNames;
|
||||
this._frames = [];
|
||||
this._frameNames = [];
|
||||
|
||||
public get total(): number {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
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;
|
||||
private _frames: Frame[];
|
||||
private _frameNames;
|
||||
|
||||
}
|
||||
|
||||
public getFrame(index: number):Frame {
|
||||
|
||||
if (this._frames[index])
|
||||
{
|
||||
return this._frames[index];
|
||||
public get total(): number {
|
||||
return this._frames.length;
|
||||
}
|
||||
|
||||
return null;
|
||||
public addFrame(frame: Frame): Frame {
|
||||
|
||||
}
|
||||
frame.index = this._frames.length;
|
||||
|
||||
public getFrameByName(name: string):Frame {
|
||||
this._frames.push(frame);
|
||||
|
||||
if (frame.name !== '')
|
||||
{
|
||||
this._frameNames[frame.name] = frame.index;
|
||||
}
|
||||
|
||||
return frame;
|
||||
|
||||
if (this._frameNames[name] >= 0)
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
|
||||
return null;
|
||||
public getFrame(index: number): Frame {
|
||||
|
||||
}
|
||||
if (this._frames[index])
|
||||
{
|
||||
return this._frames[index];
|
||||
}
|
||||
|
||||
public getFrameRange(start: number, end: number, output?:Frame[] = []):Frame[] {
|
||||
return null;
|
||||
|
||||
for (var i = start; i <= end; i++)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
public getFrameByName(name: string): Frame {
|
||||
|
||||
}
|
||||
if (this._frameNames[name] >= 0)
|
||||
{
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
|
||||
public getFrameIndexes(output?:number[] = []):number[] {
|
||||
return null;
|
||||
|
||||
output.length = 0;
|
||||
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
output.push(i);
|
||||
}
|
||||
|
||||
return output;
|
||||
public checkFrameName(name: string): bool {
|
||||
|
||||
}
|
||||
if (this._frameNames[name] >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public getAllFrames():Frame[] {
|
||||
return this._frames;
|
||||
}
|
||||
return false;
|
||||
|
||||
public getFrames(range: number[]) {
|
||||
|
||||
var output: Frame[] = [];
|
||||
|
||||
for (var i = 0; i < range.length; i++)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
public getFrameRange(start: number, end: number, output?: Frame[] = []): Frame[] {
|
||||
|
||||
for (var i = start; i <= end; i++)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
public getFrameIndexes(output?: number[] = []): number[] {
|
||||
|
||||
output.length = 0;
|
||||
|
||||
for (var i = 0; i < this._frames.length; i++)
|
||||
{
|
||||
output.push(i);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public getAllFrames(): Frame[] {
|
||||
return this._frames;
|
||||
}
|
||||
|
||||
public getFrames(range: number[]) {
|
||||
|
||||
var output: Frame[] = [];
|
||||
|
||||
for (var i = 0; i < range.length; i++)
|
||||
{
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
module Phaser.Easing {
|
||||
|
||||
export class Linear {
|
||||
|
||||
public static None(k) {
|
||||
|
||||
return k;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Easing
|
||||
*
|
||||
* @desc Based heavily on tween.js by sole (https://github.com/sole/tween.js)
|
||||
*
|
||||
* @version 1.0 - 11th January 2013
|
||||
*
|
||||
* @author Richard Davey, TypeScript conversion and Phaser integration. See Phaser.TweenManager for the full tween.js author list
|
||||
*/
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+295
-290
@@ -1,6 +1,4 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../geom/Point.ts" />
|
||||
/// <reference path="../../geom/Circle.ts" />
|
||||
|
||||
/**
|
||||
* Input - Finger
|
||||
@@ -13,311 +11,318 @@
|
||||
* @todo Lots
|
||||
*/
|
||||
|
||||
class Finger {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Kiwi.Game} game.
|
||||
* @return {Kiwi.Input.Finger} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
this.active = false;
|
||||
export class Finger {
|
||||
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Finger} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _game
|
||||
* @type Kiwi.Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
this._game = game;
|
||||
this.active = false;
|
||||
|
||||
/**
|
||||
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
|
||||
* @property identifier
|
||||
* @type Number
|
||||
*/
|
||||
public identifier: number;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property active
|
||||
* @type Boolean
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property point
|
||||
* @type Point
|
||||
**/
|
||||
public point: Point = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property circle
|
||||
* @type Circle
|
||||
**/
|
||||
public circle: Circle = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type Boolean
|
||||
*/
|
||||
public withinGame: bool = false;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
public isUp: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property timeDown
|
||||
* @type Number
|
||||
**/
|
||||
public timeDown: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property duration
|
||||
* @type Number
|
||||
**/
|
||||
public duration: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property timeUp
|
||||
* @type Number
|
||||
**/
|
||||
public timeUp: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property justPressedRate
|
||||
* @type Number
|
||||
**/
|
||||
public justPressedRate: number = 200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property justReleasedRate
|
||||
* @type Number
|
||||
**/
|
||||
public justReleasedRate: number = 200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
public start(event) {
|
||||
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
|
||||
// populate geom objects
|
||||
if (this.point === null)
|
||||
{
|
||||
this.point = new Point();
|
||||
}
|
||||
|
||||
if (this.circle === null)
|
||||
{
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
/**
|
||||
*
|
||||
* @property _game
|
||||
* @type Phaser.Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
|
||||
* @property identifier
|
||||
* @type Number
|
||||
*/
|
||||
public identifier: number;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property active
|
||||
* @type Boolean
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property point
|
||||
* @type Point
|
||||
**/
|
||||
public point: Point = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property circle
|
||||
* @type Circle
|
||||
**/
|
||||
public circle: Circle = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type Boolean
|
||||
*/
|
||||
public withinGame: bool = false;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
public isUp: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property timeDown
|
||||
* @type Number
|
||||
**/
|
||||
public timeDown: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property duration
|
||||
* @type Number
|
||||
**/
|
||||
public duration: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property timeUp
|
||||
* @type Number
|
||||
**/
|
||||
public timeUp: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property justPressedRate
|
||||
* @type Number
|
||||
**/
|
||||
public justPressedRate: number = 200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property justReleasedRate
|
||||
* @type Number
|
||||
**/
|
||||
public justReleasedRate: number = 200;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
public start(event) {
|
||||
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
|
||||
// populate geom objects
|
||||
if (this.point === null)
|
||||
{
|
||||
this.point = new Point();
|
||||
}
|
||||
|
||||
if (this.circle === null)
|
||||
{
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
}
|
||||
|
||||
this.move(event);
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
|
||||
}
|
||||
|
||||
this.move(event);
|
||||
/**
|
||||
*
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
public move(event) {
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
public move(event) {
|
||||
this.point.setTo(this.x, this.y);
|
||||
this.circle.setTo(this.x, this.y, 44);
|
||||
|
||||
this.clientX = event.clientX;
|
||||
this.clientY = event.clientY;
|
||||
this.pageX = event.pageX;
|
||||
this.pageY = event.pageY;
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
// Droppings history (used for gestures and motion tracking)
|
||||
|
||||
this.x = this.pageX - this._game.stage.offset.x;
|
||||
this.y = this.pageY - this._game.stage.offset.y;
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
|
||||
this.point.setTo(this.x, this.y);
|
||||
this.circle.setTo(this.x, this.y, 44);
|
||||
|
||||
// Droppings history (used for gestures and motion tracking)
|
||||
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
public leave(event) {
|
||||
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
public stop(event) {
|
||||
|
||||
this.active = false;
|
||||
this.withinGame = false;
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public justPressed(duration?: number = this.justPressedRate): bool {
|
||||
|
||||
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
public leave(event) {
|
||||
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
public stop(event) {
|
||||
|
||||
this.active = false;
|
||||
this.withinGame = false;
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public justPressed(duration?: number = this.justPressedRate): bool {
|
||||
|
||||
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public justReleased(duration?: number = this.justReleasedRate): bool {
|
||||
|
||||
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
public toString(): string {
|
||||
|
||||
return "[{Finger (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 + ")}]";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public justReleased(duration?: number = this.justReleasedRate): bool {
|
||||
|
||||
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
public toString(): string {
|
||||
|
||||
return "[{Finger (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 + ")}]";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +1,81 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Mouse.ts" />
|
||||
/// <reference path="Keyboard.ts" />
|
||||
/// <reference path="Touch.ts" />
|
||||
|
||||
class Input {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
export class Input {
|
||||
|
||||
this.mouse = new Mouse(this._game);
|
||||
this.keyboard = new Keyboard(this._game);
|
||||
this.touch = new Touch(this._game);
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
this.mouse = new Mouse(this._game);
|
||||
this.keyboard = new Keyboard(this._game);
|
||||
this.touch = new Touch(this._game);
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
public mouse: Mouse;
|
||||
public keyboard: Keyboard;
|
||||
public touch: Touch;
|
||||
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
|
||||
public scaleX: number = 1;
|
||||
public scaleY: number = 1;
|
||||
|
||||
public worldX: number = 0;
|
||||
public worldY: number = 0;
|
||||
|
||||
public update() {
|
||||
|
||||
this.x = Math.round(this.x);
|
||||
this.y = Math.round(this.y);
|
||||
|
||||
this.worldX = this._game.camera.worldView.x + this.x;
|
||||
this.worldY = this._game.camera.worldView.y + this.y;
|
||||
|
||||
this.mouse.update();
|
||||
this.touch.update();
|
||||
|
||||
}
|
||||
|
||||
public reset() {
|
||||
|
||||
this.mouse.reset();
|
||||
this.keyboard.reset();
|
||||
this.touch.reset();
|
||||
|
||||
}
|
||||
|
||||
public getWorldX(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
public getWorldY(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
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.worldX + ' World Y: ' + this.worldY, x, y + 28);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
public mouse: Mouse;
|
||||
public keyboard: Keyboard;
|
||||
public touch: Touch;
|
||||
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
|
||||
public scaleX: number = 1;
|
||||
public scaleY: number = 1;
|
||||
|
||||
public worldX: number = 0;
|
||||
public worldY: number = 0;
|
||||
|
||||
public update() {
|
||||
|
||||
this.x = Math.round(this.x);
|
||||
this.y = Math.round(this.y);
|
||||
|
||||
this.worldX = this._game.camera.worldView.x + this.x;
|
||||
this.worldY = this._game.camera.worldView.y + this.y;
|
||||
|
||||
this.mouse.update();
|
||||
this.touch.update();
|
||||
|
||||
}
|
||||
|
||||
public reset() {
|
||||
|
||||
this.mouse.reset();
|
||||
this.keyboard.reset();
|
||||
this.touch.reset();
|
||||
|
||||
}
|
||||
|
||||
public getWorldX(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
public getWorldY(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
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.worldX + ' World Y: ' + this.worldY, x, y + 28);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+234
-207
@@ -1,214 +1,241 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Input.ts" />
|
||||
|
||||
class Keyboard {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
this.start();
|
||||
export class Keyboard {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
this.start();
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
private _keys = {};
|
||||
private _capture = {};
|
||||
|
||||
public start() {
|
||||
|
||||
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
|
||||
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
|
||||
|
||||
}
|
||||
|
||||
public addKeyCapture(keycode: number) {
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
|
||||
public removeKeyCapture(keycode: number) {
|
||||
delete this._capture[keycode];
|
||||
}
|
||||
|
||||
public clearCaptures() {
|
||||
|
||||
this._capture = {};
|
||||
|
||||
}
|
||||
|
||||
public onKeyDown(event: KeyboardEvent) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public onKeyUp(event: KeyboardEvent) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
|
||||
private _keys = {};
|
||||
|
||||
public start() {
|
||||
|
||||
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
|
||||
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
|
||||
|
||||
}
|
||||
|
||||
public onKeyDown(event: KeyboardEvent) {
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public onKeyUp(event: KeyboardEvent) {
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,101 +1,108 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Input.ts" />
|
||||
|
||||
class Mouse {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
this.start();
|
||||
export class Mouse {
|
||||
|
||||
}
|
||||
constructor(game: Game) {
|
||||
|
||||
private _game: Game;
|
||||
this._game = game;
|
||||
this.start();
|
||||
|
||||
private _x: number = 0;
|
||||
private _y: number = 0;
|
||||
}
|
||||
|
||||
public button: number;
|
||||
private _game: Game;
|
||||
|
||||
public static LEFT_BUTTON: number = 0;
|
||||
public static MIDDLE_BUTTON: number = 1;
|
||||
public static RIGHT_BUTTON: number = 2;
|
||||
private _x: number = 0;
|
||||
private _y: number = 0;
|
||||
|
||||
public isDown: bool = false;
|
||||
public isUp: bool = true;
|
||||
public timeDown: number = 0;
|
||||
public duration: number = 0;
|
||||
public timeUp: number = 0;
|
||||
public button: number;
|
||||
|
||||
public start() {
|
||||
public static LEFT_BUTTON: number = 0;
|
||||
public static MIDDLE_BUTTON: number = 1;
|
||||
public static RIGHT_BUTTON: number = 2;
|
||||
|
||||
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);
|
||||
public isDown: bool = false;
|
||||
public isUp: bool = true;
|
||||
public timeDown: number = 0;
|
||||
public duration: number = 0;
|
||||
public timeUp: number = 0;
|
||||
|
||||
}
|
||||
|
||||
public reset() {
|
||||
public start() {
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public onMouseDown(event: MouseEvent) {
|
||||
public reset() {
|
||||
|
||||
this.button = event.button;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
}
|
||||
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
public onMouseDown(event: MouseEvent) {
|
||||
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
this.button = event.button;
|
||||
|
||||
}
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
|
||||
public update() {
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
//this._game.input.x = this._x * this._game.input.scaleX;
|
||||
//this._game.input.y = this._y * this._game.input.scaleY;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
//this._game.input.x = this._x * this._game.input.scaleX;
|
||||
//this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
if (this.isDown)
|
||||
{
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public onMouseMove(event: MouseEvent) {
|
||||
|
||||
this.button = event.button;
|
||||
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
}
|
||||
|
||||
public onMouseUp(event: MouseEvent) {
|
||||
|
||||
this.button = event.button;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
if (this.isDown)
|
||||
{
|
||||
this.duration = this._game.time.now - this.timeDown;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public onMouseMove(event: MouseEvent) {
|
||||
|
||||
this.button = event.button;
|
||||
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
}
|
||||
|
||||
public onMouseUp(event: MouseEvent) {
|
||||
|
||||
this.button = event.button;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.timeUp = this._game.time.now;
|
||||
this.duration = this.timeUp - this.timeDown;
|
||||
|
||||
this._x = event.clientX - this._game.stage.x;
|
||||
this._y = event.clientY - this._game.stage.y;
|
||||
|
||||
this._game.input.x = this._x * this._game.input.scaleX;
|
||||
this._game.input.y = this._y * this._game.input.scaleY;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+390
-384
@@ -1,5 +1,4 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Signal.ts" />
|
||||
/// <reference path="Finger.ts" />
|
||||
|
||||
/**
|
||||
@@ -20,430 +19,437 @@
|
||||
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
|
||||
*/
|
||||
|
||||
class Touch {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
export class Touch {
|
||||
|
||||
this.finger1 = new Finger(this._game);
|
||||
this.finger2 = new Finger(this._game);
|
||||
this.finger3 = new Finger(this._game);
|
||||
this.finger4 = new Finger(this._game);
|
||||
this.finger5 = new Finger(this._game);
|
||||
this.finger6 = new Finger(this._game);
|
||||
this.finger7 = new Finger(this._game);
|
||||
this.finger8 = new Finger(this._game);
|
||||
this.finger9 = new Finger(this._game);
|
||||
this.finger10 = new Finger(this._game);
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
|
||||
this._game = game;
|
||||
|
||||
this.touchDown = new Signal();
|
||||
this.touchUp = new Signal();
|
||||
this.finger1 = new Finger(this._game);
|
||||
this.finger2 = new Finger(this._game);
|
||||
this.finger3 = new Finger(this._game);
|
||||
this.finger4 = new Finger(this._game);
|
||||
this.finger5 = new Finger(this._game);
|
||||
this.finger6 = new Finger(this._game);
|
||||
this.finger7 = new Finger(this._game);
|
||||
this.finger8 = new Finger(this._game);
|
||||
this.finger9 = new Finger(this._game);
|
||||
this.finger10 = new Finger(this._game);
|
||||
|
||||
this.start();
|
||||
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
|
||||
|
||||
}
|
||||
this.touchDown = new Signal();
|
||||
this.touchUp = new Signal();
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _game
|
||||
* @type Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
this.start();
|
||||
|
||||
/**
|
||||
*
|
||||
* @property x
|
||||
* @type Number
|
||||
**/
|
||||
public x: number = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @property y
|
||||
* @type Number
|
||||
**/
|
||||
public y: number = 0;
|
||||
/**
|
||||
*
|
||||
* @property _game
|
||||
* @type Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _fingers
|
||||
* @type Array
|
||||
* @private
|
||||
**/
|
||||
private _fingers: Finger[];
|
||||
/**
|
||||
*
|
||||
* @property x
|
||||
* @type Number
|
||||
**/
|
||||
public x: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger1
|
||||
* @type Finger
|
||||
**/
|
||||
public finger1: Finger;
|
||||
/**
|
||||
*
|
||||
* @property y
|
||||
* @type Number
|
||||
**/
|
||||
public y: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger2
|
||||
* @type Finger
|
||||
**/
|
||||
public finger2: Finger;
|
||||
/**
|
||||
*
|
||||
* @property _fingers
|
||||
* @type Array
|
||||
* @private
|
||||
**/
|
||||
private _fingers: Finger[];
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger3
|
||||
* @type Finger
|
||||
**/
|
||||
public finger3: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger1
|
||||
* @type Finger
|
||||
**/
|
||||
public finger1: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger4
|
||||
* @type Finger
|
||||
**/
|
||||
public finger4: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger2
|
||||
* @type Finger
|
||||
**/
|
||||
public finger2: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger5
|
||||
* @type Finger
|
||||
**/
|
||||
public finger5: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger3
|
||||
* @type Finger
|
||||
**/
|
||||
public finger3: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger6
|
||||
* @type Finger
|
||||
**/
|
||||
public finger6: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger4
|
||||
* @type Finger
|
||||
**/
|
||||
public finger4: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger7
|
||||
* @type Finger
|
||||
**/
|
||||
public finger7: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger5
|
||||
* @type Finger
|
||||
**/
|
||||
public finger5: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger8
|
||||
* @type Finger
|
||||
**/
|
||||
public finger8: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger6
|
||||
* @type Finger
|
||||
**/
|
||||
public finger6: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger9
|
||||
* @type Finger
|
||||
**/
|
||||
public finger9: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger7
|
||||
* @type Finger
|
||||
**/
|
||||
public finger7: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger10
|
||||
* @type Finger
|
||||
**/
|
||||
public finger10: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger8
|
||||
* @type Finger
|
||||
**/
|
||||
public finger8: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property latestFinger
|
||||
* @type Finger
|
||||
**/
|
||||
public latestFinger: Finger;
|
||||
/**
|
||||
*
|
||||
* @property finger9
|
||||
* @type Finger
|
||||
**/
|
||||
public finger9: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
/**
|
||||
*
|
||||
* @property finger10
|
||||
* @type Finger
|
||||
**/
|
||||
public finger10: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
public isUp: bool = true;
|
||||
/**
|
||||
*
|
||||
* @property latestFinger
|
||||
* @type Finger
|
||||
**/
|
||||
public latestFinger: Finger;
|
||||
|
||||
public touchDown: Signal;
|
||||
public touchUp: Signal;
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* @type Boolean
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
*/
|
||||
public start() {
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type Boolean
|
||||
**/
|
||||
public isUp: bool = true;
|
||||
|
||||
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);
|
||||
public touchDown: Signal;
|
||||
public touchUp: Signal;
|
||||
|
||||
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
|
||||
/**
|
||||
*
|
||||
* @method start
|
||||
*/
|
||||
public start() {
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
/**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private consumeTouchMove(event) {
|
||||
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private consumeTouchMove(event) {
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchStart(event) {
|
||||
event.preventDefault();
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
// A list of all the touch points that BECAME active with the current event
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
/**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchStart(event) {
|
||||
|
||||
// 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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
event.preventDefault();
|
||||
|
||||
// A list of all the touch points that BECAME active with the current event
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
|
||||
// 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++)
|
||||
{
|
||||
if (this._fingers[f].active === false)
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
break;
|
||||
if (this._fingers[f].active === false)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchCancel(event) {
|
||||
|
||||
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
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchEnter(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// 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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].active === false)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchLeave(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].leave(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchMove(event) {
|
||||
|
||||
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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].move(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateDistance
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateDistance(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateAngle
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateAngle(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method checkOverlap
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public checkOverlap(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method update
|
||||
*/
|
||||
public update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method reset
|
||||
**/
|
||||
public reset() {
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchCancel(event) {
|
||||
|
||||
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
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchEnter(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// 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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].active === false)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchLeave(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].leave(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchMove(event) {
|
||||
|
||||
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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].move(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateDistance
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateDistance(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateAngle
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateAngle(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method checkOverlap
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public checkOverlap(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method update
|
||||
*/
|
||||
public update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method stop
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method reset
|
||||
**/
|
||||
public reset() {
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user