Version 0.7 release. StageScaleMode support added and world input values exposed.

This commit is contained in:
Richard Davey
2013-04-14 02:31:00 +01:00
parent 0541e93db4
commit ebf83609ae
18 changed files with 9289 additions and 271 deletions
+28 -6
View File
@@ -21,11 +21,23 @@ class Input {
public keyboard: Keyboard;
public touch: Touch;
public x: number;
public y: number;
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();
@@ -39,15 +51,25 @@ class Input {
}
public getWorldX(camera: Camera): number {
public getWorldX(camera?: Camera = this._game.camera) {
return this.x;
return camera.worldView.x + this.x;
}
public getWorldY(camera: Camera): number {
public getWorldY(camera?: Camera = this._game.camera) {
return this.y;
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);
}
+4
View File
@@ -23,6 +23,8 @@ class Keyboard {
public onKeyDown(event: KeyboardEvent) {
event.preventDefault();
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: true, timeDown: this._game.time.now, timeUp: 0 };
@@ -37,6 +39,8 @@ class Keyboard {
public onKeyUp(event: KeyboardEvent) {
event.preventDefault();
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this._game.time.now };
+11 -2
View File
@@ -49,6 +49,9 @@ class Mouse {
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;
this.isDown = true;
this.isUp = false;
this.timeDown = this._game.time.now;
@@ -57,8 +60,8 @@ class Mouse {
public update() {
this._game.input.x = this._x;
this._game.input.y = this._y;
//this._game.input.x = this._x * this._game.input.scaleX;
//this._game.input.y = this._y * this._game.input.scaleY;
if (this.isDown)
{
@@ -74,6 +77,9 @@ class Mouse {
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) {
@@ -87,6 +93,9 @@ class Mouse {
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;
}
}
+8 -4
View File
@@ -64,14 +64,14 @@ class Touch {
* @property x
* @type Number
**/
public x: number;
public x: number = 0;
/**
*
* @property y
* @type Number
**/
public y: number;
public y: number = 0;
/**
*
@@ -227,6 +227,8 @@ class Touch {
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;
@@ -338,6 +340,8 @@ class Touch {
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;
}
}
@@ -367,6 +371,8 @@ class Touch {
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;
@@ -410,8 +416,6 @@ class Touch {
*/
public update() {
this._game.input.x = this.x;
this._game.input.y = this.y;
}