Skip to content

Commit 3249aa2

Browse files
committed
Merge pull request phaserjs#204 from gltovar/dev
Update typescript definition file
2 parents 83cacb9 + 4d80d6c commit 3249aa2

22 files changed

Lines changed: 40601 additions & 21 deletions

build/phaser.d.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ declare module Phaser {
6262
world: Phaser.World;
6363
particles: Phaser.Particles;
6464
physics: Phaser.Physics.Arcade;
65-
load();
65+
load: Phaser.Loader;
6666
preload();
6767
create();
6868
render();
@@ -87,9 +87,9 @@ declare module Phaser {
8787
onPausedCallback(): void;
8888
onShutDownCallback(): void;
8989
boot(): void;
90-
add(key: string, state: Phaser.State, autoStart: boolean): void;
90+
add(key: string, state: typeof Phaser.State, autoStart?: boolean): void;
9191
remove(key: string): void;
92-
start(key: string, clearWorld: boolean, clearCache: boolean): void;
92+
start(key: string, clearWorld?: boolean, clearCache?: boolean): void;
9393
dummy(): void;
9494
checkState(key: string): boolean;
9595
link(key: string): void;
@@ -120,10 +120,10 @@ declare module Phaser {
120120
memorize: boolean;
121121
active: boolean;
122122
validateListener(listener: Function, fnName: string): void;
123-
has(listener: Function, context?: Object): boolean;
124-
add(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding;
125-
addOnce(listener: Function, listenerContext?: Object, priority?: number): Phaser.SignalBinding;
126-
remove(listener: Function, context?: Object): Function;
123+
has(listener: Function, context?: any): boolean;
124+
add(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
125+
addOnce(listener: Function, listenerContext?: any, priority?: number): Phaser.SignalBinding;
126+
remove(listener: Function, context?: any): Function;
127127
removeAll(): void;
128128
getNumListeners(): number;
129129
halt(): void;
@@ -185,6 +185,7 @@ declare module Phaser {
185185
scale: Phaser.StageScaleMode;
186186
aspectRatio: number;
187187
backgroundColor: string;
188+
disableVisibilityChange: boolean;
188189
boot(): void;
189190
visibilityChange(event: Event): void;
190191
}
@@ -205,7 +206,7 @@ declare module Phaser {
205206
add(child: any): any;
206207
addAt(child: any, index: number): any;
207208
getAt(index: number): any;
208-
create(x: number, y: number, key: string, frame: string, exists: boolean): any;
209+
create(x: number, y: number, key: string, frame: string, exists?: boolean): any;
209210
swap(child1: any, child2: any): boolean;
210211
bringToTop(child: any): any;
211212
getIndex(child: any): number;
@@ -216,7 +217,7 @@ declare module Phaser {
216217
multiplyAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void;
217218
divideAll(key: string, value: number, checkAlive: boolean, checkVisible: boolean, operation: number): void;
218219
callAllExists(callback: Function, callbackContext: Object, existsValue: boolean): void;
219-
callAll(callback: Function, callbackContext: Object): void;
220+
callAll(callback: string, callbackContext?: Object): void;
220221
forEach(callback: Function, callbackContext: Object, checkExists: boolean): void;
221222
forEachAlive(callback: Function, callbackContext: Object): void;
222223
forEachDead(callback: Function, callbackContext: Object): void;
@@ -253,7 +254,7 @@ declare module Phaser {
253254
}
254255

255256
class Game {
256-
constructor(width: number, height: number, renderer: number, parent: string, state: object, transparent: boolean, antialias: boolean);
257+
constructor(width: number, height: number, renderer: number, parent: string, state: Object, transparent: boolean, antialias: boolean);
257258
id: number;
258259
width: number;
259260
height: number;
@@ -343,10 +344,10 @@ declare module Phaser {
343344
touch: Phaser.Touch;
344345
mspointer: Phaser.MSPointer;
345346
interactiveItems: Phaser.LinkedList;
346-
onDown(): void;
347-
onUp(): void;
348-
onTap(): void;
349-
onHold(): void;
347+
onDown: Phaser.Signal;
348+
onUp: Phaser.Signal;
349+
onTap: Phaser.Signal;
350+
onHold: Phaser.Signal;
350351
boot(): void;
351352
update(): void;
352353
reset(hard?: boolean);
@@ -655,14 +656,14 @@ declare module Phaser {
655656
game: Phaser.Game;
656657
world: Phaser.World;
657658
existing(object: any): boolean;
658-
sprite(x: number, y: number, key?: string, frame?: number): Phaser.Sprite;
659+
sprite(x: number, y: number, key?: string, frame?: any): Phaser.Sprite;
659660
child(parent: any, x: number, y: number, key?: string, frame?: number): Phaser.Sprite;
660661
tween(obj: Object): Phaser.Tween;
661-
group(parent: any, name: string): Phaser.Group;
662-
audio(key: string, volume: number, loop: boolean): Phaser.Sound;
662+
group(parent?: any, name?: string): Phaser.Group;
663+
audio(key: string, volume?: number, loop?: boolean): Phaser.Sound;
663664
tileSprite(x: number, y: number, width: number, height: number, key?: string, frame?: number): Phaser.TileSprite;
664-
text(x: number, y: number, text: string, style: string): Phaser.Text;
665-
button(x: number, y: number, key: string, callback: Function, callbackContext: Object, overFrame?: number, outFrame?: number, downFrame?: number): Phaser.Button;
665+
text(x: number, y: number, text: string, style: any): Phaser.Text;
666+
button(x: number, y: number, key: string, callback: Function, callbackContext: Object, overFrame?: any, outFrame?: any, downFrame?: any): Phaser.Button;
666667
graphics(x: number, y: number): Phaser.Graphics;
667668
emitter(x: number, y: number, maxParticles: number): Phaser.Particles.Arcade.Emitter;
668669
bitmapText(x: number, y: number, text: string, style: string): Phaser.BitmapText;
@@ -709,6 +710,7 @@ declare module Phaser {
709710
frameName: string;
710711
inCamera: boolean;
711712
crop: boolean;
713+
cropEnabled: boolean;
712714
inputEnabled: boolean;
713715
preUpdate(): void;
714716
postUpdate(): void;
@@ -736,12 +738,14 @@ declare module Phaser {
736738
exists: boolean;
737739
alive: boolean;
738740
group: Phaser.Group;
741+
content: string;
739742
name: string;
740743
game: Phaser.Game;
741744
type: number;
742745
text: string;
743746
angle: number;
744747
style: string;
748+
visible: boolean;
745749
position: Phaser.Point;
746750
anchor: Phaser.Point;
747751
scale: Phaser.Point;
@@ -804,6 +808,8 @@ declare module Phaser {
804808
pageAlignVeritcally: boolean;
805809
minWidth: number;
806810
maxWidth: number;
811+
minHeight: number;
812+
maxHeight: number;
807813
width: number;
808814
height: number;
809815
maxIterations: number;
@@ -1380,7 +1386,7 @@ declare module Phaser {
13801386
onFileError: Phaser.Signal;
13811387
onLoadStart: Phaser.Signal;
13821388
onLoadComplete: Phaser.Signal;
1383-
setPreloadSprite(sprite: Phaser.Sprite, direction: number): void;
1389+
setPreloadSprite(sprite: Phaser.Sprite, direction?: number): void;
13841390
checkKeyExists(key: string): boolean;
13851391
reset(): void;
13861392
addToFileList(type: string, key: string, url: string, properties: Array): void;
@@ -1451,7 +1457,7 @@ declare module Phaser {
14511457
addMarker(name: string, start: number, stop: number, volume?: number, loop?: boolean): void;
14521458
removeMarker(name: string): void;
14531459
update(): void;
1454-
play(marker: string, position: number, volume?: number, loop?: boolean): Phaser.Sound;
1460+
play(marker?: string, position?: number, volume?: number, loop?: boolean): Phaser.Sound;
14551461
restart(marker: string, position: number, volume?: number, loop?: boolean): void;
14561462
pause(): void;
14571463
resume(): void;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var __extends = this.__extends || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
__.prototype = b.prototype;
5+
d.prototype = new __();
6+
};
7+
/// <reference path="phaser.d.ts" />
8+
var BasicGame;
9+
(function (BasicGame) {
10+
var Boot = (function (_super) {
11+
__extends(Boot, _super);
12+
function Boot() {
13+
_super.apply(this, arguments);
14+
}
15+
Boot.prototype.preload = function () {
16+
this.load.image("preloaderBackground", "assets/preloader_background.gif");
17+
this.load.image("preloaderBar", "assets/preloadr_bar.png");
18+
};
19+
Boot.prototype.create = function () {
20+
this.game.input.maxPointers = 1;
21+
this.game.stage.disableVisibilityChange = true;
22+
23+
if (this.game.device.desktop) {
24+
this.game.stage.scale.pageAlignHorizontally = true;
25+
} else {
26+
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
27+
this.game.stage.scale.minWidth = 480;
28+
this.game.stage.scale.minHeight = 260;
29+
this.game.stage.scale.maxWidth = 1024;
30+
this.game.stage.scale.maxHeight = 768;
31+
this.game.stage.scale.forceLandscape = true;
32+
this.game.stage.scale.pageAlignHorizontally = true;
33+
this.game.stage.scale.setScreenSize(true);
34+
}
35+
36+
this.game.state.start("Preloader");
37+
};
38+
return Boot;
39+
})(Phaser.State);
40+
BasicGame.Boot = Boot;
41+
})(BasicGame || (BasicGame = {}));
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference path="phaser.d.ts" />
2+
module BasicGame
3+
{
4+
export class Boot extends Phaser.State{
5+
preload() {
6+
this.load.image("preloaderBackground","assets/preloader_background.gif");
7+
this.load.image("preloaderBar","assets/preloadr_bar.png");
8+
}
9+
create() {
10+
this.game.input.maxPointers = 1;
11+
this.game.stage.disableVisibilityChange = true;
12+
13+
if( this.game.device.desktop )
14+
{
15+
this.game.stage.scale.pageAlignHorizontally = true;
16+
}
17+
else
18+
{
19+
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
20+
this.game.stage.scale.minWidth = 480;
21+
this.game.stage.scale.minHeight = 260;
22+
this.game.stage.scale.maxWidth = 1024;
23+
this.game.stage.scale.maxHeight = 768;
24+
this.game.stage.scale.forceLandscape = true;
25+
this.game.stage.scale.pageAlignHorizontally = true;
26+
this.game.stage.scale.setScreenSize( true );
27+
}
28+
29+
this.game.state.start("Preloader");
30+
}
31+
}
32+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/// <reference path="phaser.d.ts" />
2+
var __extends = this.__extends || function (d, b) {
3+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4+
function __() { this.constructor = d; }
5+
__.prototype = b.prototype;
6+
d.prototype = new __();
7+
};
8+
var BasicGame;
9+
(function (BasicGame) {
10+
var GameState = (function (_super) {
11+
__extends(GameState, _super);
12+
function GameState() {
13+
_super.apply(this, arguments);
14+
}
15+
GameState.prototype.create = function () {
16+
this.game.world.height = 620;
17+
18+
this._ballOnPaddle = true;
19+
this._score = 0;
20+
this._lives = 3;
21+
22+
this._s = this.game.add.tileSprite(0, 0, 800, 600, "starfield");
23+
24+
var brick;
25+
this._bricks = this.game.add.group();
26+
27+
for (var y = 0; y < 4; y++) {
28+
for (var x = 0; x < 15; x++) {
29+
brick = this._bricks.create(120 + (x * 36), 100 + (y * 52), "breakout", "brick_" + (y + 1) + "_1.png");
30+
brick.body.bounce.setTo(1, 1);
31+
brick.body.immovable = true;
32+
}
33+
}
34+
35+
this._paddle = this.game.add.sprite(this.game.world.centerX, 500, "breakout", "paddle_big.png");
36+
this._paddle.anchor.setTo(0.5, 0.5);
37+
this._paddle.body.collideWorldBounds = true;
38+
this._paddle.body.bounce.setTo(1, 1);
39+
this._paddle.body.immovable = true;
40+
41+
this._ball = this.game.add.sprite(this.game.world.centerX, this._paddle.y - 16, "breakout", 'ball_1.png');
42+
this._ball.anchor.setTo(0.5, 0.5);
43+
this._ball.body.collideWorldBounds = true;
44+
45+
this._ball.body.bounce.setTo(1, 1);
46+
this._ball.animations.add("spin", ["ball_1.png", "ball_2.png", "ball_3.png", "ball_4.png", "ball_5.png"], 50, true, false);
47+
48+
this._scoreText = this.game.add.text(32, 550, "score: 0", { font: "20px Arial", fill: "#ffffff", align: "left" });
49+
this._livesText = this.game.add.text(680, 550, "lives: 3", { font: "20px Arial", fill: "#ffffff", align: "left" });
50+
this._introText = this.game.add.text(this.game.world.centerX, 400, "- click to start -", { font: "40px Arial", fill: "#ffffff", align: "center" });
51+
this._introText.anchor.setTo(0.5, 0.5);
52+
53+
this.game.input.onDown.add(this.releaseBall, this);
54+
55+
this._ballOnPaddle = true;
56+
};
57+
58+
GameState.prototype.update = function () {
59+
this._paddle.x = this.game.input.x;
60+
61+
if (this._paddle.x < 24) {
62+
this._paddle.x = 24;
63+
} else if (this._paddle.x > this.game.width - 24) {
64+
this._paddle.x = this.game.width - 24;
65+
}
66+
67+
if (this._ballOnPaddle) {
68+
this._ball.x = this._paddle.x;
69+
} else {
70+
this.game.physics.collide(this._ball, this._paddle, this.ballHitPaddle, null, this);
71+
this.game.physics.collide(this._ball, this._bricks, this.ballHitBrick, null, this);
72+
}
73+
74+
if (this._ball.y > 600 && this._ballOnPaddle == false) {
75+
this.ballLost();
76+
}
77+
};
78+
79+
GameState.prototype.quitGame = function (p_pointer) {
80+
this.game.state.start("MainMenu");
81+
};
82+
83+
GameState.prototype.releaseBall = function () {
84+
if (this._ballOnPaddle) {
85+
this._ballOnPaddle = false;
86+
this._ball.body.velocity.y = -300;
87+
this._ball.body.velocity.x = -75;
88+
this._ball.animations.play("spin");
89+
this._introText.visible = false;
90+
}
91+
};
92+
93+
GameState.prototype.ballLost = function () {
94+
this._lives--;
95+
96+
if (this._lives == 0) {
97+
this.gameOver();
98+
} else {
99+
this._livesText.content = "lives: " + this._lives;
100+
this._ballOnPaddle = true;
101+
this._ball.body.velocity.setTo(0, 0);
102+
this._ball.x = this._paddle.x + 16;
103+
this._ball.y = this._paddle.y - 16;
104+
this._ball.animations.stop();
105+
}
106+
};
107+
108+
GameState.prototype.gameOver = function () {
109+
this._ball.body.velocity.setTo(0, 0);
110+
111+
this.quitGame();
112+
};
113+
114+
GameState.prototype.ballHitBrick = function (p_ball, p_brick) {
115+
p_brick.kill();
116+
117+
this._score += 10;
118+
this._scoreText.content = "score: " + this._score;
119+
120+
if (this._bricks.countLiving() == 0) {
121+
this._score += 1000;
122+
this._scoreText.content = "score: " + this._score;
123+
this._introText.content = "- Next Level -";
124+
125+
this._ballOnPaddle = true;
126+
this._ball.body.velocity.setTo(0, 0);
127+
this._ball.x = this._paddle.x + 16;
128+
this._ball.y = this._paddle.y - 16;
129+
this._ball.animations.stop();
130+
131+
this._bricks.callAll('revive');
132+
}
133+
};
134+
135+
GameState.prototype.ballHitPaddle = function (p_ball, p_paddle) {
136+
var l_diff = 0;
137+
138+
if (p_ball.x < p_paddle.x) {
139+
l_diff = p_paddle.x - p_ball.x;
140+
p_ball.body.velocity.x = (-10 * l_diff);
141+
} else if (p_ball.x > p_paddle.x) {
142+
l_diff = p_ball.x - p_paddle.x;
143+
p_ball.body.velocity.x = (10 * l_diff);
144+
} else {
145+
p_ball.body.velocity.x = 2 + Math.random() * 8;
146+
}
147+
};
148+
return GameState;
149+
})(Phaser.State);
150+
BasicGame.GameState = GameState;
151+
})(BasicGame || (BasicGame = {}));

0 commit comments

Comments
 (0)