21 Commits
Author SHA1 Message Date
Richard Davey b5b5a99dce Preparing for 0.9.6 work 2013-05-02 20:54:28 +01:00
Richard Davey be982b4322 Updated readme and new minified build 2013-05-02 14:03:41 +01:00
Richard Davey 493380a51e Updated readme for official release. 2013-05-02 05:20:01 +01:00
Richard Davey 0a08e1ae0e Removed un-needed file and added SoundManager fix. 2013-05-02 05:16:16 +01:00
Richard Davey e39073d07b Updated readme 2013-05-02 05:02:05 +01:00
Richard Davey 54a5e6477c Lots of new tile map commands and tests. 2013-05-02 05:01:34 +01:00
Richard Davey 2a5b6ef12a Large Tilemap collision overhaul. Proper callback support, optimised collision checks and lots more. 2013-05-02 03:37:45 +01:00
Richard Davey e62b300a25 Added Camera Mirror FX and test case. 2013-05-02 01:02:06 +01:00
Richard Davey 7d98a1bb9d New FXManager system and Camera FX now in place. 2013-05-01 04:10:21 +01:00
Richard Davey c5cccf3283 Large refactoring of the pause and boot screens in Stage and various other small fixes 2013-04-29 02:41:19 +01:00
Richard Davey 9f23c378a1 0.9.4 release 2013-04-28 22:10:12 +01:00
Richard Davey b6f8a3fba6 Final 0.9.4 release 2013-04-28 22:10:11 +01:00
Richard Davey cb9cb6e894 Github Bug Fixes 2013-04-28 22:04:37 +01:00
Richard Davey e948f1e3be Fixed daft issue in Camera and fully implemented tilemap collision. 2013-04-28 22:04:36 +01:00
Richard Davey 4c21ac0d87 Tilemap collision is now working but all Camera following seems to be broken as a result. Awesome. 2013-04-28 22:04:36 +01:00
Richard Davey db9b8ec370 Merge pull request #11 from HackManiac/amd
Automatic creation of UMD wrapped variant of Phaser
2013-04-28 13:37:09 -07:00
HackManiacandDaniel Wippermann f66e0e9254 Automatic creation of UMD wrapped variant of Phaser 2013-04-26 16:35:32 +02:00
Richard Davey 2087b2d76e tidying up 2013-04-26 00:24:58 +01:00
Richard Davey b2e1434f5e Tilemap collision working but needs speeding up 2013-04-25 20:05:56 +01:00
Richard Davey b8ab13fec8 Getting tilemap collision up and running 2013-04-25 01:55:56 +01:00
Richard Davey 53d8e4da2e Fixed Game.boot syntax error. 2013-04-24 09:37:29 +01:00
180 changed files with 52405 additions and 2307 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

+37 -10
View File
@@ -2,7 +2,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-typescript'); grunt.loadNpmTasks('grunt-typescript');
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-copy');
grunt.initConfig({ grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON('package.json'),
typescript: { typescript: {
@@ -14,18 +14,45 @@ module.exports = function (grunt) {
} }
} }
}, },
copy: { copy: {
main: { main: {
files: [ files: [{
{src: 'build/phaser.js', dest: 'Tests/phaser.js'} src: 'build/phaser.js',
]} dest: 'Tests/phaser.js'
}, }]
watch: { },
amd: {
files: [{
src: 'build/phaser.js',
dest: 'build/phaser.amd.js'
}],
options: {
processContent: function(content) {
var replacement = [
'(function (root, factory) {',
' if (typeof exports === \'object\') {',
' module.exports = factory();',
' } else if (typeof define === \'function\' && define.amd) {',
' define(factory);',
' } else {',
' root.Phaser = factory();',
' }',
'}(this, function () {',
content,
'return Phaser;',
'}));'
];
return replacement.join('\n');
}
}
}
},
watch: {
files: '**/*.ts', files: '**/*.ts',
tasks: ['typescript', 'copy'] tasks: ['typescript', 'copy']
} }
}); });
grunt.registerTask('default', ['watch']); grunt.registerTask('default', ['watch']);
} }
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="Game.d.ts" />
/// <reference path="gameobjects/Sprite.d.ts" />
/// <reference path="system/animation/Animation.d.ts" />
/// <reference path="system/animation/AnimationLoader.d.ts" />
/// <reference path="system/animation/Frame.d.ts" />
/// <reference path="system/animation/FrameData.d.ts" />
module Phaser {
class AnimationManager {
constructor(game: Game, parent: Sprite);
private _game;
private _parent;
private _anims;
private _frameIndex;
private _frameData;
public currentAnim: Animation;
public currentFrame: Frame;
public loadFrameData(frameData: FrameData): void;
public add(name: string, frames?: any[], frameRate?: number, loop?: bool, useNumericIndex?: bool): void;
private validateFrames(frames, useNumericIndex);
public play(name: string, frameRate?: number, loop?: bool): void;
public stop(name: string): void;
public update(): void;
public frameData : FrameData;
public frameTotal : number;
public frame : number;
public frameName : string;
}
}
+23
View File
@@ -0,0 +1,23 @@
/// <reference path="Game.d.ts" />
module Phaser {
class Basic {
constructor(game: Game);
public _game: Game;
public name: string;
public ID: number;
public isGroup: bool;
public exists: bool;
public active: bool;
public visible: bool;
public alive: bool;
public ignoreDrawDebug: bool;
public destroy(): void;
public preUpdate(): void;
public update(): void;
public postUpdate(): void;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): void;
public kill(): void;
public revive(): void;
public toString(): string;
}
}
+26
View File
@@ -0,0 +1,26 @@
/// <reference path="Game.d.ts" />
module Phaser {
class Cache {
constructor(game: Game);
private _game;
private _canvases;
private _images;
private _sounds;
private _text;
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D): void;
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number): void;
public addTextureAtlas(key: string, url: string, data, jsonData): void;
public addImage(key: string, url: string, data): void;
public addSound(key: string, url: string, data): void;
public decodedSound(key: string, data): void;
public addText(key: string, url: string, data): void;
public getCanvas(key: string);
public getImage(key: string);
public getFrameData(key: string): FrameData;
public getSound(key: string);
public isSoundDecoded(key: string): bool;
public isSpriteSheet(key: string): bool;
public getText(key: string);
public destroy(): void;
}
}
+17
View File
@@ -0,0 +1,17 @@
/// <reference path="Game.d.ts" />
/// <reference path="system/Camera.d.ts" />
module Phaser {
class CameraManager {
constructor(game: Game, x: number, y: number, width: number, height: number);
private _game;
private _cameras;
private _cameraInstance;
public current: Camera;
public getAll(): Camera[];
public update(): void;
public render(): void;
public addCamera(x: number, y: number, width: number, height: number): Camera;
public removeCamera(id: number): bool;
public destroy(): void;
}
}
+53
View File
@@ -0,0 +1,53 @@
/// <reference path="Game.d.ts" />
/// <reference path="geom/Point.d.ts" />
/// <reference path="geom/Rectangle.d.ts" />
/// <reference path="geom/Quad.d.ts" />
/// <reference path="geom/Circle.d.ts" />
/// <reference path="geom/Line.d.ts" />
/// <reference path="geom/IntersectResult.d.ts" />
/// <reference path="system/QuadTree.d.ts" />
module Phaser {
class Collision {
constructor(game: Game);
private _game;
static LEFT: number;
static RIGHT: number;
static UP: number;
static DOWN: number;
static NONE: number;
static CEILING: number;
static FLOOR: number;
static WALL: number;
static ANY: number;
static OVERLAP_BIAS: number;
static TILE_OVERLAP: bool;
static _tempBounds: Quad;
static lineToLine(line1: Line, line2: Line, output?: IntersectResult): IntersectResult;
static lineToLineSegment(line: Line, seg: Line, output?: IntersectResult): IntersectResult;
static lineToRawSegment(line: Line, x1: number, y1: number, x2: number, y2: number, output?: IntersectResult): IntersectResult;
static lineToRay(line1: Line, ray: Line, output?: IntersectResult): IntersectResult;
static lineToCircle(line: Line, circle: Circle, output?: IntersectResult): IntersectResult;
static lineToRectangle(line: Line, rect: Rectangle, output?: IntersectResult): IntersectResult;
static lineSegmentToLineSegment(line1: Line, line2: Line, output?: IntersectResult): IntersectResult;
static lineSegmentToRay(line: Line, ray: Line, output?: IntersectResult): IntersectResult;
static lineSegmentToCircle(seg: Line, circle: Circle, output?: IntersectResult): IntersectResult;
static lineSegmentToRectangle(seg: Line, rect: Rectangle, output?: IntersectResult): IntersectResult;
static rayToRectangle(ray: Line, rect: Rectangle, output?: IntersectResult): IntersectResult;
static rayToLineSegment(rayX1, rayY1, rayX2, rayY2, lineX1, lineY1, lineX2, lineY2, output?: IntersectResult): IntersectResult;
static pointToRectangle(point, rect: Rectangle, output?: IntersectResult): IntersectResult;
static rectangleToRectangle(rect1: Rectangle, rect2: Rectangle, output?: IntersectResult): IntersectResult;
static rectangleToCircle(rect: Rectangle, circle: Circle, output?: IntersectResult): IntersectResult;
static circleToCircle(circle1: Circle, circle2: Circle, output?: IntersectResult): IntersectResult;
static circleToRectangle(circle: Circle, rect: Rectangle, output?: IntersectResult): IntersectResult;
static circleContainsPoint(circle: Circle, point, output?: IntersectResult): IntersectResult;
public overlap(object1?: Basic, object2?: Basic, notifyCallback?, processCallback?): bool;
static separate(object1, object2): bool;
static separateTile(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool, collideUp: bool, collideDown: bool): bool;
static separateTileX(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideLeft: bool, collideRight: bool): bool;
static separateTileY(object: GameObject, x: number, y: number, width: number, height: number, mass: number, collideUp: bool, collideDown: bool): bool;
static separateX(object1, object2): bool;
static separateY(object1, object2): bool;
static distance(x1: number, y1: number, x2: number, y2: number): number;
static distanceSquared(x1: number, y1: number, x2: number, y2: number): number;
}
}
+550 -387
View File
File diff suppressed because it is too large Load Diff
+32
View File
@@ -0,0 +1,32 @@
/// <reference path="Game.d.ts" />
module Phaser {
class DynamicTexture {
constructor(game: Game, width: number, height: number);
private _game;
private _sx;
private _sy;
private _sw;
private _sh;
private _dx;
private _dy;
private _dw;
private _dh;
public bounds: Rectangle;
public canvas: HTMLCanvasElement;
public context: CanvasRenderingContext2D;
public getPixel(x: number, y: number): number;
public getPixel32(x: number, y: number): number;
public getPixels(rect: Rectangle): ImageData;
public setPixel(x: number, y: number, color: number): void;
public setPixel32(x: number, y: number, color: number): void;
public setPixels(rect: Rectangle, input): void;
public fillRect(rect: Rectangle, color: number): void;
public pasteImage(key: string, frame?: number, destX?: number, destY?: number, destWidth?: number, destHeight?: number): void;
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point): void;
public clear(): void;
public width : number;
public height : number;
private getColor32(alpha, red, green, blue);
private getColor(red, green, blue);
}
}
+18
View File
@@ -0,0 +1,18 @@
/// <reference path="Game.d.ts" />
module Phaser {
class FXManager {
constructor(game: Game);
private _fx;
private _length;
private _game;
public active: bool;
public visible: bool;
public add(effect): any;
public preUpdate(): void;
public postUpdate(): void;
public preRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
public render(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
public postRender(camera: Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number): void;
public destroy(): void;
}
}
+220
View File
@@ -0,0 +1,220 @@
/// <reference path="Game.ts" />
/**
* Phaser - FXManager
*
* The FXManager controls all special effects applied to game objects such as Cameras.
*/
module Phaser {
export class FXManager {
constructor(game: Game, parent) {
this._game = game;
this._parent = parent;
this._fx = [];
this.active = true;
this.visible = true;
}
/**
* The essential reference to the main game object.
*/
private _game: Game;
/**
* A reference to the object that owns this FXManager instance.
*/
private _parent;
/**
* The array in which we keep all of the registered FX
*/
private _fx;
/**
* Holds the size of the _fx array
*/
private _length: number;
/**
* Controls whether any of the FX have preUpdate, update or postUpdate called
*/
public active: bool;
/**
* Controls whether any of the FX have preRender, render or postRender called
*/
public visible: bool;
/**
* Adds a new FX to the FXManager.
* The effect must be an object with at least one of the following methods: preUpdate, postUpdate, preRender, render or postRender.
* A new instance of the effect will be created and a reference to Game will be passed to the object constructor.
*/
public add(effect): any {
var result: bool = false;
var newEffect = { effect: {}, preUpdate: false, postUpdate: false, preRender: false, render: false, postRender: false };
if (typeof effect === 'function')
{
newEffect.effect = new effect(this._game, this._parent);
}
else
{
throw new Error("Invalid object given to Phaser.FXManager.add");
}
// Check for methods now to avoid having to do this every loop
if (typeof newEffect.effect['preUpdate'] === 'function')
{
newEffect.preUpdate = true;
result = true;
}
if (typeof newEffect.effect['postUpdate'] === 'function')
{
newEffect.postUpdate = true;
result = true;
}
if (typeof newEffect.effect['preRender'] === 'function')
{
newEffect.preRender = true;
result = true;
}
if (typeof newEffect.effect['render'] === 'function')
{
newEffect.render = true;
result = true;
}
if (typeof newEffect.effect['postRender'] === 'function')
{
newEffect.postRender = true;
result = true;
}
if (result == true)
{
this._length = this._fx.push(newEffect);
return newEffect.effect;
}
else
{
return result;
}
}
/**
* Pre-update is called at the start of the objects update cycle, before any other updates have taken place.
*/
public preUpdate() {
if (this.active)
{
for (var i = 0; i < this._length; i++)
{
if (this._fx[i].preUpdate)
{
this._fx[i].effect.preUpdate();
}
}
}
}
/**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
*/
public postUpdate() {
if (this.active)
{
for (var i = 0; i < this._length; i++)
{
if (this._fx[i].postUpdate)
{
this._fx[i].effect.postUpdate();
}
}
}
}
/**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
*/
public preRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
if (this.visible)
{
for (var i = 0; i < this._length; i++)
{
if (this._fx[i].preRender)
{
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
}
}
}
}
/**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
*/
public render(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
if (this.visible)
{
for (var i = 0; i < this._length; i++)
{
if (this._fx[i].preRender)
{
this._fx[i].effect.preRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
}
}
}
}
/**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* It happens directly BEFORE a canvas context.restore has happened if added to a Camera.
*/
public postRender(camera:Camera, cameraX: number, cameraY: number, cameraWidth: number, cameraHeight: number) {
if (this.visible)
{
for (var i = 0; i < this._length; i++)
{
if (this._fx[i].postRender)
{
this._fx[i].effect.postRender(camera, cameraX, cameraY, cameraWidth, cameraHeight);
}
}
}
}
/**
* Clear down this FXManager and null out references
*/
public destroy() {
this._game = null;
this._fx = null;
}
}
}
+88
View File
@@ -0,0 +1,88 @@
/// <reference path="AnimationManager.d.ts" />
/// <reference path="Basic.d.ts" />
/// <reference path="Cache.d.ts" />
/// <reference path="CameraManager.d.ts" />
/// <reference path="Collision.d.ts" />
/// <reference path="DynamicTexture.d.ts" />
/// <reference path="FXManager.d.ts" />
/// <reference path="GameMath.d.ts" />
/// <reference path="Group.d.ts" />
/// <reference path="Loader.d.ts" />
/// <reference path="Motion.d.ts" />
/// <reference path="Signal.d.ts" />
/// <reference path="SignalBinding.d.ts" />
/// <reference path="SoundManager.d.ts" />
/// <reference path="Stage.d.ts" />
/// <reference path="Time.d.ts" />
/// <reference path="TweenManager.d.ts" />
/// <reference path="World.d.ts" />
/// <reference path="system/Device.d.ts" />
/// <reference path="system/RandomDataGenerator.d.ts" />
/// <reference path="system/RequestAnimationFrame.d.ts" />
/// <reference path="system/input/Input.d.ts" />
/// <reference path="system/input/Keyboard.d.ts" />
/// <reference path="system/input/Mouse.d.ts" />
/// <reference path="system/input/Touch.d.ts" />
/// <reference path="gameobjects/Emitter.d.ts" />
/// <reference path="gameobjects/GameObject.d.ts" />
/// <reference path="gameobjects/GeomSprite.d.ts" />
/// <reference path="gameobjects/Particle.d.ts" />
/// <reference path="gameobjects/Sprite.d.ts" />
/// <reference path="gameobjects/Tilemap.d.ts" />
/// <reference path="gameobjects/ScrollZone.d.ts" />
module Phaser {
class Game {
constructor(callbackContext, parent?: string, width?: number, height?: number, initCallback?, createCallback?, updateCallback?, renderCallback?);
private _raf;
private _maxAccumulation;
private _accumulator;
private _step;
private _loadComplete;
private _paused;
private _pendingState;
public callbackContext;
public onInitCallback;
public onCreateCallback;
public onUpdateCallback;
public onRenderCallback;
public onPausedCallback;
public cache: Cache;
public collision: Collision;
public input: Input;
public loader: Loader;
public math: GameMath;
public motion: Motion;
public sound: SoundManager;
public stage: Stage;
public time: Time;
public tweens: TweenManager;
public world: World;
public rnd: RandomDataGenerator;
public device: Device;
public isBooted: bool;
public isRunning: bool;
private boot(parent, width, height);
private loadComplete();
private bootLoop();
private pausedLoop();
private loop();
private startState();
public setCallbacks(initCallback?, createCallback?, updateCallback?, renderCallback?): void;
public switchState(state, clearWorld?: bool, clearCache?: bool): void;
public destroy(): void;
public paused : bool;
public framerate : number;
public createCamera(x: number, y: number, width: number, height: number): Camera;
public createGeomSprite(x: number, y: number): GeomSprite;
public createSprite(x: number, y: number, key?: string): Sprite;
public createDynamicTexture(width: number, height: number): DynamicTexture;
public createGroup(MaxSize?: number): Group;
public createParticle(): Particle;
public createEmitter(x?: number, y?: number, size?: number): Emitter;
public createScrollZone(key: string, x?: number, y?: number, width?: number, height?: number): ScrollZone;
public createTilemap(key: string, mapData: string, format: number, resizeWorld?: bool, tileWidth?: number, tileHeight?: number): Tilemap;
public createTween(obj): Tween;
public collide(objectOrGroup1?: Basic, objectOrGroup2?: Basic, notifyCallback?): bool;
public camera : Camera;
}
}
+48 -22
View File
@@ -4,6 +4,7 @@
/// <reference path="CameraManager.ts" /> /// <reference path="CameraManager.ts" />
/// <reference path="Collision.ts" /> /// <reference path="Collision.ts" />
/// <reference path="DynamicTexture.ts" /> /// <reference path="DynamicTexture.ts" />
/// <reference path="FXManager.ts" />
/// <reference path="GameMath.ts" /> /// <reference path="GameMath.ts" />
/// <reference path="Group.ts" /> /// <reference path="Group.ts" />
/// <reference path="Loader.ts" /> /// <reference path="Loader.ts" />
@@ -35,6 +36,9 @@
* *
* This is where the magic happens. The Game object is the heart of your game, * This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process. * providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*/ */
module Phaser { module Phaser {
@@ -51,7 +55,7 @@ module Phaser {
if (document.readyState === 'complete' || document.readyState === 'interactive') if (document.readyState === 'complete' || document.readyState === 'interactive')
{ {
setTimeout((parent, width, height) => this.boot(parent, width, height)); setTimeout(() => this.boot(parent, width, height));
} }
else else
{ {
@@ -77,7 +81,6 @@ module Phaser {
public onRenderCallback = null; public onRenderCallback = null;
public onPausedCallback = null; public onPausedCallback = null;
public camera: Camera; // quick reference to the default created camera, access the rest via .world
public cache: Cache; public cache: Cache;
public collision: Collision; public collision: Collision;
public input: Input; public input: Input;
@@ -93,6 +96,7 @@ module Phaser {
public device: Device; public device: Device;
public isBooted: bool = false; public isBooted: bool = false;
public isRunning: bool = false;
private boot(parent: string, width: number, height: number) { private boot(parent: string, width: number, height: number) {
@@ -122,16 +126,16 @@ module Phaser {
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]); this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
this.framerate = 60; this.framerate = 60;
this.isBooted = true;
// Display the default game screen? // Display the default game screen?
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null) if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
{ {
this.isBooted = false; this._raf = new RequestAnimationFrame(this.bootLoop, this);
this.stage.drawInitScreen();
} }
else else
{ {
this.isBooted = true; this.isRunning = true;
this._loadComplete = false; this._loadComplete = false;
this._raf = new RequestAnimationFrame(this.loop, this); this._raf = new RequestAnimationFrame(this.loop, this);
@@ -158,22 +162,33 @@ module Phaser {
} }
private bootLoop() {
this.time.update();
this.tweens.update();
this.input.update();
this.stage.update();
}
private pausedLoop() {
this.time.update();
this.tweens.update();
this.input.update();
this.stage.update();
if (this.onPausedCallback !== null)
{
this.onPausedCallback.call(this.callbackContext);
}
}
private loop() { private loop() {
this.time.update(); this.time.update();
this.tweens.update(); this.tweens.update();
if (this._paused == true)
{
if (this.onPausedCallback !== null)
{
this.onPausedCallback.call(this.callbackContext);
}
return;
}
this.input.update(); this.input.update();
this.stage.update(); this.stage.update();
@@ -313,8 +328,7 @@ module Phaser {
} }
else else
{ {
throw Error("Invalid State object given. Must contain at least a create or update function."); throw new Error("Invalid State object given. Must contain at least a create or update function.");
return;
} }
} }
@@ -328,7 +342,6 @@ module Phaser {
this.onUpdateCallback = null; this.onUpdateCallback = null;
this.onRenderCallback = null; this.onRenderCallback = null;
this.onPausedCallback = null; this.onPausedCallback = null;
this.camera = null;
this.cache = null; this.cache = null;
this.input = null; this.input = null;
this.loader = null; this.loader = null;
@@ -349,12 +362,21 @@ module Phaser {
if (value == true && this._paused == false) if (value == true && this._paused == false)
{ {
this._paused = true; this._paused = true;
this._raf.setCallback(this.pausedLoop);
} }
else if (value == false && this._paused == true) else if (value == false && this._paused == true)
{ {
this._paused = false; this._paused = false;
this.time.time = Date.now(); this.time.time = Date.now();
this.input.reset(); this.input.reset();
if (this.isRunning == false)
{
this._raf.setCallback(this.bootLoop);
}
else
{
this._raf.setCallback(this.loop);
}
} }
} }
@@ -416,8 +438,12 @@ module Phaser {
return this.tweens.create(obj); return this.tweens.create(obj);
} }
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool { public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null): bool {
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate); return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
}
public get camera(): Camera {
return this.world.cameras.current;
} }
} }
+110
View File
@@ -0,0 +1,110 @@
/// <reference path="Game.d.ts" />
module Phaser {
class GameMath {
constructor(game: Game);
private _game;
static PI: number;
static PI_2: number;
static PI_4: number;
static PI_8: number;
static PI_16: number;
static TWO_PI: number;
static THREE_PI_2: number;
static E: number;
static LN10: number;
static LN2: number;
static LOG10E: number;
static LOG2E: number;
static SQRT1_2: number;
static SQRT2: number;
static DEG_TO_RAD: number;
static RAD_TO_DEG: number;
static B_16: number;
static B_31: number;
static B_32: number;
static B_48: number;
static B_53: number;
static B_64: number;
static ONE_THIRD: number;
static TWO_THIRDS: number;
static ONE_SIXTH: number;
static COS_PI_3: number;
static SIN_2PI_3: number;
static CIRCLE_ALPHA: number;
static ON: bool;
static OFF: bool;
static SHORT_EPSILON: number;
static PERC_EPSILON: number;
static EPSILON: number;
static LONG_EPSILON: number;
public cosTable: any[];
public sinTable: any[];
public fuzzyEqual(a: number, b: number, epsilon?: number): bool;
public fuzzyLessThan(a: number, b: number, epsilon?: number): bool;
public fuzzyGreaterThan(a: number, b: number, epsilon?: number): bool;
public fuzzyCeil(val: number, epsilon?: number): number;
public fuzzyFloor(val: number, epsilon?: number): number;
public average(...args: any[]): number;
public slam(value: number, target: number, epsilon?: number): number;
public percentageMinMax(val: number, max: number, min?: number): number;
public sign(n: number): number;
public truncate(n: number): number;
public shear(n: number): number;
public wrap(val: number, max: number, min?: number): number;
public arithWrap(value: number, max: number, min?: number): number;
public clamp(input: number, max: number, min?: number): number;
public snapTo(input: number, gap: number, start?: number): number;
public snapToFloor(input: number, gap: number, start?: number): number;
public snapToCeil(input: number, gap: number, start?: number): number;
public snapToInArray(input: number, arr: number[], sort?: bool): number;
public roundTo(value: number, place?: number, base?: number): number;
public floorTo(value: number, place?: number, base?: number): number;
public ceilTo(value: number, place?: number, base?: number): number;
public interpolateFloat(a: number, b: number, weight: number): number;
public radiansToDegrees(angle: number): number;
public degreesToRadians(angle: number): number;
public angleBetween(x1: number, y1: number, x2: number, y2: number): number;
public normalizeAngle(angle: number, radians?: bool): number;
public nearestAngleBetween(a1: number, a2: number, radians?: bool): number;
public normalizeAngleToAnother(dep: number, ind: number, radians?: bool): number;
public normalizeAngleAfterAnother(dep: number, ind: number, radians?: bool): number;
public normalizeAngleBeforeAnother(dep: number, ind: number, radians?: bool): number;
public interpolateAngles(a1: number, a2: number, weight: number, radians?: bool, ease?): number;
public logBaseOf(value: number, base: number): number;
public GCD(m: number, n: number): number;
public LCM(m: number, n: number): number;
public factorial(value: number): number;
public gammaFunction(value: number): number;
public fallingFactorial(base: number, exp: number): number;
public risingFactorial(base: number, exp: number): number;
public binCoef(n: number, k: number): number;
public risingBinCoef(n: number, k: number): number;
public chanceRoll(chance?: number): bool;
public maxAdd(value: number, amount: number, max: number): number;
public minSub(value: number, amount: number, min: number): number;
public wrapValue(value: number, amount: number, max: number): number;
public randomSign(): number;
public isOdd(n: number): bool;
public isEven(n: number): bool;
public wrapAngle(angle: number): number;
public angleLimit(angle: number, min: number, max: number): number;
public linearInterpolation(v, k);
public bezierInterpolation(v, k): number;
public catmullRomInterpolation(v, k);
public linear(p0, p1, t);
public bernstein(n, i): number;
public catmullRom(p0, p1, p2, p3, t);
public difference(a: number, b: number): number;
public globalSeed: number;
public random(): number;
public srand(Seed: number): number;
public getRandom(Objects, StartIndex?: number, Length?: number);
public floor(Value: number): number;
public ceil(Value: number): number;
public sinCosGenerator(length: number, sinAmplitude?: number, cosAmplitude?: number, frequency?: number): any[];
public shiftSinTable(): number;
public shiftCosTable(): number;
public vectorLength(dx: number, dy: number): number;
public dotProduct(ax: number, ay: number, bx: number, by: number): number;
}
}
+9 -11
View File
@@ -855,29 +855,27 @@ module Phaser {
/** /**
* Fetch a random entry from the given array. * Fetch a random entry from the given array.
* Will return null if random selection is missing, or array has no entries. * Will return null if random selection is missing, or array has no entries.
* <code>G.getRandom()</code> is deterministic and safe for use with replays/recordings.
* HOWEVER, <code>U.getRandom()</code> is NOT deterministic and unsafe for use with replays/recordings.
* *
* @param Objects An array of objects. * @param objects An array of objects.
* @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array. * @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
* @param Length Optional restriction on the number of values you want to randomly select from. * @param length Optional restriction on the number of values you want to randomly select from.
* *
* @return The random object that was selected. * @return The random object that was selected.
*/ */
public getRandom(Objects, StartIndex: number = 0, Length: number = 0) { public getRandom(objects, startIndex: number = 0, length: number = 0) {
if (Objects != null) if (objects != null)
{ {
var l: number = Length; var l: number = length;
if ((l == 0) || (l > Objects.length - StartIndex)) if ((l == 0) || (l > objects.length - startIndex))
{ {
l = Objects.length - StartIndex; l = objects.length - startIndex;
} }
if (l > 0) if (l > 0)
{ {
return Objects[StartIndex + Math.floor(Math.random() * l)]; return objects[startIndex + Math.floor(Math.random() * l)];
} }
} }
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="Basic.d.ts" />
/// <reference path="Game.d.ts" />
module Phaser {
class Group extends Basic {
constructor(game: Game, MaxSize?: number);
static ASCENDING: number;
static DESCENDING: number;
public members: Basic[];
public length: number;
private _maxSize;
private _marker;
private _sortIndex;
private _sortOrder;
public destroy(): void;
public update(): void;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): void;
public maxSize : number;
public add(Object: Basic): Basic;
public recycle(ObjectClass?);
public remove(Object: Basic, Splice?: bool): Basic;
public replace(OldObject: Basic, NewObject: Basic): Basic;
public sort(Index?: string, Order?: number): void;
public setAll(VariableName: string, Value: Object, Recurse?: bool): void;
public callAll(FunctionName: string, Recurse?: bool): void;
public forEach(callback, recursive?: bool): void;
public forEachAlive(context, callback, recursive?: bool): void;
public getFirstAvailable(ObjectClass?);
public getFirstNull(): number;
public getFirstExtant(): Basic;
public getFirstAlive(): Basic;
public getFirstDead(): Basic;
public countLiving(): number;
public countDead(): number;
public getRandom(StartIndex?: number, Length?: number): Basic;
public clear(): void;
public kill(): void;
public sortHandler(Obj1: Basic, Obj2: Basic): number;
}
}
+43 -19
View File
@@ -321,21 +321,21 @@ module Phaser {
/** /**
* Removes an object from the group. * Removes an object from the group.
* *
* @param Object The <code>Basic</code> you want to remove. * @param object The <code>Basic</code> you want to remove.
* @param Splice Whether the object should be cut from the array entirely or not. * @param splice Whether the object should be cut from the array entirely or not.
* *
* @return The removed object. * @return The removed object.
*/ */
public remove(Object: Basic, Splice: bool = false): Basic { public remove(object: Basic, splice: bool = false): Basic {
var index: number = this.members.indexOf(Object); var index: number = this.members.indexOf(object);
if ((index < 0) || (index >= this.members.length)) if ((index < 0) || (index >= this.members.length))
{ {
return null; return null;
} }
if (Splice) if (splice)
{ {
this.members.splice(index, 1); this.members.splice(index, 1);
this.length--; this.length--;
@@ -345,30 +345,30 @@ module Phaser {
this.members[index] = null; this.members[index] = null;
} }
return Object; return object;
} }
/** /**
* Replaces an existing <code>Basic</code> with a new one. * Replaces an existing <code>Basic</code> with a new one.
* *
* @param OldObject The object you want to replace. * @param oldObject The object you want to replace.
* @param NewObject The new object you want to use instead. * @param newObject The new object you want to use instead.
* *
* @return The new object. * @return The new object.
*/ */
public replace(OldObject: Basic, NewObject: Basic): Basic { public replace(oldObject: Basic, newObject: Basic): Basic {
var index: number = this.members.indexOf(OldObject); var index: number = this.members.indexOf(oldObject);
if ((index < 0) || (index >= this.members.length)) if ((index < 0) || (index >= this.members.length))
{ {
return null; return null;
} }
this.members[index] = NewObject; this.members[index] = newObject;
return NewObject; return newObject;
} }
@@ -379,13 +379,13 @@ module Phaser {
* <code>State.update()</code> override. To sort all existing objects after * <code>State.update()</code> override. To sort all existing objects after
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>. * a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
* *
* @param Index The <code>string</code> name of the member variable you want to sort on. Default value is "y". * @param index The <code>string</code> name of the member variable you want to sort on. Default value is "y".
* @param Order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>. * @param order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
*/ */
public sort(Index: string = "y", Order: number = Group.ASCENDING) { public sort(index: string = "y", order: number = Group.ASCENDING) {
this._sortIndex = Index; this._sortIndex = index;
this._sortOrder = Order; this._sortOrder = order;
this.members.sort(this.sortHandler); this.members.sort(this.sortHandler);
} }
@@ -450,7 +450,7 @@ module Phaser {
} }
} }
public forEach(callback, Recurse: bool = false) { public forEach(callback, recursive: bool = false) {
var basic; var basic;
var i: number = 0; var i: number = 0;
@@ -461,7 +461,7 @@ module Phaser {
if (basic != null) if (basic != null)
{ {
if (Recurse && (basic.isGroup == true)) if (recursive && (basic.isGroup == true))
{ {
basic.forEach(callback, true); basic.forEach(callback, true);
} }
@@ -474,6 +474,30 @@ module Phaser {
} }
public forEachAlive(context, callback, recursive: bool = false) {
var basic;
var i: number = 0;
while (i < this.length)
{
basic = this.members[i++];
if (basic != null && basic.alive)
{
if (recursive && (basic.isGroup == true))
{
basic.forEachAlive(context, callback, true);
}
else
{
callback.call(context, basic);
}
}
}
}
/** /**
* Call this function to retrieve the first object with exists == false in the group. * Call this function to retrieve the first object with exists == false in the group.
* This is handy for recycling in general, e.g. respawning enemies. * This is handy for recycling in general, e.g. respawning enemies.
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="Game.d.ts" />
module Phaser {
class Loader {
constructor(game: Game, callback);
private _game;
private _keys;
private _fileList;
private _gameCreateComplete;
private _onComplete;
private _onFileLoad;
private _progressChunk;
private _xhr;
private _queueSize;
public hasLoaded: bool;
public progress: number;
public reset(): void;
public queueSize : number;
public addImageFile(key: string, url: string): void;
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number): void;
public addTextureAtlas(key: string, url: string, jsonURL?: string, jsonData?): void;
public addAudioFile(key: string, url: string): void;
public addTextFile(key: string, url: string): void;
public removeFile(key: string): void;
public removeAll(): void;
public load(onFileLoadCallback?, onCompleteCallback?): void;
private loadFile();
private fileError(key);
private fileComplete(key);
private jsonLoadComplete(key);
private jsonLoadError(key);
private nextFile(previousKey, success);
private checkKeyExists(key);
}
}
+23
View File
@@ -0,0 +1,23 @@
/// <reference path="Game.d.ts" />
/// <reference path="gameobjects/GameObject.d.ts" />
module Phaser {
class Motion {
constructor(game: Game);
private _game;
public computeVelocity(Velocity: number, Acceleration?: number, Drag?: number, Max?: number): number;
public velocityFromAngle(angle: number, speed: number): Point;
public moveTowardsObject(source: GameObject, dest: GameObject, speed?: number, maxTime?: number): void;
public accelerateTowardsObject(source: GameObject, dest: GameObject, speed: number, xSpeedMax: number, ySpeedMax: number): void;
public moveTowardsMouse(source: GameObject, speed?: number, maxTime?: number): void;
public accelerateTowardsMouse(source: GameObject, speed: number, xSpeedMax: number, ySpeedMax: number): void;
public moveTowardsPoint(source: GameObject, target: Point, speed?: number, maxTime?: number): void;
public accelerateTowardsPoint(source: GameObject, target: Point, speed: number, xSpeedMax: number, ySpeedMax: number): void;
public distanceBetween(a: GameObject, b: GameObject): number;
public distanceToPoint(a: GameObject, target: Point): number;
public distanceToMouse(a: GameObject): number;
public angleBetweenPoint(a: GameObject, target: Point, asDegrees?: bool): number;
public angleBetween(a: GameObject, b: GameObject, asDegrees?: bool): number;
public velocityFromFacing(parent: GameObject, speed: number): Point;
public angleBetweenMouse(a: GameObject, asDegrees?: bool): number;
}
}
+14
View File
@@ -47,12 +47,14 @@
<TypeScriptIncludeComments>true</TypeScriptIncludeComments> <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap> <TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile> <TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
<TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> <PropertyGroup Condition="'$(Configuration)' == 'Release'">
<TypeScriptTarget>ES5</TypeScriptTarget> <TypeScriptTarget>ES5</TypeScriptTarget>
<TypeScriptIncludeComments>false</TypeScriptIncludeComments> <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
<TypeScriptSourceMap>false</TypeScriptSourceMap> <TypeScriptSourceMap>false</TypeScriptSourceMap>
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile> <TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
<TypeScriptGeneratesDeclarations>true</TypeScriptGeneratesDeclarations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="plugins\" /> <Folder Include="plugins\" />
@@ -67,6 +69,10 @@
<Content Include="DynamicTexture.js"> <Content Include="DynamicTexture.js">
<DependentUpon>DynamicTexture.ts</DependentUpon> <DependentUpon>DynamicTexture.ts</DependentUpon>
</Content> </Content>
<TypeScriptCompile Include="FXManager.ts" />
<Content Include="FXManager.js">
<DependentUpon>FXManager.ts</DependentUpon>
</Content>
<Content Include="Game.js"> <Content Include="Game.js">
<DependentUpon>Game.ts</DependentUpon> <DependentUpon>Game.ts</DependentUpon>
</Content> </Content>
@@ -125,6 +131,14 @@
<Content Include="SoundManager.js"> <Content Include="SoundManager.js">
<DependentUpon>SoundManager.ts</DependentUpon> <DependentUpon>SoundManager.ts</DependentUpon>
</Content> </Content>
<TypeScriptCompile Include="system\screens\PauseScreen.ts" />
<TypeScriptCompile Include="system\screens\BootScreen.ts" />
<Content Include="system\screens\BootScreen.js">
<DependentUpon>BootScreen.ts</DependentUpon>
</Content>
<Content Include="system\screens\PauseScreen.js">
<DependentUpon>PauseScreen.ts</DependentUpon>
</Content>
<Content Include="system\Sound.js"> <Content Include="system\Sound.js">
<DependentUpon>Sound.ts</DependentUpon> <DependentUpon>Sound.ts</DependentUpon>
</Content> </Content>
+3
View File
@@ -0,0 +1,3 @@
module Phaser {
var VERSION: string;
}
+3 -3
View File
@@ -1,13 +1,13 @@
/** /**
* Phaser * Phaser
* *
* v0.9.3 - April 24th 2013 * v0.9.5 - April 28th 2013
* *
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi. * A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
* *
* Richard Davey (@photonstorm) * Richard Davey (@photonstorm)
* *
* Many thanks to Adam Saltsman (@ADAMATOMIC) for the original Flixel AS3 code on which Phaser is based. * Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel on which Phaser took a lot of inspiration.
* *
* "If you want your children to be intelligent, read them fairy tales." * "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales." * "If you want them to be more intelligent, read them more fairy tales."
@@ -16,6 +16,6 @@
module Phaser { module Phaser {
export var VERSION: string = 'Phaser version 0.9.3'; export var VERSION: string = 'Phaser version 0.9.5';
} }
+26
View File
@@ -0,0 +1,26 @@
/// <reference path="SignalBinding.d.ts" />
module Phaser {
class Signal {
private _bindings;
private _prevParams;
static VERSION: string;
public memorize: bool;
private _shouldPropagate;
public active: bool;
public validateListener(listener, fnName): void;
private _registerListener(listener, isOnce, listenerContext, priority);
private _addBinding(binding);
private _indexOfListener(listener, context);
public has(listener, context?: any): bool;
public add(listener, listenerContext?: any, priority?: number): SignalBinding;
public addOnce(listener, listenerContext?: any, priority?: number): SignalBinding;
public remove(listener, context?: any);
public removeAll(): void;
public getNumListeners(): number;
public halt(): void;
public dispatch(...paramsArr: any[]): void;
public forget(): void;
public dispose(): void;
public toString(): string;
}
}
+10 -7
View File
@@ -211,7 +211,7 @@ module Phaser {
if (i !== -1) if (i !== -1)
{ {
this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal this._bindings[i]._destroy();
this._bindings.splice(i, 1); this._bindings.splice(i, 1);
} }
@@ -224,14 +224,17 @@ module Phaser {
*/ */
public removeAll() { public removeAll() {
var n: number = this._bindings.length; if (this._bindings)
while (n--)
{ {
this._bindings[n]._destroy(); var n: number = this._bindings.length;
}
this._bindings.length = 0; while (n--)
{
this._bindings[n]._destroy();
}
this._bindings.length = 0;
}
} }
+21
View File
@@ -0,0 +1,21 @@
/// <reference path="Signal.d.ts" />
module Phaser {
class SignalBinding {
constructor(signal: Signal, listener, isOnce: bool, listenerContext, priority?: number);
private _listener;
private _isOnce;
public context;
private _signal;
public priority: number;
public active: bool;
public params;
public execute(paramsArr?: any[]);
public detach();
public isBound(): bool;
public isOnce(): bool;
public getListener();
public getSignal(): Signal;
public _destroy(): void;
public toString(): string;
}
}
+16
View File
@@ -0,0 +1,16 @@
/// <reference path="Game.d.ts" />
/// <reference path="system/Sound.d.ts" />
module Phaser {
class SoundManager {
constructor(game: Game);
private _game;
private _context;
private _gainNode;
private _volume;
public mute(): void;
public unmute(): void;
public volume : number;
public decode(key: string, callback?, sound?: Sound): void;
public play(key: string, volume?: number, loop?: bool): Sound;
}
}
+1 -1
View File
@@ -111,7 +111,7 @@ module Phaser {
var tempSound: Sound = new Sound(this._context, this._gainNode, null, volume, loop); var tempSound: Sound = new Sound(this._context, this._gainNode, null, volume, loop);
// this is an async process, so we can return the Sound object anyway, it just won't be playing yet // this is an async process, so we can return the Sound object anyway, it just won't be playing yet
this.decode(key, () => this.play(key), tempSound); this.decode(key, () => tempSound.play(), tempSound);
return tempSound; return tempSound;
} }
+47
View File
@@ -0,0 +1,47 @@
/// <reference path="Phaser.d.ts" />
/// <reference path="Game.d.ts" />
/// <reference path="system/StageScaleMode.d.ts" />
/// <reference path="system/screens/BootScreen.d.ts" />
/// <reference path="system/screens/PauseScreen.d.ts" />
module Phaser {
class Stage {
constructor(game: Game, parent: string, width: number, height: number);
private _game;
private _bgColor;
private _bootScreen;
private _pauseScreen;
static ORIENTATION_LANDSCAPE: number;
static ORIENTATION_PORTRAIT: number;
public bounds: Rectangle;
public aspectRatio: number;
public clear: bool;
public canvas: HTMLCanvasElement;
public context: CanvasRenderingContext2D;
public disablePauseScreen: bool;
public disableBootScreen: bool;
public offset: Point;
public scale: StageScaleMode;
public scaleMode: number;
public minScaleX: number;
public maxScaleX: number;
public minScaleY: number;
public maxScaleY: number;
public update(): void;
private visibilityChange(event);
private getOffset(element);
public strokeStyle: string;
public lineWidth: number;
public fillStyle: string;
public saveCanvasValues(): void;
public restoreCanvasValues(): void;
public backgroundColor : string;
public x : number;
public y : number;
public width : number;
public height : number;
public centerX : number;
public centerY : number;
public randomX : number;
public randomY : number;
}
}
+33 -69
View File
@@ -1,6 +1,8 @@
/// <reference path="Phaser.ts" /> /// <reference path="Phaser.ts" />
/// <reference path="Game.ts" /> /// <reference path="Game.ts" />
/// <reference path="system/StageScaleMode.ts" /> /// <reference path="system/StageScaleMode.ts" />
/// <reference path="system/screens/BootScreen.ts" />
/// <reference path="system/screens/PauseScreen.ts" />
/** /**
* Phaser - Stage * Phaser - Stage
@@ -43,8 +45,11 @@ module Phaser {
this.scaleMode = StageScaleMode.NO_SCALE; this.scaleMode = StageScaleMode.NO_SCALE;
this.scale = new StageScaleMode(this._game); this.scale = new StageScaleMode(this._game);
//document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false); this._bootScreen = new BootScreen(this._game);
//document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false); this._pauseScreen = new PauseScreen(this._game, width, height);
document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false);
document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false);
window.onblur = (event) => this.visibilityChange(event); window.onblur = (event) => this.visibilityChange(event);
window.onfocus = (event) => this.visibilityChange(event); window.onfocus = (event) => this.visibilityChange(event);
@@ -52,7 +57,8 @@ module Phaser {
private _game: Game; private _game: Game;
private _bgColor: string; private _bgColor: string;
private _bootScreen;
private _pauseScreen;
public static ORIENTATION_LANDSCAPE: number = 0; public static ORIENTATION_LANDSCAPE: number = 0;
public static ORIENTATION_PORTRAIT: number = 1; public static ORIENTATION_PORTRAIT: number = 1;
@@ -63,6 +69,7 @@ module Phaser {
public canvas: HTMLCanvasElement; public canvas: HTMLCanvasElement;
public context: CanvasRenderingContext2D; public context: CanvasRenderingContext2D;
public disablePauseScreen: bool = false; public disablePauseScreen: bool = false;
public disableBootScreen: bool = false;
public offset: Point; public offset: Point;
public scale: StageScaleMode; public scale: StageScaleMode;
public scaleMode: number; public scaleMode: number;
@@ -82,18 +89,20 @@ module Phaser {
this.context.clearRect(0, 0, this.width, this.height); this.context.clearRect(0, 0, this.width, this.height);
} }
} if (this._game.isRunning == false && this.disableBootScreen == false)
{
this._bootScreen.update();
this._bootScreen.render();
}
public renderDebugInfo() { if (this._game.paused == true && this.disablePauseScreen == false)
{
this.context.fillStyle = 'rgb(255,255,255)'; this._pauseScreen.update();
this.context.fillText(Phaser.VERSION, 10, 20); this._pauseScreen.render();
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 10, 40); }
this.context.fillText('x: ' + this.x + ' y: ' + this.y, 10, 60);
} }
//if (document['hidden'] === true || document['webkitHidden'] === true)
private visibilityChange(event) { private visibilityChange(event) {
if (this.disablePauseScreen) if (this.disablePauseScreen)
@@ -101,70 +110,27 @@ module Phaser {
return; return;
} }
if (event.type == 'blur' && this._game.paused == false && this._game.isBooted == true) if (event.type === 'blur' || document['hidden'] === true || document['webkitHidden'] === true)
{ {
this._game.paused = true; if (this._game.paused == false)
this.drawPauseScreen(); {
this._pauseScreen.onPaused();
this.saveCanvasValues();
this._game.paused = true;
}
} }
else if (event.type == 'focus') else if (event.type == 'focus')
{ {
this._game.paused = false; if (this._game.paused == true)
{
this._pauseScreen.onResume();
this._game.paused = false;
this.restoreCanvasValues();
}
} }
} }
public drawInitScreen() {
this.context.fillStyle = 'rgb(40, 40, 40)';
this.context.fillRect(0, 0, this.width, this.height);
this.context.fillStyle = 'rgb(255,255,255)';
this.context.font = 'bold 18px Arial';
this.context.textBaseline = 'top';
this.context.fillText(Phaser.VERSION, 54, 32);
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 32, 64);
this.context.fillText('www.photonstorm.com', 32, 96);
this.context.font = '16px Arial';
this.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 160);
this.context.fillText('functions in the Game constructor, or use Game.loadState()', 32, 184);
var image = new Image();
var that = this;
image.onload = function () {
that.context.drawImage(image, 32, 32);
};
image.src = this._logo;
}
private drawPauseScreen() {
this.saveCanvasValues();
this.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
this.context.fillRect(0, 0, this.width, this.height);
// Draw a 'play' arrow
var arrowWidth = Math.round(this.width / 2);
var arrowHeight = Math.round(this.height / 2);
var sx = this.centerX - arrowWidth / 2;
var sy = this.centerY - arrowHeight / 2;
this.context.beginPath();
this.context.moveTo(sx, sy);
this.context.lineTo(sx, sy + arrowHeight);
this.context.lineTo(sx + arrowWidth, this.centerY);
this.context.fillStyle = 'rgba(255, 255, 255, 0.8)';
this.context.fill();
this.context.closePath();
this.restoreCanvasValues();
}
private getOffset(element): Point { private getOffset(element): Point {
var box = element.getBoundingClientRect(); var box = element.getBoundingClientRect();
@@ -238,8 +204,6 @@ module Phaser {
return Math.round(Math.random() * this.bounds.height); return Math.round(Math.random() * this.bounds.height);
} }
private _logo: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";
} }
} }
+25
View File
@@ -0,0 +1,25 @@
/// <reference path="Game.d.ts" />
module Phaser {
class Time {
constructor(game: Game);
private _game;
private _started;
public timeScale: number;
public elapsed: number;
public time: number;
public now: number;
public delta: number;
public totalElapsedSeconds : number;
public fps: number;
public fpsMin: number;
public fpsMax: number;
public msMin: number;
public msMax: number;
public frames: number;
private _timeLastSecond;
public update(): void;
public elapsedSince(since: number): number;
public elapsedSecondsSince(since: number): number;
public reset(): void;
}
}
+15
View File
@@ -0,0 +1,15 @@
/// <reference path="Game.d.ts" />
/// <reference path="system/Tween.d.ts" />
module Phaser {
class TweenManager {
constructor(game: Game);
private _game;
private _tweens;
public getAll(): Tween[];
public removeAll(): void;
public create(object): Tween;
public add(tween: Tween): Tween;
public remove(tween: Tween): void;
public update(): bool;
}
}
+32
View File
@@ -0,0 +1,32 @@
/// <reference path="Game.d.ts" />
module Phaser {
class World {
constructor(game: Game, width: number, height: number);
private _game;
public cameras: CameraManager;
public group: Group;
public bounds: Rectangle;
public worldDivisions: number;
public update(): void;
public render(): void;
public destroy(): void;
public setSize(width: number, height: number, updateCameraBounds?: bool): void;
public width : number;
public height : number;
public centerX : number;
public centerY : number;
public randomX : number;
public randomY : number;
public createCamera(x: number, y: number, width: number, height: number): Camera;
public removeCamera(id: number): bool;
public getAllCameras(): Camera[];
public createSprite(x: number, y: number, key?: string): Sprite;
public createGeomSprite(x: number, y: number): GeomSprite;
public createDynamicTexture(width: number, height: number): DynamicTexture;
public createGroup(MaxSize?: number): Group;
public createScrollZone(key: string, x?: number, y?: number, width?: number, height?: number): ScrollZone;
public createTilemap(key: string, mapData: string, format: number, resizeWorld?: bool, tileWidth?: number, tileHeight?: number): Tilemap;
public createParticle(): Particle;
public createEmitter(x?: number, y?: number, size?: number): Emitter;
}
}
+9 -9
View File
@@ -16,9 +16,9 @@ module Phaser {
this._game = game; this._game = game;
this._cameras = new CameraManager(this._game, 0, 0, width, height); this.cameras = new CameraManager(this._game, 0, 0, width, height);
this._game.camera = this._cameras.current; this._game.camera = this.cameras.current;
this.group = new Group(this._game, 0); this.group = new Group(this._game, 0);
@@ -29,8 +29,8 @@ module Phaser {
} }
private _game: Game; private _game: Game;
private _cameras: CameraManager;
public cameras: CameraManager;
public group: Group; public group: Group;
public bounds: Rectangle; public bounds: Rectangle;
public worldDivisions: number; public worldDivisions: number;
@@ -41,14 +41,14 @@ module Phaser {
this.group.update(); this.group.update();
this.group.postUpdate(); this.group.postUpdate();
this._cameras.update(); this.cameras.update();
} }
public render() { public render() {
// Unlike in flixel our render process is camera driven, not group driven // Unlike in flixel our render process is camera driven, not group driven
this._cameras.render(); this.cameras.render();
} }
@@ -56,7 +56,7 @@ module Phaser {
this.group.destroy(); this.group.destroy();
this._cameras.destroy(); this.cameras.destroy();
} }
@@ -109,15 +109,15 @@ module Phaser {
// Cameras // Cameras
public createCamera(x: number, y: number, width: number, height: number): Camera { public createCamera(x: number, y: number, width: number, height: number): Camera {
return this._cameras.addCamera(x, y, width, height); return this.cameras.addCamera(x, y, width, height);
} }
public removeCamera(id: number): bool { public removeCamera(id: number): bool {
return this._cameras.removeCamera(id); return this.cameras.removeCamera(id);
} }
public getAllCameras(): Camera[] { public getAllCameras(): Camera[] {
return this._cameras.getAll(); return this.cameras.getAll();
} }
// Game Objects // Game Objects
+38
View File
@@ -0,0 +1,38 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../Group.d.ts" />
module Phaser {
class Emitter extends Group {
constructor(game: Game, X?: number, Y?: number, Size?: number);
public x: number;
public y: number;
public width: number;
public height: number;
public minParticleSpeed: MicroPoint;
public maxParticleSpeed: MicroPoint;
public particleDrag: MicroPoint;
public minRotation: number;
public maxRotation: number;
public gravity: number;
public on: bool;
public frequency: number;
public lifespan: number;
public bounce: number;
public particleClass;
private _quantity;
private _explode;
private _timer;
private _counter;
private _point;
public destroy(): void;
public makeParticles(Graphics, Quantity?: number, BakedRotations?: number, Multiple?: bool, Collide?: number): Emitter;
public update(): void;
public kill(): void;
public start(Explode?: bool, Lifespan?: number, Frequency?: number, Quantity?: number): void;
public emitParticle(): void;
public setSize(Width: number, Height: number): void;
public setXSpeed(Min?: number, Max?: number): void;
public setYSpeed(Min?: number, Max?: number): void;
public setRotation(Min?: number, Max?: number): void;
public at(Object): void;
}
}
+10 -9
View File
@@ -27,13 +27,13 @@ module Phaser {
this.y = Y; this.y = Y;
this.width = 0; this.width = 0;
this.height = 0; this.height = 0;
this.minParticleSpeed = new Point(-100, -100); this.minParticleSpeed = new MicroPoint(-100, -100);
this.maxParticleSpeed = new Point(100, 100); this.maxParticleSpeed = new MicroPoint(100, 100);
this.minRotation = -360; this.minRotation = -360;
this.maxRotation = 360; this.maxRotation = 360;
this.gravity = 0; this.gravity = 0;
this.particleClass = null; this.particleClass = null;
this.particleDrag = new Point(); this.particleDrag = new MicroPoint();
this.frequency = 0.1; this.frequency = 0.1;
this.lifespan = 3; this.lifespan = 3;
this.bounce = 0; this.bounce = 0;
@@ -41,7 +41,7 @@ module Phaser {
this._counter = 0; this._counter = 0;
this._explode = true; this._explode = true;
this.on = false; this.on = false;
this._point = new Point(); this._point = new MicroPoint();
} }
/** /**
@@ -68,18 +68,18 @@ module Phaser {
* The minimum possible velocity of a particle. * The minimum possible velocity of a particle.
* The default value is (-100,-100). * The default value is (-100,-100).
*/ */
public minParticleSpeed: Point; public minParticleSpeed: MicroPoint;
/** /**
* The maximum possible velocity of a particle. * The maximum possible velocity of a particle.
* The default value is (100,100). * The default value is (100,100).
*/ */
public maxParticleSpeed: Point; public maxParticleSpeed: MicroPoint;
/** /**
* The X and Y drag component of particles launched from the emitter. * The X and Y drag component of particles launched from the emitter.
*/ */
public particleDrag: Point; public particleDrag: MicroPoint;
/** /**
* The minimum possible angular velocity of a particle. The default value is -360. * The minimum possible angular velocity of a particle. The default value is -360.
@@ -149,7 +149,7 @@ module Phaser {
/** /**
* Internal point object, handy for reusing for memory mgmt purposes. * Internal point object, handy for reusing for memory mgmt purposes.
*/ */
private _point: Point; private _point: MicroPoint;
/** /**
* Clean up memory. * Clean up memory.
@@ -174,7 +174,7 @@ module Phaser {
* *
* @return This Emitter instance (nice for chaining stuff together, if you're into that). * @return This Emitter instance (nice for chaining stuff together, if you're into that).
*/ */
public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0.8): Emitter { public makeParticles(Graphics, Quantity: number = 50, BakedRotations: number = 16, Multiple: bool = false, Collide: number = 0): Emitter {
this.maxSize = Quantity; this.maxSize = Quantity;
@@ -236,6 +236,7 @@ module Phaser {
if (Collide > 0) if (Collide > 0)
{ {
particle.allowCollisions = Collision.ANY;
particle.width *= Collide; particle.width *= Collide;
particle.height *= Collide; particle.height *= Collide;
//particle.centerOffsets(); //particle.centerOffsets();
+84
View File
@@ -0,0 +1,84 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../Basic.d.ts" />
/// <reference path="../Signal.d.ts" />
module Phaser {
class GameObject extends Basic {
constructor(game: Game, x?: number, y?: number, width?: number, height?: number);
private _angle;
static ALIGN_TOP_LEFT: number;
static ALIGN_TOP_CENTER: number;
static ALIGN_TOP_RIGHT: number;
static ALIGN_CENTER_LEFT: number;
static ALIGN_CENTER: number;
static ALIGN_CENTER_RIGHT: number;
static ALIGN_BOTTOM_LEFT: number;
static ALIGN_BOTTOM_CENTER: number;
static ALIGN_BOTTOM_RIGHT: number;
static OUT_OF_BOUNDS_STOP: number;
static OUT_OF_BOUNDS_KILL: number;
public _point: MicroPoint;
public cameraBlacklist: number[];
public bounds: Rectangle;
public worldBounds: Quad;
public outOfBoundsAction: number;
public align: number;
public facing: number;
public alpha: number;
public scale: MicroPoint;
public origin: MicroPoint;
public z: number;
public rotationOffset: number;
public renderRotation: bool;
public immovable: bool;
public velocity: MicroPoint;
public mass: number;
public elasticity: number;
public acceleration: MicroPoint;
public drag: MicroPoint;
public maxVelocity: MicroPoint;
public angularVelocity: number;
public angularAcceleration: number;
public angularDrag: number;
public maxAngular: number;
public scrollFactor: MicroPoint;
public health: number;
public moves: bool;
public touching: number;
public wasTouching: number;
public allowCollisions: number;
public last: MicroPoint;
public inputEnabled: bool;
private _inputOver;
public onInputOver: Signal;
public onInputOut: Signal;
public onInputDown: Signal;
public onInputUp: Signal;
public preUpdate(): void;
public update(): void;
public postUpdate(): void;
private updateInput();
private updateMotion();
public overlaps(ObjectOrGroup, InScreenSpace?: bool, Camera?: Camera): bool;
public overlapsAt(X: number, Y: number, ObjectOrGroup, InScreenSpace?: bool, Camera?: Camera): bool;
public overlapsPoint(point: Point, InScreenSpace?: bool, Camera?: Camera): bool;
public onScreen(Camera?: Camera): bool;
public getScreenXY(point?: MicroPoint, Camera?: Camera): MicroPoint;
public solid : bool;
public getMidpoint(point?: MicroPoint): MicroPoint;
public reset(X: number, Y: number): void;
public isTouching(Direction: number): bool;
public justTouched(Direction: number): bool;
public hurt(Damage: number): void;
public setBounds(x: number, y: number, width: number, height: number): void;
public hideFromCamera(camera: Camera): void;
public showToCamera(camera: Camera): void;
public clearCameraList(): void;
public destroy(): void;
public x : number;
public y : number;
public rotation : number;
public angle : number;
public width : number;
public height : number;
}
}
+6 -29
View File
@@ -29,8 +29,8 @@ module Phaser {
this.last = new MicroPoint(x, y); this.last = new MicroPoint(x, y);
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight); this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
this.align = GameObject.ALIGN_TOP_LEFT; this.align = GameObject.ALIGN_TOP_LEFT;
this.mass = 1.0; this.mass = 1;
this.elasticity = 0.0; this.elasticity = 0;
this.health = 1; this.health = 1;
this.immovable = false; this.immovable = false;
this.moves = true; this.moves = true;
@@ -52,7 +52,7 @@ module Phaser {
this.maxAngular = 10000; this.maxAngular = 10000;
this.cameraBlacklist = []; this.cameraBlacklist = [];
this.scrollFactor = new MicroPoint(1.0, 1.0); this.scrollFactor = new MicroPoint(1, 1);
} }
@@ -89,6 +89,8 @@ module Phaser {
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system // rotationOffset to 90 and it would correspond correctly with Phasers rotation system
public rotationOffset: number = 0; public rotationOffset: number = 0;
public renderRotation: bool = true;
// Physics properties // Physics properties
public immovable: bool; public immovable: bool;
@@ -243,17 +245,6 @@ module Phaser {
} }
/*
if (typeof ObjectOrGroup === 'Tilemap')
{
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
// we redirect the call to the tilemap overlap here.
return ObjectOrGroup.overlaps(this, InScreenSpace, Camera);
}
*/
//var object: GameObject = ObjectOrGroup;
if (!InScreenSpace) if (!InScreenSpace)
{ {
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) && return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
@@ -306,20 +297,6 @@ module Phaser {
return results; return results;
} }
/*
if (typeof ObjectOrGroup === 'Tilemap')
{
//Since tilemap's have to be the caller, not the target, to do proper tile-based collisions,
// we redirect the call to the tilemap overlap here.
//However, since this is overlapsAt(), we also have to invent the appropriate position for the tilemap.
//So we calculate the offset between the player and the requested position, and subtract that from the tilemap.
var tilemap: Tilemap = ObjectOrGroup;
return tilemap.overlapsAt(tilemap.x - (X - this.x), tilemap.y - (Y - this.y), this, InScreenSpace, Camera);
}
*/
//var object: GameObject = ObjectOrGroup;
if (!InScreenSpace) if (!InScreenSpace)
{ {
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) && return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
@@ -346,7 +323,7 @@ module Phaser {
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>. * Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
* *
* @param Point The point in world space you want to check. * @param Point The point in world space you want to check.
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. * @param InScreenSpace Whether to take scroll factors into account when checking for overlap.
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera. * @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
* *
* @return Whether or not the point overlaps this object. * @return Whether or not the point overlaps this object.
+40
View File
@@ -0,0 +1,40 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class GeomSprite extends GameObject {
constructor(game: Game, x?: number, y?: number);
private _dx;
private _dy;
private _dw;
private _dh;
public type: number;
static UNASSIGNED: number;
static CIRCLE: number;
static LINE: number;
static POINT: number;
static RECTANGLE: number;
public circle: Circle;
public line: Line;
public point: Point;
public rect: Rectangle;
public renderOutline: bool;
public renderFill: bool;
public lineWidth: number;
public lineColor: string;
public fillColor: string;
public loadCircle(circle: Circle): GeomSprite;
public loadLine(line: Line): GeomSprite;
public loadPoint(point: Point): GeomSprite;
public loadRectangle(rect: Rectangle): GeomSprite;
public createCircle(diameter: number): GeomSprite;
public createLine(x: number, y: number): GeomSprite;
public createPoint(): GeomSprite;
public createRectangle(width: number, height: number): GeomSprite;
public refresh(): void;
public update(): void;
public inCamera(camera: Rectangle): bool;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool;
public renderPoint(offsetX, offsetY, point, size): void;
public renderDebugInfo(x: number, y: number, color?: string): void;
public collide(source: GeomSprite): bool;
}
}
+20 -13
View File
@@ -301,15 +301,24 @@ module Phaser {
// And now the edge points // And now the edge points
this._game.stage.context.fillStyle = 'rgb(255,255,255)'; this._game.stage.context.fillStyle = 'rgb(255,255,255)';
this.renderPoint(this._dx, this._dy, this.rect.topLeft, 2); //this.renderPoint(this.rect.topLeft, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.topCenter, 2); //this.renderPoint(this.rect.topCenter, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.topRight, 2); //this.renderPoint(this.rect.topRight, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.leftCenter, 2); //this.renderPoint(this.rect.leftCenter, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.center, 2); //this.renderPoint(this.rect.center, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.rightCenter, 2); //this.renderPoint(this.rect.rightCenter, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomLeft, 2); //this.renderPoint(this.rect.bottomLeft, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomCenter, 2); //this.renderPoint(this.rect.bottomCenter, this._dx, this._dy, 2);
this.renderPoint(this._dx, this._dy, this.rect.bottomRight, 2); //this.renderPoint(this.rect.bottomRight, this._dx, this._dy, 2);
this.renderPoint(this.rect.topLeft, 0, 0, 2);
this.renderPoint(this.rect.topCenter, 0, 0, 2);
this.renderPoint(this.rect.topRight, 0, 0, 2);
this.renderPoint(this.rect.leftCenter, 0, 0, 2);
this.renderPoint(this.rect.center, 0, 0, 2);
this.renderPoint(this.rect.rightCenter, 0, 0, 2);
this.renderPoint(this.rect.bottomLeft, 0, 0, 2);
this.renderPoint(this.rect.bottomCenter, 0, 0, 2);
this.renderPoint(this.rect.bottomRight, 0, 0, 2);
} }
@@ -330,11 +339,9 @@ module Phaser {
} }
public renderPoint(offsetX, offsetY, point, size) { public renderPoint(point, offsetX?: number = 0, offsetY?: number = 0, size?: number = 1) {
offsetX = 0; this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, size, size);
offsetY = 0;
this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, 1, 1);
} }
+11
View File
@@ -0,0 +1,11 @@
/// <reference path="../Game.d.ts" />
/// <reference path="Sprite.d.ts" />
module Phaser {
class Particle extends Sprite {
constructor(game: Game);
public lifespan: number;
public friction: number;
public update(): void;
public onEmit(): void;
}
}
+2
View File
@@ -22,6 +22,7 @@ module Phaser {
this.lifespan = 0; this.lifespan = 0;
this.friction = 500; this.friction = 500;
} }
/** /**
@@ -43,6 +44,7 @@ module Phaser {
* be dead yet, and then has some special bounce behavior if there is some gravity on it. * be dead yet, and then has some special bounce behavior if there is some gravity on it.
*/ */
public update() { public update() {
//lifespan behavior //lifespan behavior
if (this.lifespan <= 0) if (this.lifespan <= 0)
{ {
+22
View File
@@ -0,0 +1,22 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../geom/Quad.d.ts" />
module Phaser {
class ScrollRegion {
constructor(x: number, y: number, width: number, height: number, speedX: number, speedY: number);
private _A;
private _B;
private _C;
private _D;
private _bounds;
private _scroll;
private _anchorWidth;
private _anchorHeight;
private _inverseWidth;
private _inverseHeight;
public visible: bool;
public scrollSpeed: MicroPoint;
public update(delta: number): void;
public render(context: CanvasRenderingContext2D, texture, dx: number, dy: number, dw: number, dh: number): void;
private crop(context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY);
}
}
+23
View File
@@ -0,0 +1,23 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../geom/Quad.d.ts" />
/// <reference path="ScrollRegion.d.ts" />
module Phaser {
class ScrollZone extends GameObject {
constructor(game: Game, key: string, x?: number, y?: number, width?: number, height?: number);
private _texture;
private _dynamicTexture;
private _dx;
private _dy;
private _dw;
private _dh;
public currentRegion: ScrollRegion;
public regions: ScrollRegion[];
public flipped: bool;
public addRegion(x: number, y: number, width: number, height: number, speedX?: number, speedY?: number): ScrollRegion;
public setSpeed(x: number, y: number): ScrollZone;
public update(): void;
public inCamera(camera: Rectangle): bool;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool;
private createRepeatingTexture(regionWidth, regionHeight);
}
}
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../AnimationManager.d.ts" />
/// <reference path="GameObject.d.ts" />
/// <reference path="../system/Camera.d.ts" />
module Phaser {
class Sprite extends GameObject {
constructor(game: Game, x?: number, y?: number, key?: string);
private _texture;
private _dynamicTexture;
private _sx;
private _sy;
private _sw;
private _sh;
private _dx;
private _dy;
private _dw;
private _dh;
public animations: AnimationManager;
public renderDebug: bool;
public renderDebugColor: string;
public renderDebugPointColor: string;
public flipped: bool;
public loadGraphic(key: string): Sprite;
public loadDynamicTexture(texture: DynamicTexture): Sprite;
public makeGraphic(width: number, height: number, color?: number): Sprite;
public inCamera(camera: Rectangle): bool;
public postUpdate(): void;
public frame : number;
public frameName : string;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool;
private renderBounds(camera, cameraOffsetX, cameraOffsetY);
public renderDebugInfo(x: number, y: number, color?: string): void;
}
}
+1 -1
View File
@@ -229,7 +229,7 @@ module Phaser {
this._game.stage.context.save(); this._game.stage.context.save();
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2)); this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
if (this.angle !== 0 || this.rotationOffset !== 0) if (this.renderRotation == true && (this.angle !== 0 || this.rotationOffset !== 0))
{ {
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180)); this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
} }
+31
View File
@@ -0,0 +1,31 @@
/// <reference path="../Game.d.ts" />
/// <reference path="GameObject.d.ts" />
/// <reference path="../system/TilemapLayer.d.ts" />
/// <reference path="../system/Tile.d.ts" />
module Phaser {
class Tilemap extends GameObject {
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld?: bool, tileWidth?: number, tileHeight?: number);
static FORMAT_CSV: number;
static FORMAT_TILED_JSON: number;
public tiles: Tile[];
public layers: TilemapLayer[];
public currentLayer: TilemapLayer;
public collisionLayer: TilemapLayer;
public mapFormat: number;
public update(): void;
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): void;
private parseCSV(data, key, tileWidth, tileHeight);
private parseTiledJSON(data, key);
private generateTiles(qty);
public widthInPixels : number;
public heightInPixels : number;
public setCollisionRange(start: number, end: number, collision?: number, resetCollisions?: bool): void;
public setCollisionByIndex(values: number[], collision?: number, resetCollisions?: bool): void;
public getTile(x: number, y: number, layer?: number): Tile;
public getTileFromWorldXY(x: number, y: number, layer?: number): Tile;
public getTileFromInputXY(layer?: number): Tile;
public getTileOverlaps(object: GameObject): bool;
public collide(objectOrGroup?, callback?): bool;
public collideGameObject(object: GameObject): bool;
}
}
+151 -12
View File
@@ -1,6 +1,7 @@
/// <reference path="../Game.ts" /> /// <reference path="../Game.ts" />
/// <reference path="GameObject.ts" /> /// <reference path="GameObject.ts" />
/// <reference path="../system/TilemapLayer.ts" /> /// <reference path="../system/TilemapLayer.ts" />
/// <reference path="../system/Tile.ts" />
/** /**
* Phaser - Tilemap * Phaser - Tilemap
@@ -19,7 +20,8 @@ module Phaser {
this.isGroup = false; this.isGroup = false;
this._layers = []; this.tiles = [];
this.layers = [];
this.mapFormat = format; this.mapFormat = format;
@@ -41,12 +43,17 @@ module Phaser {
} }
private _layers : TilemapLayer[]; private _tempCollisionData;
public static FORMAT_CSV: number = 0; public static FORMAT_CSV: number = 0;
public static FORMAT_TILED_JSON: number = 1; public static FORMAT_TILED_JSON: number = 1;
public tiles : Tile[];
public layers : TilemapLayer[];
public currentLayer: TilemapLayer; public currentLayer: TilemapLayer;
public collisionLayer: TilemapLayer;
public collisionCallback = null;
public collisionCallbackContext;
public mapFormat: number; public mapFormat: number;
public update() { public update() {
@@ -57,9 +64,9 @@ module Phaser {
if (this.cameraBlacklist.indexOf(camera.ID) == -1) if (this.cameraBlacklist.indexOf(camera.ID) == -1)
{ {
// Loop through the layers // Loop through the layers
for (var i = 0; i < this._layers.length; i++) for (var i = 0; i < this.layers.length; i++)
{ {
this._layers[i].render(camera, cameraOffsetX, cameraOffsetY); this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
} }
} }
@@ -67,7 +74,7 @@ module Phaser {
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) { private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
var layer: TilemapLayer = new TilemapLayer(this._game, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this._layers.length.toString(), tileWidth, tileHeight); var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
// Trim any rogue whitespace from the data // Trim any rogue whitespace from the data
data = data.trim(); data = data.trim();
@@ -85,10 +92,14 @@ module Phaser {
} }
layer.updateBounds(); layer.updateBounds();
var tileQuantity = layer.parseTileOffsets();
this.currentLayer = layer; this.currentLayer = layer;
this.collisionLayer = layer;
this._layers.push(layer); this.layers.push(layer);
this.generateTiles(tileQuantity);
} }
@@ -101,10 +112,12 @@ module Phaser {
for (var i = 0; i < json.layers.length; i++) for (var i = 0; i < json.layers.length; i++)
{ {
var layer: TilemapLayer = new TilemapLayer(this._game, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight); var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
layer.alpha = json.layers[i].opacity; layer.alpha = json.layers[i].opacity;
layer.visible = json.layers[i].visible; layer.visible = json.layers[i].visible;
layer.tileMargin = json.tilesets[0].margin;
layer.tileSpacing = json.tilesets[0].spacing;
var c = 0; var c = 0;
var row; var row;
@@ -129,12 +142,26 @@ module Phaser {
layer.updateBounds(); layer.updateBounds();
var tileQuantity = layer.parseTileOffsets();
this.currentLayer = layer; this.currentLayer = layer;
this.collisionLayer = layer;
this._layers.push(layer); this.layers.push(layer);
} }
this.generateTiles(tileQuantity);
}
private generateTiles(qty:number) {
for (var i = 0; i < qty; i++)
{
this.tiles.push(new Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
}
} }
public get widthInPixels(): number { public get widthInPixels(): number {
@@ -145,15 +172,127 @@ module Phaser {
return this.currentLayer.heightInPixels; return this.currentLayer.heightInPixels;
} }
// Tile Collision
public setCollisionCallback(context, callback) {
this.collisionCallbackContext = context;
this.collisionCallback = callback;
}
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = start; i < end; i++)
{
this.tiles[i].setCollision(collision, resetCollisions, separateX, separateY);
}
}
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions?: bool = false, separateX?: bool = true, separateY?: bool = true) {
for (var i = 0; i < values.length; i++)
{
this.tiles[values[i]].setCollision(collision, resetCollisions, separateX, separateY);
}
}
// Tile Management
public getTileByIndex(value: number):Tile {
if (this.tiles[value])
{
return this.tiles[value];
}
return null;
}
public getTile(x: number, y: number, layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileIndex(x, y)];
}
public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
}
public getTileFromInputXY(layer?: number = 0):Tile {
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.worldX, this._game.input.worldY)];
}
public getTileOverlaps(object: GameObject) {
return this.currentLayer.getTileOverlaps(object);
}
// COLLIDE
public collide(objectOrGroup = null, callback = null, context = null) {
if (callback !== null && context !== null)
{
this.collisionCallback = callback;
this.collisionCallbackContext = context;
}
if (objectOrGroup == null)
{
objectOrGroup = this._game.world.group;
}
// Group?
if (objectOrGroup.isGroup == false)
{
this.collideGameObject(objectOrGroup);
}
else
{
objectOrGroup.forEachAlive(this, this.collideGameObject, true);
}
}
public collideGameObject(object: GameObject): bool {
if (object !== this && object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
{
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
if (this.collisionCallback !== null && this._tempCollisionData.length > 0)
{
this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
}
return true;
}
else
{
return false;
}
}
public putTile(x: number, y: number, index: number, layer?: number = 0) {
this.layers[layer].putTile(x, y, index);
}
// Set current layer // Set current layer
// Set layer order? // Set layer order?
// Get tile from x/y
// Get block of tiles
// Swap tiles around
// Delete tiles of certain type // Delete tiles of certain type
// Erase tiles // Erase tiles
} }
} }
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Circle {
constructor(x?: number, y?: number, diameter?: number);
private _diameter;
private _radius;
public x: number;
public y: number;
public diameter : number;
public radius : number;
public circumference(): number;
public bottom : number;
public left : number;
public right : number;
public top : number;
public area : number;
public isEmpty : bool;
public intersectCircleLine(line: Line): bool;
public clone(output?: Circle): Circle;
public contains(x: number, y: number): bool;
public containsPoint(point: Point): bool;
public containsCircle(circle: Circle): bool;
public copyFrom(source: Circle): Circle;
public copyTo(target: Circle): Circle;
public distanceTo(target: any, round?: bool): number;
public equals(toCompare: Circle): bool;
public intersects(toIntersect: Circle): bool;
public circumferencePoint(angle: number, asDegrees?: bool, output?: Point): Point;
public offset(dx: number, dy: number): Circle;
public offsetPoint(point: Point): Circle;
public setTo(x: number, y: number, diameter: number): Circle;
public toString(): string;
}
}
+1 -1
View File
@@ -262,7 +262,7 @@ module Phaser {
**/ **/
get isEmpty(): bool { get isEmpty(): bool {
if (this._diameter < 1) if (this._diameter <= 0)
{ {
return true; return true;
} }
+15
View File
@@ -0,0 +1,15 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class IntersectResult {
public result: bool;
public x: number;
public y: number;
public x1: number;
public y1: number;
public x2: number;
public y2: number;
public width: number;
public height: number;
public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void;
}
}
+27
View File
@@ -0,0 +1,27 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Line {
constructor(x1?: number, y1?: number, x2?: number, y2?: number);
public x1: number;
public y1: number;
public x2: number;
public y2: number;
public clone(output?: Line): Line;
public copyFrom(source: Line): Line;
public copyTo(target: Line): Line;
public setTo(x1?: number, y1?: number, x2?: number, y2?: number): Line;
public width : number;
public height : number;
public length : number;
public getY(x: number): number;
public angle : number;
public slope : number;
public perpSlope : number;
public yIntercept : number;
public isPointOnLine(x: number, y: number): bool;
public isPointOnLineSegment(x: number, y: number): bool;
public intersectLineLine(line): any;
public perp(x: number, y: number, output?: Line): Line;
public toString(): string;
}
}
+16
View File
@@ -0,0 +1,16 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class MicroPoint {
constructor(x?: number, y?: number, parent?: any);
private _x;
private _y;
public parent: any;
public x : number;
public y : number;
public copyFrom(source: any): MicroPoint;
public copyTo(target: any): MicroPoint;
public setTo(x: number, y: number, callParent?: bool): MicroPoint;
public equals(toCompare): bool;
public toString(): string;
}
}
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Point {
constructor(x?: number, y?: number);
public x: number;
public y: number;
public add(toAdd: Point, output?: Point): Point;
public addTo(x?: number, y?: number): Point;
public subtractFrom(x?: number, y?: number): Point;
public invert(): Point;
public clamp(min: number, max: number): Point;
public clampX(min: number, max: number): Point;
public clampY(min: number, max: number): Point;
public clone(output?: Point): Point;
public copyFrom(source: Point): Point;
public copyTo(target: Point): Point;
public distanceTo(target: Point, round?: bool): number;
static distanceBetween(pointA: Point, pointB: Point, round?: bool): number;
public distanceCompare(target: Point, distance: number): bool;
public equals(toCompare: Point): bool;
public interpolate(pointA, pointB, f): void;
public offset(dx: number, dy: number): Point;
public polar(length, angle): void;
public setTo(x: number, y: number): Point;
public subtract(point: Point, output?: Point): Point;
public toString(): string;
}
}
+19
View File
@@ -0,0 +1,19 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Quad {
constructor(x?: number, y?: number, width?: number, height?: number);
public x: number;
public y: number;
public width: number;
public height: number;
public setTo(x: number, y: number, width: number, height: number): Quad;
public left : number;
public right : number;
public top : number;
public bottom : number;
public halfWidth : number;
public halfHeight : number;
public intersects(q, t?: number): bool;
public toString(): string;
}
}
+10 -2
View File
@@ -68,15 +68,23 @@ module Phaser {
return this.y + this.height; return this.y + this.height;
} }
public get halfWidth(): number {
return this.width / 2;
}
public get halfHeight(): number {
return this.height / 2;
}
/** /**
* Determines whether the object specified intersects (overlaps) with this Quad object. * Determines whether the object specified intersects (overlaps) with this Quad object.
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object. * This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
* @method intersects * @method intersects
* @param {Quad} q The Quad to compare against to see if it intersects with this Quad. * @param {Object} q The object to check for intersection with this Quad. Must have left/right/top/bottom properties (Rectangle, Quad).
* @param {Number} t A tolerance value to allow for an intersection test with padding, default to 0 * @param {Number} t A tolerance value to allow for an intersection test with padding, default to 0
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false. * @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
**/ **/
public intersects(q: Quad, t?: number = 0): bool { public intersects(q, t?: number = 0): bool {
return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t); return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
+57
View File
@@ -0,0 +1,57 @@
/// <reference path="../Game.d.ts" />
/// <reference path="MicroPoint.d.ts" />
module Phaser {
class Rectangle {
constructor(x?: number, y?: number, width?: number, height?: number);
private _tempX;
private _tempY;
private _tempWidth;
private _tempHeight;
public x : number;
public y : number;
public topLeft: MicroPoint;
public topCenter: MicroPoint;
public topRight: MicroPoint;
public leftCenter: MicroPoint;
public center: MicroPoint;
public rightCenter: MicroPoint;
public bottomLeft: MicroPoint;
public bottomCenter: MicroPoint;
public bottomRight: MicroPoint;
private _width;
private _height;
private _halfWidth;
private _halfHeight;
public length: number;
public updateBounds(): void;
public width : number;
public height : number;
public halfWidth : number;
public halfHeight : number;
public bottom : number;
public left : number;
public right : number;
public size(output?: Point): Point;
public volume : number;
public perimeter : number;
public top : number;
public clone(output?: Rectangle): Rectangle;
public contains(x: number, y: number): bool;
public containsPoint(point: any): bool;
public containsRect(rect: Rectangle): bool;
public copyFrom(source: Rectangle): Rectangle;
public copyTo(target: Rectangle): Rectangle;
public equals(toCompare: Rectangle): bool;
public inflate(dx: number, dy: number): Rectangle;
public inflatePoint(point: Point): Rectangle;
public intersection(toIntersect: Rectangle, output?: Rectangle): Rectangle;
public intersects(r2: Rectangle, t?: number): bool;
public isEmpty : bool;
public offset(dx: number, dy: number): Rectangle;
public offsetPoint(point: Point): Rectangle;
public setEmpty(): Rectangle;
public setTo(x: number, y: number, width: number, height: number): Rectangle;
public union(toUnion: Rectangle, output?: Rectangle): Rectangle;
public toString(): string;
}
}
+3 -3
View File
@@ -1,13 +1,13 @@
/** /**
* Phaser * Phaser
* *
* v0.9.3 - April 22nd 2013 * v0.9.5 - April 28th 2013
* *
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi. * A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
* *
* Richard Davey (@photonstorm) * Richard Davey (@photonstorm)
* *
* Many thanks to Adam Saltsman (@ADAMATOMIC) for the original Flixel AS3 code on which Phaser is based. * Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel on which Phaser took a lot of inspiration.
* *
* "If you want your children to be intelligent, read them fairy tales." * "If you want your children to be intelligent, read them fairy tales."
* "If you want them to be more intelligent, read them more fairy tales." * "If you want them to be more intelligent, read them more fairy tales."
@@ -15,5 +15,5 @@
*/ */
var Phaser; var Phaser;
(function (Phaser) { (function (Phaser) {
Phaser.VERSION = 'Phaser version 0.9.3'; Phaser.VERSION = 'Phaser version 0.9.5';
})(Phaser || (Phaser = {})); })(Phaser || (Phaser = {}));
+80
View File
@@ -0,0 +1,80 @@
/// <reference path="../gameobjects/Sprite.d.ts" />
/// <reference path="../Game.d.ts" />
module Phaser {
class Camera {
constructor(game: Game, id: number, x: number, y: number, width: number, height: number);
private _game;
private _clip;
private _stageX;
private _stageY;
private _rotation;
private _target;
private _sx;
private _sy;
private _fxFlashColor;
private _fxFlashComplete;
private _fxFlashDuration;
private _fxFlashAlpha;
private _fxFadeColor;
private _fxFadeComplete;
private _fxFadeDuration;
private _fxFadeAlpha;
private _fxShakeIntensity;
private _fxShakeDuration;
private _fxShakeComplete;
private _fxShakeOffset;
private _fxShakeDirection;
private _fxShakePrevX;
private _fxShakePrevY;
static STYLE_LOCKON: number;
static STYLE_PLATFORMER: number;
static STYLE_TOPDOWN: number;
static STYLE_TOPDOWN_TIGHT: number;
static SHAKE_BOTH_AXES: number;
static SHAKE_HORIZONTAL_ONLY: number;
static SHAKE_VERTICAL_ONLY: number;
public ID: number;
public worldView: Rectangle;
public totalSpritesRendered: number;
public scale: MicroPoint;
public scroll: MicroPoint;
public bounds: Rectangle;
public deadzone: Rectangle;
public showBorder: bool;
public borderColor: string;
public opaque: bool;
private _bgColor;
private _bgTexture;
private _bgTextureRepeat;
public showShadow: bool;
public shadowColor: string;
public shadowBlur: number;
public shadowOffset: MicroPoint;
public visible: bool;
public alpha: number;
public inputX: number;
public inputY: number;
public fx: FXManager;
public flash(color?: number, duration?: number, onComplete?, force?: bool): void;
public fade(color?: number, duration?: number, onComplete?, force?: bool): void;
public shake(intensity?: number, duration?: number, onComplete?, force?: bool, direction?: number): void;
public stopFX(): void;
public follow(target: Sprite, style?: number): void;
public focusOnXY(x: number, y: number): void;
public focusOn(point): void;
public setBounds(x?: number, y?: number, width?: number, height?: number): void;
public update(): void;
public render(): void;
public backgroundColor : string;
public setTexture(key: string, repeat?: string): void;
public setPosition(x: number, y: number): void;
public setSize(width: number, height: number): void;
public renderDebugInfo(x: number, y: number, color?: string): void;
public x : number;
public y : number;
public width : number;
public height : number;
public rotation : number;
private checkClip();
}
}
+42 -248
View File
@@ -29,6 +29,7 @@ module Phaser {
this.ID = id; this.ID = id;
this._stageX = x; this._stageX = x;
this._stageY = y; this._stageY = y;
this.fx = new FXManager(this._game, this);
// The view into the world canvas we wish to render // The view into the world canvas we wish to render
this.worldView = new Rectangle(0, 0, width, height); this.worldView = new Rectangle(0, 0, width, height);
@@ -47,42 +48,21 @@ module Phaser {
private _sx: number = 0; private _sx: number = 0;
private _sy: number = 0; private _sy: number = 0;
private _fxFlashColor: string;
private _fxFlashComplete = null;
private _fxFlashDuration: number = 0;
private _fxFlashAlpha: number = 0;
private _fxFadeColor: string;
private _fxFadeComplete = null;
private _fxFadeDuration: number = 0;
private _fxFadeAlpha: number = 0;
private _fxShakeIntensity: number = 0;
private _fxShakeDuration: number = 0;
private _fxShakeComplete = null;
private _fxShakeOffset: Point = new Point(0, 0);
private _fxShakeDirection: number = 0;
private _fxShakePrevX: number = 0;
private _fxShakePrevY: number = 0;
public static STYLE_LOCKON: number = 0; public static STYLE_LOCKON: number = 0;
public static STYLE_PLATFORMER: number = 1; public static STYLE_PLATFORMER: number = 1;
public static STYLE_TOPDOWN: number = 2; public static STYLE_TOPDOWN: number = 2;
public static STYLE_TOPDOWN_TIGHT: number = 3; public static STYLE_TOPDOWN_TIGHT: number = 3;
public static SHAKE_BOTH_AXES: number = 0;
public static SHAKE_HORIZONTAL_ONLY: number = 1;
public static SHAKE_VERTICAL_ONLY: number = 2;
public ID: number; public ID: number;
public worldView: Rectangle; public worldView: Rectangle;
public totalSpritesRendered: number; public totalSpritesRendered: number;
public scale: Point = new Point(1, 1); public scale: MicroPoint = new MicroPoint(1, 1);
public scroll: Point = new Point(0, 0); public scroll: MicroPoint = new MicroPoint(0, 0);
public bounds: Rectangle = null; public bounds: Rectangle = null;
public deadzone: Rectangle = null; public deadzone: Rectangle = null;
// Camera Border // Camera Border
public disableClipping: bool = false;
public showBorder: bool = false; public showBorder: bool = false;
public borderColor: string = 'rgb(255,255,255)'; public borderColor: string = 'rgb(255,255,255)';
@@ -96,7 +76,7 @@ module Phaser {
public showShadow: bool = false; public showShadow: bool = false;
public shadowColor: string = 'rgb(0,0,0)'; public shadowColor: string = 'rgb(0,0,0)';
public shadowBlur: number = 10; public shadowBlur: number = 10;
public shadowOffset: Point = new Point(4, 4); public shadowOffset: MicroPoint = new MicroPoint(4, 4);
public visible: bool = true; public visible: bool = true;
public alpha: number = 1; public alpha: number = 1;
@@ -105,122 +85,12 @@ module Phaser {
public inputX: number = 0; public inputX: number = 0;
public inputY: number = 0; public inputY: number = 0;
/** public fx: FXManager;
* The camera is filled with this color and returns to normal at the given duration.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
public flash(color: number = 0xffffff, duration: number = 1, onComplete = null, force: bool = false) {
if (force === false && this._fxFlashAlpha > 0)
{
// You can't flash again unless you force it
return;
}
if (duration <= 0)
{
duration = 1;
}
var red = color >> 16 & 0xFF;
var green = color >> 8 & 0xFF;
var blue = color & 0xFF;
this._fxFlashColor = 'rgba(' + red + ',' + green + ',' + blue + ',';
this._fxFlashDuration = duration;
this._fxFlashAlpha = 1;
this._fxFlashComplete = onComplete;
}
/**
* The camera is gradually filled with this color.
*
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
* @param Duration How long it takes for the flash to fade.
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
* @param Force Force an already running flash effect to reset.
*/
public fade(color: number = 0x000000, duration: number = 1, onComplete = null, force: bool = false) {
if (force === false && this._fxFadeAlpha > 0)
{
// You can't fade again unless you force it
return;
}
if (duration <= 0)
{
duration = 1;
}
var red = color >> 16 & 0xFF;
var green = color >> 8 & 0xFF;
var blue = color & 0xFF;
this._fxFadeColor = 'rgba(' + red + ',' + green + ',' + blue + ',';
this._fxFadeDuration = duration;
this._fxFadeAlpha = 0.01;
this._fxFadeComplete = onComplete;
}
/**
* A simple screen-shake effect.
*
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
* @param Duration The length in seconds that the shaking effect should last.
* @param OnComplete A function you want to run when the shake effect finishes.
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
*/
public shake(intensity: number = 0.05, duration: number = 0.5, onComplete = null, force: bool = true, direction: number = Camera.SHAKE_BOTH_AXES) {
if (!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)))
{
return;
}
// If a shake is not already running we need to store the offsets here
if (this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0)
{
this._fxShakePrevX = this._stageX;
this._fxShakePrevY = this._stageY;
}
this._fxShakeIntensity = intensity;
this._fxShakeDuration = duration;
this._fxShakeComplete = onComplete;
this._fxShakeDirection = direction;
this._fxShakeOffset.setTo(0, 0);
}
/**
* Just turns off all the camera effects instantly.
*/
public stopFX() {
this._fxFlashAlpha = 0;
this._fxFadeAlpha = 0;
if (this._fxShakeDuration !== 0)
{
this._fxShakeDuration = 0;
this._fxShakeOffset.setTo(0, 0);
this._stageX = this._fxShakePrevX;
this._stageY = this._fxShakePrevY;
}
}
public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) { public follow(target: Sprite, style?: number = Camera.STYLE_LOCKON) {
this._target = target; this._target = target;
var helper: number; var helper: number;
switch (style) switch (style)
@@ -256,7 +126,7 @@ module Phaser {
} }
public focusOn(point: Point) { public focusOn(point) {
point.x += (point.x > 0) ? 0.0000001 : -0.0000001; point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
point.y += (point.y > 0) ? 0.0000001 : -0.0000001; point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
@@ -269,29 +139,29 @@ module Phaser {
/** /**
* Specify the boundaries of the world or where the camera is allowed to move. * Specify the boundaries of the world or where the camera is allowed to move.
* *
* @param X The smallest X value of your world (usually 0). * @param x The smallest X value of your world (usually 0).
* @param Y The smallest Y value of your world (usually 0). * @param y The smallest Y value of your world (usually 0).
* @param Width The largest X value of your world (usually the world width). * @param width The largest X value of your world (usually the world width).
* @param Height The largest Y value of your world (usually the world height). * @param height The largest Y value of your world (usually the world height).
* @param UpdateWorld Whether the global quad-tree's dimensions should be updated to match (default: false).
*/ */
public setBounds(X: number = 0, Y: number = 0, Width: number = 0, Height: number = 0, UpdateWorld: bool = false) { public setBounds(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
if (this.bounds == null) if (this.bounds == null)
{ {
this.bounds = new Rectangle(); this.bounds = new Rectangle();
} }
this.bounds.setTo(X, Y, Width, Height); this.bounds.setTo(x, y, width, height);
//if(UpdateWorld) this.scroll.setTo(0, 0);
// G.worldBounds.copyFrom(bounds);
this.update(); this.update();
} }
public update() { public update() {
this.fx.preUpdate();
if (this._target !== null) if (this._target !== null)
{ {
if (this.deadzone == null) if (this.deadzone == null)
@@ -335,7 +205,7 @@ module Phaser {
} }
// Make sure we didn't go outside the camera's bounds // Make sure we didn't go outside the cameras bounds
if (this.bounds !== null) if (this.bounds !== null)
{ {
if (this.scroll.x < this.bounds.left) if (this.scroll.x < this.bounds.left)
@@ -345,7 +215,7 @@ module Phaser {
if (this.scroll.x > this.bounds.right - this.width) if (this.scroll.x > this.bounds.right - this.width)
{ {
this.scroll.x = this.bounds.right - this.width; this.scroll.x = (this.bounds.right - this.width) + 1;
} }
if (this.scroll.y < this.bounds.top) if (this.scroll.y < this.bounds.top)
@@ -355,7 +225,7 @@ module Phaser {
if (this.scroll.y > this.bounds.bottom - this.height) if (this.scroll.y > this.bounds.bottom - this.height)
{ {
this.scroll.y = this.bounds.bottom - this.height; this.scroll.y = (this.bounds.bottom - this.height) + 1;
} }
} }
@@ -366,74 +236,7 @@ module Phaser {
this.inputX = this.worldView.x + this._game.input.x; this.inputX = this.worldView.x + this._game.input.x;
this.inputY = this.worldView.y + this._game.input.y; this.inputY = this.worldView.y + this._game.input.y;
// Update the Flash effect this.fx.postUpdate();
if (this._fxFlashAlpha > 0)
{
this._fxFlashAlpha -= this._game.time.elapsed / this._fxFlashDuration;
this._fxFlashAlpha = this._game.math.roundTo(this._fxFlashAlpha, -2);
if (this._fxFlashAlpha <= 0)
{
this._fxFlashAlpha = 0;
if (this._fxFlashComplete !== null)
{
this._fxFlashComplete();
}
}
}
// Update the Fade effect
if (this._fxFadeAlpha > 0)
{
this._fxFadeAlpha += this._game.time.elapsed / this._fxFadeDuration;
this._fxFadeAlpha = this._game.math.roundTo(this._fxFadeAlpha, -2);
if (this._fxFadeAlpha >= 1)
{
this._fxFadeAlpha = 1;
if (this._fxFadeComplete !== null)
{
this._fxFadeComplete();
}
}
}
// Update the "shake" special effect
if (this._fxShakeDuration > 0)
{
this._fxShakeDuration -= this._game.time.elapsed;
this._fxShakeDuration = this._game.math.roundTo(this._fxShakeDuration, -2);
if (this._fxShakeDuration <= 0)
{
this._fxShakeDuration = 0;
this._fxShakeOffset.setTo(0, 0);
this._stageX = this._fxShakePrevX;
this._stageY = this._fxShakePrevY;
if (this._fxShakeComplete != null)
{
this._fxShakeComplete();
}
}
else
{
if ((this._fxShakeDirection == Camera.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Camera.SHAKE_HORIZONTAL_ONLY))
{
//this._fxShakeOffset.x = ((this._game.math.random() * this._fxShakeIntensity * this.worldView.width * 2 - this._fxShakeIntensity * this.worldView.width) * this._zoom;
this._fxShakeOffset.x = (this._game.math.random() * this._fxShakeIntensity * this.worldView.width * 2 - this._fxShakeIntensity * this.worldView.width);
}
if ((this._fxShakeDirection == Camera.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Camera.SHAKE_VERTICAL_ONLY))
{
//this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this.worldView.height * 2 - this._fxShakeIntensity * this.worldView.height) * this._zoom;
this._fxShakeOffset.y = (this._game.math.random() * this._fxShakeIntensity * this.worldView.height * 2 - this._fxShakeIntensity * this.worldView.height);
}
}
}
} }
@@ -444,23 +247,16 @@ module Phaser {
return; return;
} }
if ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))
{
//this._stageX = this._fxShakePrevX + (this.worldView.halfWidth * this._zoom) + this._fxShakeOffset.x;
//this._stageY = this._fxShakePrevY + (this.worldView.halfHeight * this._zoom) + this._fxShakeOffset.y;
this._stageX = this._fxShakePrevX + (this.worldView.halfWidth) + this._fxShakeOffset.x;
this._stageY = this._fxShakePrevY + (this.worldView.halfHeight) + this._fxShakeOffset.y;
//console.log('shake', this._fxShakeDuration, this._fxShakeIntensity, this._fxShakeOffset.x, this._fxShakeOffset.y);
}
//if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1) //if (this._rotation !== 0 || this._clip || this.scale.x !== 1 || this.scale.y !== 1)
//{ //{
//this._game.stage.context.save(); //this._game.stage.context.save();
//} //}
// It may be safe/quicker to just save the context every frame regardless // It may be safer/quicker to just save the context every frame regardless (needs testing on mobile)
this._game.stage.context.save(); this._game.stage.context.save();
this.fx.preRender(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
if (this.alpha !== 1) if (this.alpha !== 1)
{ {
this._game.stage.context.globalAlpha = this.alpha; this._game.stage.context.globalAlpha = this.alpha;
@@ -496,7 +292,6 @@ module Phaser {
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight)); this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
} }
// Background // Background
if (this.opaque == true) if (this.opaque == true)
{ {
@@ -520,8 +315,10 @@ module Phaser {
this._game.stage.context.shadowOffsetY = 0; this._game.stage.context.shadowOffsetY = 0;
} }
this.fx.render(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
// Clip the camera so we don't get sprites appearing outside the edges // Clip the camera so we don't get sprites appearing outside the edges
if (this._clip) if (this._clip && this.disableClipping == false)
{ {
this._game.stage.context.beginPath(); this._game.stage.context.beginPath();
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height); this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
@@ -539,33 +336,19 @@ module Phaser {
this._game.stage.context.stroke(); this._game.stage.context.stroke();
} }
// "Flash" FX
if (this._fxFlashAlpha > 0)
{
this._game.stage.context.fillStyle = this._fxFlashColor + this._fxFlashAlpha + ')';
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
}
// "Fade" FX
if (this._fxFadeAlpha > 0)
{
this._game.stage.context.fillStyle = this._fxFadeColor + this._fxFadeAlpha + ')';
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
}
// Scale off // Scale off
if (this.scale.x !== 1 || this.scale.y !== 1) if (this.scale.x !== 1 || this.scale.y !== 1)
{ {
this._game.stage.context.scale(1, 1); this._game.stage.context.scale(1, 1);
} }
if (this._rotation !== 0 || this._clip) this.fx.postRender(this, this._sx, this._sy, this.worldView.width, this.worldView.height);
if (this._rotation !== 0 || (this._clip && this.disableClipping == false))
{ {
this._game.stage.context.translate(0, 0); this._game.stage.context.translate(0, 0);
//this._game.stage.context.restore();
} }
// maybe just do this every frame regardless?
this._game.stage.context.restore(); this._game.stage.context.restore();
if (this.alpha !== 1) if (this.alpha !== 1)
@@ -605,7 +388,6 @@ module Phaser {
this.worldView.width = width; this.worldView.width = width;
this.worldView.height = height; this.worldView.height = height;
this.checkClip(); this.checkClip();
} }
@@ -647,6 +429,12 @@ module Phaser {
} }
public set width(value: number) { public set width(value: number) {
if (value > this._game.stage.width)
{
value = this._game.stage.width;
}
this.worldView.width = value; this.worldView.width = value;
this.checkClip(); this.checkClip();
} }
@@ -656,6 +444,12 @@ module Phaser {
} }
public set height(value: number) { public set height(value: number) {
if (value > this._game.stage.height)
{
value = this._game.stage.height;
}
this.worldView.height = value; this.worldView.height = value;
this.checkClip(); this.checkClip();
} }
+49
View File
@@ -0,0 +1,49 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Device {
constructor();
public desktop: bool;
public iOS: bool;
public android: bool;
public chromeOS: bool;
public linux: bool;
public macOS: bool;
public windows: bool;
public canvas: bool;
public file: bool;
public fileSystem: bool;
public localStorage: bool;
public webGL: bool;
public worker: bool;
public touch: bool;
public css3D: bool;
public arora: bool;
public chrome: bool;
public epiphany: bool;
public firefox: bool;
public ie: bool;
public ieVersion: number;
public mobileSafari: bool;
public midori: bool;
public opera: bool;
public safari: bool;
public webApp: bool;
public audioData: bool;
public webaudio: bool;
public ogg: bool;
public mp3: bool;
public wav: bool;
public m4a: bool;
public iPhone: bool;
public iPhone4: bool;
public iPad: bool;
public pixelRatio: number;
private _checkOS();
private _checkFeatures();
private _checkBrowser();
private _checkAudio();
private _checkDevice();
private _checkCSS3D();
public getAll(): string;
}
}
+9
View File
@@ -0,0 +1,9 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class LinkedList {
constructor();
public object: Basic;
public next: LinkedList;
public destroy(): void;
}
}
+53
View File
@@ -0,0 +1,53 @@
/// <reference path="../Game.d.ts" />
/// <reference path="LinkedList.d.ts" />
module Phaser {
class QuadTree extends Rectangle {
constructor(X: number, Y: number, Width: number, Height: number, Parent?: QuadTree);
static A_LIST: number;
static B_LIST: number;
static divisions: number;
private _canSubdivide;
private _headA;
private _tailA;
private _headB;
private _tailB;
private static _min;
private _northWestTree;
private _northEastTree;
private _southEastTree;
private _southWestTree;
private _leftEdge;
private _rightEdge;
private _topEdge;
private _bottomEdge;
private _halfWidth;
private _halfHeight;
private _midpointX;
private _midpointY;
private static _object;
private static _objectLeftEdge;
private static _objectTopEdge;
private static _objectRightEdge;
private static _objectBottomEdge;
private static _list;
private static _useBothLists;
private static _processingCallback;
private static _notifyCallback;
private static _iterator;
private static _objectHullX;
private static _objectHullY;
private static _objectHullWidth;
private static _objectHullHeight;
private static _checkObjectHullX;
private static _checkObjectHullY;
private static _checkObjectHullWidth;
private static _checkObjectHullHeight;
public destroy(): void;
public load(ObjectOrGroup1: Basic, ObjectOrGroup2?: Basic, NotifyCallback?, ProcessCallback?): void;
public add(ObjectOrGroup: Basic, List: number): void;
private addObject();
private addToList();
public execute(): bool;
private overlapNode();
}
}
-2
View File
@@ -704,8 +704,6 @@ module Phaser {
*/ */
private overlapNode(): bool { private overlapNode(): bool {
//console.log('overlapNode');
//Walk the list and check for overlaps //Walk the list and check for overlaps
var overlapProcessed: bool = false; var overlapProcessed: bool = false;
var checkObject; var checkObject;
+26
View File
@@ -0,0 +1,26 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class RandomDataGenerator {
constructor(seeds?: string[]);
private s0;
private s1;
private s2;
private c;
private uint32();
private fract32();
private rnd();
private hash(data);
public sow(seeds?: string[]): void;
public integer : number;
public frac : number;
public real : number;
public integerInRange(min: number, max: number): number;
public realInRange(min: number, max: number): number;
public normal : number;
public uuid : string;
public pick(array);
public weightedPick(array);
public timestamp(min?: number, max?: number): number;
public angle : number;
}
}
+20
View File
@@ -0,0 +1,20 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class RequestAnimationFrame {
constructor(callback, callbackContext);
private _callback;
private _callbackContext;
public setCallback(callback): void;
private _timeOutID;
private _isSetTimeOut;
public isUsingSetTimeOut(): bool;
public isUsingRAF(): bool;
public lastTime: number;
public currentTime: number;
public isRunning: bool;
public start(callback?): void;
public stop(): void;
public RAFUpdate(): void;
public SetTimeoutUpdate(): void;
}
}
+23
View File
@@ -0,0 +1,23 @@
/// <reference path="../Game.d.ts" />
/// <reference path="../SoundManager.d.ts" />
module Phaser {
class Sound {
constructor(context, gainNode, data, volume?: number, loop?: bool);
private _context;
private _gainNode;
private _localGainNode;
private _buffer;
private _volume;
private _sound;
public loop: bool;
public duration: number;
public isPlaying: bool;
public isDecoding: bool;
public setDecodedBuffer(data): void;
public play(): void;
public stop(): void;
public mute(): void;
public unmute(): void;
public volume : number;
}
}
+1 -1
View File
@@ -54,7 +54,7 @@ module Phaser {
this._buffer = data; this._buffer = data;
this.isDecoding = false; this.isDecoding = false;
this.play(); //this.play();
} }
+21
View File
@@ -0,0 +1,21 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class StageScaleMode {
constructor(game: Game);
private _game;
private _startHeight;
private _iterations;
private _check;
static EXACT_FIT: number;
static NO_SCALE: number;
static SHOW_ALL: number;
public width: number;
public height: number;
public orientation;
public update(): void;
public isLandscape : bool;
private checkOrientation(event);
private refresh();
private setScreenSize();
}
}
+22
View File
@@ -0,0 +1,22 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class Tile {
constructor(game: Game, tilemap: Tilemap, index: number, width: number, height: number);
private _game;
public name: string;
public mass: number;
public width: number;
public height: number;
public allowCollisions: number;
public collideLeft: bool;
public collideRight: bool;
public collideUp: bool;
public collideDown: bool;
public tilemap: Tilemap;
public index: number;
public destroy(): void;
public setCollision(collision: number, resetCollisions: bool): void;
public resetCollision(): void;
public toString(): string;
}
}
+90 -47
View File
@@ -3,55 +3,43 @@
/** /**
* Phaser - Tile * Phaser - Tile
* *
* A simple helper object for <code>Tilemap</code> that helps expand collision opportunities and control. * A Tile is a single representation of a tile within a Tilemap
*/ */
module Phaser { module Phaser {
export class Tile extends GameObject { export class Tile {
/** constructor(game: Game, tilemap: Tilemap, index: number, width: number, height: number) {
* Instantiate this new tile object. This is usually called from <code>Tilemap.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) {
super(game, 0, 0, Width, Height); this._game = game;
this.tilemap = tilemap;
this.index = index;
this.immovable = true; this.width = width;
this.moves = false; this.height = height;
this.callback = null; this.allowCollisions = Collision.NONE;
this.filter = null;
this.tilemap = Tilemap;
this.index = Index;
this.visible = Visible;
this.allowCollisions = AllowCollisions;
this.mapIndex = 0;
} }
/** private _game: Game;
* This function is called whenever an object hits a tile of this type.
* This function should take the form <code>myFunction(Tile:Tile,Object:Object)</code>.
* Defaults to null, set through <code>Tilemap.setTileProperties()</code>.
*/
public callback;
/** // You can give this Tile a friendly name to help with debugging. Never used internally.
* Each tile can store its own filter class for their callback functions. public name: string;
* That is, the callback will only be triggered if an object with a class
* type matching the filter touched it. public mass: number = 1.0;
* Defaults to null, set through <code>Tilemap.setTileProperties()</code>. public width: number;
*/ public height: number;
public filter;
public allowCollisions: number;
public collideLeft: bool = false;
public collideRight: bool = false;
public collideUp: bool = false;
public collideDown: bool = false;
public separateX: bool = true;
public separateY: bool = true;
/** /**
* A reference to the tilemap this tile object belongs to. * A reference to the tilemap this tile object belongs to.
@@ -65,24 +53,79 @@ module Phaser {
*/ */
public index: number; 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. * Clean up memory.
*/ */
public destroy() { public destroy() {
super.destroy();
this.callback = null;
this.tilemap = null; this.tilemap = null;
} }
public setCollision(collision: number, resetCollisions: bool, separateX: bool, separateY: bool) {
if (resetCollisions)
{
this.resetCollision();
}
this.separateX = separateX;
this.separateY = separateY;
this.allowCollisions = collision;
if (collision & Collision.ANY)
{
this.collideLeft = true;
this.collideRight = true;
this.collideUp = true;
this.collideDown = true;
return;
}
if (collision & Collision.LEFT || collision & Collision.WALL)
{
this.collideLeft = true;
}
if (collision & Collision.RIGHT || collision & Collision.WALL)
{
this.collideRight = true;
}
if (collision & Collision.UP || collision & Collision.CEILING)
{
this.collideUp = true;
}
if (collision & Collision.DOWN || collision & Collision.CEILING)
{
this.collideDown = true;
}
}
public resetCollision() {
this.allowCollisions = Collision.NONE;
this.collideLeft = false;
this.collideRight = false;
this.collideUp = false;
this.collideDown = false;
}
/**
* Returns a string representation of this object.
* @method toString
* @return {string} a string representation of the object.
**/
public toString(): string {
return "[{Tiled (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]";
}
} }
} }
+51
View File
@@ -0,0 +1,51 @@
/// <reference path="../Game.d.ts" />
module Phaser {
class TilemapLayer {
constructor(game: Game, parent: Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number);
private _game;
private _parent;
private _texture;
private _tileOffsets;
private _startX;
private _startY;
private _maxX;
private _maxY;
private _tx;
private _ty;
private _dx;
private _dy;
private _oldCameraX;
private _oldCameraY;
private _columnData;
private _tempTileX;
private _tempTileY;
private _tempTileW;
private _tempTileH;
public name: string;
public alpha: number;
public exists: bool;
public visible: bool;
public orientation: string;
public properties: {};
public mapData;
public mapFormat: number;
public boundsInTiles: Rectangle;
public tileWidth: number;
public tileHeight: number;
public widthInTiles: number;
public heightInTiles: number;
public widthInPixels: number;
public heightInPixels: number;
public tileMargin: number;
public tileSpacing: number;
public getTileFromWorldXY(x: number, y: number): number;
public getTileOverlaps(object: GameObject): bool;
public getTileBlock(x: number, y: number, width: number, height: number): any[];
public getTileIndex(x: number, y: number): number;
public addColumn(column): void;
public updateBounds(): void;
public parseTileOffsets(): number;
public renderDebugInfo(x: number, y: number, color?: string): void;
public render(camera: Camera, dx, dy): bool;
}
}
+230 -6
View File
@@ -10,9 +10,10 @@ module Phaser {
export class TilemapLayer { export class TilemapLayer {
constructor(game: Game, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) { constructor(game: Game, parent:Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number) {
this._game = game; this._game = game;
this._parent = parent;
this.name = name; this.name = name;
this.mapFormat = mapFormat; this.mapFormat = mapFormat;
@@ -22,13 +23,13 @@ module Phaser {
//this.scrollFactor = new MicroPoint(1, 1); //this.scrollFactor = new MicroPoint(1, 1);
this.mapData = []; this.mapData = [];
this._tempTileBlock = [];
this._texture = this._game.cache.getImage(key); this._texture = this._game.cache.getImage(key);
this.parseTileOffsets();
} }
private _game: Game; private _game: Game;
private _parent: Tilemap;
private _texture; private _texture;
private _tileOffsets; private _tileOffsets;
private _startX: number = 0; private _startX: number = 0;
@@ -43,8 +44,16 @@ module Phaser {
private _oldCameraY: number = 0; private _oldCameraY: number = 0;
private _columnData; private _columnData;
private _tempTileX: number;
private _tempTileY: number;
private _tempTileW: number;
private _tempTileH: number;
private _tempTileBlock;
private _tempBlockResults;
public name: string; public name: string;
public alpha: number = 1; public alpha: number = 1;
public exists: bool = true;
public visible: bool = true; public visible: bool = true;
//public scrollFactor: MicroPoint; //public scrollFactor: MicroPoint;
public orientation: string; public orientation: string;
@@ -63,6 +72,209 @@ module Phaser {
public widthInPixels: number = 0; public widthInPixels: number = 0;
public heightInPixels: number = 0; public heightInPixels: number = 0;
public tileMargin: number = 0;
public tileSpacing: number = 0;
public putTile(x: number, y: number, index: number) {
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
if (y >= 0 && y < this.mapData.length)
{
if (x >= 0 && x < this.mapData[y].length)
{
this.mapData[y][x] = index;
}
}
}
public swapTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
for (var r = 0; r < this._tempTileBlock.length; r++)
{
// First sweep marking tileA as needing a new index
if (this._tempTileBlock[r].tile.index == tileA)
{
this._tempTileBlock[r].newIndex = true;
}
// In the same pass we can swap tileB to tileA
if (this._tempTileBlock[r].tile.index == tileB)
{
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileA;
}
}
for (var r = 0; r < this._tempTileBlock.length; r++)
{
// And now swap our newIndex tiles for tileB
if (this._tempTileBlock[r].newIndex == true)
{
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
}
}
}
public fillTile(index: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
for (var r = 0; r < this._tempTileBlock.length; r++)
{
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = index;
}
}
public randomiseTiles(tiles: number[], x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
for (var r = 0; r < this._tempTileBlock.length; r++)
{
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles);
}
}
public replaceTile(tileA: number, tileB: number, x?: number = 0, y?: number = 0, width?: number = this.widthInTiles, height?: number = this.heightInTiles) {
this.getTempBlock(x, y, width, height);
for (var r = 0; r < this._tempTileBlock.length; r++)
{
if (this._tempTileBlock[r].tile.index == tileA)
{
this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = tileB;
}
}
}
public getTileBlock(x: number, y: number, width: number, height: number) {
var output = [];
this.getTempBlock(x, y, width, height);
for (var r = 0; r < this._tempTileBlock.length; r++)
{
output.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
return output;
}
public getTileFromWorldXY(x: number, y: number): number {
x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth;
y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight;
return this.getTileIndex(x, y);
}
public getTileOverlaps(object: GameObject) {
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
if (object.bounds.x < 0 || object.bounds.x > this.widthInPixels || object.bounds.y < 0 || object.bounds.bottom > this.heightInPixels)
{
return;
}
// What tiles do we need to check against?
this._tempTileX = this._game.math.snapToFloor(object.bounds.x, this.tileWidth) / this.tileWidth;
this._tempTileY = this._game.math.snapToFloor(object.bounds.y, this.tileHeight) / this.tileHeight;
this._tempTileW = (this._game.math.snapToCeil(object.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth;
this._tempTileH = (this._game.math.snapToCeil(object.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
this._tempBlockResults = [];
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
Collision.TILE_OVERLAP = false;
for (var r = 0; r < this._tempTileBlock.length; r++)
{
if (Collision.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true)
{
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
}
}
return this._tempBlockResults;
}
private getTempBlock(x: number, y: number, width: number, height: number, collisionOnly?: bool = false) {
if (x < 0)
{
x = 0;
}
if (y < 0)
{
y = 0;
}
if (width > this.widthInTiles)
{
width = this.widthInTiles;
}
if (height > this.heightInTiles)
{
height = this.heightInTiles;
}
this._tempTileBlock = [];
for (var ty = y; ty < y + height; ty++)
{
for (var tx = x; tx < x + width; tx++)
{
if (collisionOnly)
{
// We only want to consider the tile for checking if you can actually collide with it
if (this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Collision.NONE)
{
this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
}
}
else
{
if (this.mapData[ty] && this.mapData[ty][tx])
{
this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] });
}
}
}
}
}
public getTileIndex(x: number, y: number): number {
if (y >= 0 && y < this.mapData.length)
{
if (x >= 0 && x < this.mapData[y].length)
{
return this.mapData[y][x];
}
}
return null;
}
public addColumn(column) { public addColumn(column) {
var data = []; var data = [];
@@ -91,7 +303,7 @@ module Phaser {
} }
private parseTileOffsets() { public parseTileOffsets():number {
this._tileOffsets = []; this._tileOffsets = [];
@@ -104,15 +316,17 @@ module Phaser {
i = 1; i = 1;
} }
for (var ty = 0; ty < this._texture.height; ty += this.tileHeight) for (var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing))
{ {
for (var tx = 0; tx < this._texture.width; tx += this.tileWidth) for (var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing))
{ {
this._tileOffsets[i] = { x: tx, y: ty }; this._tileOffsets[i] = { x: tx, y: ty };
i++; i++;
} }
} }
return this._tileOffsets.length;
} }
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
@@ -151,6 +365,16 @@ module Phaser {
this._startY = 0; this._startY = 0;
} }
if (this._maxX > this.widthInTiles)
{
this._maxX = this.widthInTiles;
}
if (this._maxY > this.heightInTiles)
{
this._maxY = this.heightInTiles;
}
if (this._startX + this._maxX > this.widthInTiles) if (this._startX + this._maxX > this.widthInTiles)
{ {
this._startX = this.widthInTiles - this._maxX; this._startX = this.widthInTiles - this._maxX;
+42
View File
@@ -0,0 +1,42 @@
/// <reference path="../Game.d.ts" />
/// <reference path="easing/Back.d.ts" />
/// <reference path="easing/Bounce.d.ts" />
/// <reference path="easing/Circular.d.ts" />
/// <reference path="easing/Cubic.d.ts" />
/// <reference path="easing/Elastic.d.ts" />
/// <reference path="easing/Exponential.d.ts" />
/// <reference path="easing/Linear.d.ts" />
/// <reference path="easing/Quadratic.d.ts" />
/// <reference path="easing/Quartic.d.ts" />
/// <reference path="easing/Quintic.d.ts" />
/// <reference path="easing/Sinusoidal.d.ts" />
module Phaser {
class Tween {
constructor(object, game: Game);
private _game;
private _manager;
private _object;
private _pausedTime;
private _valuesStart;
private _valuesEnd;
private _duration;
private _delayTime;
private _startTime;
private _easingFunction;
private _interpolationFunction;
private _chainedTweens;
public onStart: Signal;
public onUpdate: Signal;
public onComplete: Signal;
public to(properties, duration?: number, ease?: any, autoStart?: bool): Tween;
public start(): Tween;
public stop(): Tween;
public parent : Game;
public delay : number;
public easing : any;
public interpolation : any;
public chain(tween: Tween): Tween;
public debugValue;
public update(time): bool;
}
}
+3
View File
@@ -30,6 +30,7 @@ module Phaser {
this._interpolationFunction = this._game.math.linearInterpolation; this._interpolationFunction = this._game.math.linearInterpolation;
this._easingFunction = Phaser.Easing.Linear.None; this._easingFunction = Phaser.Easing.Linear.None;
this._chainedTweens = [];
this.onStart = new Phaser.Signal(); this.onStart = new Phaser.Signal();
this.onUpdate = new Phaser.Signal(); this.onUpdate = new Phaser.Signal();
this.onComplete = new Phaser.Signal(); this.onComplete = new Phaser.Signal();
@@ -126,6 +127,8 @@ module Phaser {
this._manager.remove(this); this._manager.remove(this);
} }
this.onComplete.dispose();
return this; return this;
} }
+27
View File
@@ -0,0 +1,27 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Animation {
constructor(game: Game, parent: Sprite, frameData: FrameData, name: string, frames, delay: number, looped: bool);
private _game;
private _parent;
private _frames;
private _frameData;
private _frameIndex;
private _timeLastFrame;
private _timeNextFrame;
public name: string;
public currentFrame: Frame;
public isFinished: bool;
public isPlaying: bool;
public looped: bool;
public delay: number;
public frameTotal : number;
public frame : number;
public play(frameRate?: number, loop?: bool): void;
public restart(): void;
public stop(): void;
public update(): bool;
public destroy(): void;
private onComplete();
}
}
+7
View File
@@ -0,0 +1,7 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class AnimationLoader {
static parseSpriteSheet(game: Game, key: string, frameWidth: number, frameHeight: number, frameMax: number): FrameData;
static parseJSONData(game: Game, json): FrameData;
}
}
+23
View File
@@ -0,0 +1,23 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Frame {
constructor(x: number, y: number, width: number, height: number, name: string);
public x: number;
public y: number;
public width: number;
public height: number;
public index: number;
public name: string;
public rotated: bool;
public rotationDirection: string;
public trimmed: bool;
public sourceSizeW: number;
public sourceSizeH: number;
public spriteSourceSizeX: number;
public spriteSourceSizeY: number;
public spriteSourceSizeW: number;
public spriteSourceSizeH: number;
public setRotation(rotated: bool, rotationDirection: string): void;
public setTrim(trimmed: bool, actualWidth, actualHeight, destX, destY, destWidth, destHeight): void;
}
}
+18
View File
@@ -0,0 +1,18 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class FrameData {
constructor();
private _frames;
private _frameNames;
public total : number;
public addFrame(frame: Frame): Frame;
public getFrame(index: number): Frame;
public getFrameByName(name: string): Frame;
public checkFrameName(name: string): bool;
public getFrameRange(start: number, end: number, output?: Frame[]): Frame[];
public getFrameIndexes(output?: number[]): number[];
public getFrameIndexesByName(input: string[]): number[];
public getAllFrames(): Frame[];
public getFrames(range: number[]): Frame[];
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Back {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Bounce {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Circular {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Cubic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Elastic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Exponential {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+6
View File
@@ -0,0 +1,6 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Linear {
static None(k);
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quadratic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quartic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Quintic {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+8
View File
@@ -0,0 +1,8 @@
/// <reference path="../../Game.d.ts" />
module Phaser.Easing {
class Sinusoidal {
static In(k): number;
static Out(k): number;
static InOut(k): number;
}
}
+35
View File
@@ -0,0 +1,35 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Finger {
constructor(game: Game);
private _game;
public identifier: number;
public active: bool;
public point: Point;
public circle: Circle;
public withinGame: bool;
public clientX: number;
public clientY: number;
public pageX: number;
public pageY: number;
public screenX: number;
public screenY: number;
public x: number;
public y: number;
public target;
public isDown: bool;
public isUp: bool;
public timeDown: number;
public duration: number;
public timeUp: number;
public justPressedRate: number;
public justReleasedRate: number;
public start(event): void;
public move(event): void;
public leave(event): void;
public stop(event): void;
public justPressed(duration?: number): bool;
public justReleased(duration?: number): bool;
public toString(): string;
}
}
+24
View File
@@ -0,0 +1,24 @@
/// <reference path="../../Game.d.ts" />
/// <reference path="../../Signal.d.ts" />
module Phaser {
class Input {
constructor(game: Game);
private _game;
public mouse: Mouse;
public keyboard: Keyboard;
public touch: Touch;
public x: number;
public y: number;
public scaleX: number;
public scaleY: number;
public worldX: number;
public worldY: number;
public onDown: Signal;
public onUp: Signal;
public update(): void;
public reset(): void;
public getWorldX(camera?: Camera): number;
public getWorldY(camera?: Camera): number;
public renderDebugInfo(x: number, y: number, color?: string): void;
}
}
+1
View File
@@ -77,6 +77,7 @@ module Phaser {
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.font = '14px Courier';
this._game.stage.context.fillStyle = color; this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y); 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('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
+117
View File
@@ -0,0 +1,117 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Keyboard {
constructor(game: Game);
private _game;
private _keys;
private _capture;
public start(): void;
public addKeyCapture(keycode): void;
public removeKeyCapture(keycode: number): void;
public clearCaptures(): void;
public onKeyDown(event: KeyboardEvent): void;
public onKeyUp(event: KeyboardEvent): void;
public reset(): void;
public justPressed(keycode: number, duration?: number): bool;
public justReleased(keycode: number, duration?: number): bool;
public isDown(keycode: number): bool;
static A: number;
static B: number;
static C: number;
static D: number;
static E: number;
static F: number;
static G: number;
static H: number;
static I: number;
static J: number;
static K: number;
static L: number;
static M: number;
static N: number;
static O: number;
static P: number;
static Q: number;
static R: number;
static S: number;
static T: number;
static U: number;
static V: number;
static W: number;
static X: number;
static Y: number;
static Z: number;
static ZERO: number;
static ONE: number;
static TWO: number;
static THREE: number;
static FOUR: number;
static FIVE: number;
static SIX: number;
static SEVEN: number;
static EIGHT: number;
static NINE: number;
static NUMPAD_0: number;
static NUMPAD_1: number;
static NUMPAD_2: number;
static NUMPAD_3: number;
static NUMPAD_4: number;
static NUMPAD_5: number;
static NUMPAD_6: number;
static NUMPAD_7: number;
static NUMPAD_8: number;
static NUMPAD_9: number;
static NUMPAD_MULTIPLY: number;
static NUMPAD_ADD: number;
static NUMPAD_ENTER: number;
static NUMPAD_SUBTRACT: number;
static NUMPAD_DECIMAL: number;
static NUMPAD_DIVIDE: number;
static F1: number;
static F2: number;
static F3: number;
static F4: number;
static F5: number;
static F6: number;
static F7: number;
static F8: number;
static F9: number;
static F10: number;
static F11: number;
static F12: number;
static F13: number;
static F14: number;
static F15: number;
static COLON: number;
static EQUALS: number;
static UNDERSCORE: number;
static QUESTION_MARK: number;
static TILDE: number;
static OPEN_BRACKET: number;
static BACKWARD_SLASH: number;
static CLOSED_BRACKET: number;
static QUOTES: number;
static BACKSPACE: number;
static TAB: number;
static CLEAR: number;
static ENTER: number;
static SHIFT: number;
static CONTROL: number;
static ALT: number;
static CAPS_LOCK: number;
static ESC: number;
static SPACEBAR: number;
static PAGE_UP: number;
static PAGE_DOWN: number;
static END: number;
static HOME: number;
static LEFT: number;
static UP: number;
static RIGHT: number;
static DOWN: number;
static INSERT: number;
static DELETE: number;
static HELP: number;
static NUM_LOCK: number;
}
}
+3 -3
View File
@@ -32,11 +32,11 @@ module Phaser {
public addKeyCapture(keycode) { public addKeyCapture(keycode) {
if (typeof keycode == 'array') if (typeof keycode === 'object')
{ {
for (var code in keycode) for (var i:number = 0; i < keycode.length; i++)
{ {
this._capture[code] = true; this._capture[keycode[i]] = true;
} }
} }
else else
+24
View File
@@ -0,0 +1,24 @@
/// <reference path="../../Game.d.ts" />
module Phaser {
class Mouse {
constructor(game: Game);
private _game;
private _x;
private _y;
public button: number;
static LEFT_BUTTON: number;
static MIDDLE_BUTTON: number;
static RIGHT_BUTTON: number;
public isDown: bool;
public isUp: bool;
public timeDown: number;
public duration: number;
public timeUp: number;
public start(): void;
public reset(): void;
public onMouseDown(event: MouseEvent): void;
public update(): void;
public onMouseMove(event: MouseEvent): void;
public onMouseUp(event: MouseEvent): void;
}
}
+40
View File
@@ -0,0 +1,40 @@
/// <reference path="../../Game.d.ts" />
/// <reference path="Finger.d.ts" />
module Phaser {
class Touch {
constructor(game: Game);
private _game;
public x: number;
public y: number;
private _fingers;
public finger1: Finger;
public finger2: Finger;
public finger3: Finger;
public finger4: Finger;
public finger5: Finger;
public finger6: Finger;
public finger7: Finger;
public finger8: Finger;
public finger9: Finger;
public finger10: Finger;
public latestFinger: Finger;
public isDown: bool;
public isUp: bool;
public touchDown: Signal;
public touchUp: Signal;
public start(): void;
private consumeTouchMove(event);
private onTouchStart(event);
private onTouchCancel(event);
private onTouchEnter(event);
private onTouchLeave(event);
private onTouchMove(event);
private onTouchEnd(event);
public calculateDistance(finger1: Finger, finger2: Finger): void;
public calculateAngle(finger1: Finger, finger2: Finger): void;
public checkOverlap(finger1: Finger, finger2: Finger): void;
public update(): void;
public stop(): void;
public reset(): void;
}
}

Some files were not shown because too many files have changed in this diff Show More