Skip to content

Commit 2f03f5f

Browse files
committed
Updated Loader component and fixed a few Pointer issues.
1 parent d42f396 commit 2f03f5f

118 files changed

Lines changed: 935 additions & 603 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Phaser/Game.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module Phaser {
101101
private _step: number = 0;
102102

103103
/**
104-
* Whether loader complete loading or not.
104+
* Whether load complete loading or not.
105105
* @type {boolean}
106106
*/
107107
private _loadComplete: bool = false;
@@ -187,7 +187,7 @@ module Phaser {
187187
* Reference to the assets loader.
188188
* @type {Loader}
189189
*/
190-
public loader: Loader;
190+
public load: Loader;
191191

192192
/**
193193
* Reference to the math helper.
@@ -288,7 +288,7 @@ module Phaser {
288288
this.add = new GameObjectFactory(this);
289289
this.sound = new SoundManager(this);
290290
this.cache = new Cache(this);
291-
this.loader = new Loader(this, this.loadComplete);
291+
this.load = new Loader(this, this.loadComplete);
292292
this.time = new Time(this);
293293
this.tweens = new TweenManager(this);
294294
this.input = new Input(this);
@@ -353,7 +353,7 @@ module Phaser {
353353
}
354354

355355
/**
356-
* Called when the loader has finished after init was run.
356+
* Called when the load has finished after init was run.
357357
*/
358358
private loadComplete() {
359359

@@ -432,12 +432,12 @@ module Phaser {
432432

433433
if (this.onInitCallback !== null)
434434
{
435-
this.loader.reset();
435+
this.load.reset();
436436

437437
this.onInitCallback.call(this.callbackContext);
438438

439-
// Is the loader empty?
440-
if (this.loader.queueSize == 0)
439+
// Is the load empty?
440+
if (this.load.queueSize == 0)
441441
{
442442
if (this.onCreateCallback !== null)
443443
{
@@ -584,7 +584,7 @@ module Phaser {
584584
this.onDestroyCallback = null;
585585
this.cache = null;
586586
this.input = null;
587-
this.loader = null;
587+
this.load = null;
588588
this.sound = null;
589589
this.stage = null;
590590
this.time = null;

Phaser/Stage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ module Phaser {
255255

256256
public pauseGame() {
257257

258-
if (this.disablePauseScreen == false)
258+
if (this.disablePauseScreen == false && this.pauseScreen)
259259
{
260260
this.pauseScreen.onPaused();
261261
}
@@ -267,7 +267,7 @@ module Phaser {
267267

268268
public resumeGame() {
269269

270-
if (this.disablePauseScreen == false)
270+
if (this.disablePauseScreen == false && this.pauseScreen)
271271
{
272272
this.pauseScreen.onResume();
273273
}

Phaser/State.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Phaser {
2222
this.camera = game.camera;
2323
this.cache = game.cache;
2424
this.input = game.input;
25-
this.loader = game.loader;
25+
this.load = game.load;
2626
this.math = game.math;
2727
this.motion = game.motion;
2828
this.sound = game.sound;
@@ -66,7 +66,7 @@ module Phaser {
6666
* Reference to the assets loader.
6767
* @type {Loader}
6868
*/
69-
public loader: Loader;
69+
public load: Loader;
7070

7171
/**
7272
* Reference to the math helper.

Phaser/components/sprite/Input.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ module Phaser.Components {
287287
}
288288
else
289289
{
290-
this._pointOutHandler(pointer);
290+
this._pointerOutHandler(pointer);
291291
return false;
292292
}
293293
}
@@ -316,7 +316,7 @@ module Phaser.Components {
316316

317317
}
318318

319-
public _pointOutHandler(pointer: Pointer) {
319+
public _pointerOutHandler(pointer: Pointer) {
320320

321321
this._pointerData[pointer.id].isOver = false;
322322
this._pointerData[pointer.id].isOut = true;
@@ -335,11 +335,8 @@ module Phaser.Components {
335335

336336
public _touchedHandler(pointer: Pointer): bool {
337337

338-
console.log('touched handler', this._pointerData[pointer.id]);
339-
340338
if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true)
341339
{
342-
//console.log('touchDown on', this._sprite.texture.cacheKey,this._sprite.frameName, this._sprite.frameBounds.width,this._sprite.frameBounds.height);
343340
this._pointerData[pointer.id].isDown = true;
344341
this._pointerData[pointer.id].isUp = false;
345342
this._pointerData[pointer.id].timeDown = this.game.time.now;
@@ -362,8 +359,6 @@ module Phaser.Components {
362359

363360
public _releasedHandler(pointer: Pointer) {
364361

365-
console.log('release handler');
366-
367362
// If was previously touched by this Pointer, check if still is
368363
if (this._pointerData[pointer.id].isDown && pointer.isUp)
369364
{
@@ -562,7 +557,7 @@ module Phaser.Components {
562557
this._dragPoint.setTo(this._sprite.x - pointer.x, this._sprite.y - pointer.y);
563558
}
564559

565-
//pointer.draggedObject = this._sprite;
560+
this.updateDrag(pointer);
566561

567562
}
568563

@@ -678,13 +673,13 @@ module Phaser.Components {
678673
*/
679674
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
680675

681-
this._sprite.texture.context.font = '16px Courier';
676+
this._sprite.texture.context.font = '14px Courier';
682677
this._sprite.texture.context.fillStyle = color;
683678
this._sprite.texture.context.fillText('Sprite Input: (' + this._sprite.frameBounds.width + ' x ' + this._sprite.frameBounds.height + ')', x, y);
684-
this._sprite.texture.context.fillText('x: ' + this.pointerX(1).toFixed(1) + ' y: ' + this.pointerY(1).toFixed(1), x, y + 14);
685-
this._sprite.texture.context.fillText('over: ' + this.pointerOver(1) + ' duration: ' + this.overDuration(1).toFixed(0), x, y + 28);
686-
this._sprite.texture.context.fillText('down: ' + this.pointerDown(1) + ' duration: ' + this.downDuration(1).toFixed(0), x, y + 42);
687-
this._sprite.texture.context.fillText('just over: ' + this.justOver(1) + ' just out: ' + this.justOut(1), x, y + 56);
679+
this._sprite.texture.context.fillText('x: ' + this.pointerX().toFixed(1) + ' y: ' + this.pointerY().toFixed(1), x, y + 14);
680+
this._sprite.texture.context.fillText('over: ' + this.pointerOver() + ' duration: ' + this.overDuration().toFixed(0), x, y + 28);
681+
this._sprite.texture.context.fillText('down: ' + this.pointerDown() + ' duration: ' + this.downDuration().toFixed(0), x, y + 42);
682+
this._sprite.texture.context.fillText('just over: ' + this.justOver() + ' just out: ' + this.justOut(), x, y + 56);
688683

689684
}
690685

Phaser/input/Input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ module Phaser {
904904
*/
905905
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
906906

907-
this._game.stage.context.font = '24px Courier';
907+
this._game.stage.context.font = '14px Courier';
908908
this._game.stage.context.fillStyle = color;
909909
this._game.stage.context.fillText('Input', x, y);
910910
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);

Phaser/input/Pointer.ts

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -348,29 +348,6 @@ module Phaser {
348348
this.game.input.currentPointers++;
349349
}
350350

351-
// Build our temporary click stack
352-
/*
353-
var _highestPriority = 0;
354-
var _highestRenderID = 0;
355-
var _highestRenderObject: number = -1;
356-
357-
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
358-
{
359-
if (this.game.input.inputObjects[i].input.checkPointerOver(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
360-
{
361-
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
362-
_highestRenderObject = i;
363-
}
364-
}
365-
366-
if (_highestRenderObject !== -1 && this._stateReset == false)
367-
{
368-
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
369-
this.targetObject.input._touchedHandler(this);
370-
//_highestRenderObject.input._touchedHandler(this);
371-
}
372-
*/
373-
374351
if (this.targetObject !== null)
375352
{
376353
this.targetObject.input._touchedHandler(this);
@@ -406,50 +383,6 @@ module Phaser {
406383
}
407384
}
408385

409-
// Iterate through the tracked objects
410-
411-
// Build our temporary click stack
412-
/*
413-
var _highestPriority = 0;
414-
var _highestRenderID = 0;
415-
var _highestRenderObject = null;
416-
417-
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
418-
{
419-
if (this.game.input.inputObjects[i].input.enabled)
420-
{
421-
//if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].input.priorityID > _highestPriority)
422-
if (this.game.input.inputObjects[i].input.update(this) && this.game.input.inputObjects[i].renderOrderID > _highestRenderID)
423-
{
424-
_highestRenderID = this.game.input.inputObjects[i].renderOrderID;
425-
_highestRenderObject = this.game.input.inputObjects[i];
426-
}
427-
}
428-
}
429-
430-
if (_highestRenderObject !== null)
431-
{
432-
_highestRenderObject.input._pointerOverHandler(this);
433-
434-
if (this.isDown && this._stateReset == false)
435-
{
436-
_highestRenderObject.input._touchedHandler(this);
437-
}
438-
439-
// Now update all objects with the highest priority ID (can be more than 1)
440-
//for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
441-
//{
442-
// if (this.game.input.inputObjects[i].input.priorityID == _highestPriority)
443-
// {
444-
// if (this.game.input.inputObjects[i].input._touchedHandler(this) == false)
445-
// {
446-
// return;
447-
// }
448-
// }
449-
//}
450-
}
451-
*/
452-
453386
}
454387

455388
}
@@ -499,7 +432,7 @@ module Phaser {
499432
else
500433
{
501434
// Build our temporary click stack
502-
var _highestRenderID = 0;
435+
var _highestRenderID = -1;
503436
var _highestRenderObject: number = -1;
504437

505438
for (var i = 0; i < this.game.input.totalTrackedObjects; i++)
@@ -517,6 +450,7 @@ module Phaser {
517450
this.targetObject = this.game.input.inputObjects[_highestRenderObject];
518451
this.targetObject.input._pointerOverHandler(this);
519452
}
453+
520454
}
521455

522456
return this;

Phaser/loader/Loader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module Phaser {
107107
* @param key {string} Unique asset key of this image file.
108108
* @param url {string} URL of image file.
109109
*/
110-
public addImageFile(key: string, url: string) {
110+
public image(key: string, url: string) {
111111

112112
if (this.checkKeyExists(key) === false)
113113
{
@@ -126,7 +126,7 @@ module Phaser {
126126
* @param frameHeight {number} Height of each single frame.
127127
* @param frameMax {number} How many frames in this sprite sheet.
128128
*/
129-
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
129+
public spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
130130

131131
if (this.checkKeyExists(key) === false)
132132
{
@@ -145,7 +145,7 @@ module Phaser {
145145
* @param [atlasData] {object} A JSON or XML data object.
146146
* @param [format] {number} A value describing the format of the data.
147147
*/
148-
public addTextureAtlas(key: string, textureURL: string, atlasURL?: string = null, atlasData? = null, format?:number = Loader.TEXTURE_ATLAS_JSON_ARRAY) {
148+
public atlas(key: string, textureURL: string, atlasURL?: string = null, atlasData? = null, format?:number = Loader.TEXTURE_ATLAS_JSON_ARRAY) {
149149

150150
if (this.checkKeyExists(key) === false)
151151
{
@@ -222,7 +222,7 @@ module Phaser {
222222
* @param key {string} Unique asset key of the audio file.
223223
* @param url {string} URL of audio file.
224224
*/
225-
public addAudioFile(key: string, url: string) {
225+
public audio(key: string, url: string) {
226226

227227
if (this.checkKeyExists(key) === false)
228228
{
@@ -238,7 +238,7 @@ module Phaser {
238238
* @param key {string} Unique asset key of the text file.
239239
* @param url {string} URL of text file.
240240
*/
241-
public addTextFile(key: string, url: string) {
241+
public text(key: string, url: string) {
242242

243243
if (this.checkKeyExists(key) === false)
244244
{
@@ -273,7 +273,7 @@ module Phaser {
273273
* @param onFileLoadCallback {function} Called when each file loaded successfully.
274274
* @param onCompleteCallback {function} Called when all assets completely loaded.
275275
*/
276-
public load(onFileLoadCallback = null, onCompleteCallback = null) {
276+
public start(onFileLoadCallback = null, onCompleteCallback = null) {
277277

278278
this.progress = 0;
279279
this.hasLoaded = false;

Phaser/sound/SoundManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ module Phaser {
1919

2020
this._game = game;
2121

22+
if (window['PhaserGlobal'] && window['PhaserGlobal'].disableAudio == true)
23+
{
24+
return;
25+
}
26+
2227
if (game.device.webaudio == true)
2328
{
2429
if (!!window['AudioContext'])

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ TODO:
4545
* Bug in AnimationManager set frame/frameName - the width/height are trimmed and wrong
4646
* RenderOrderID won't work across cameras - but then neither do Pointers yet anyway
4747
* Swap to using time based motion (like the tweens) rather than delta timer - it just doesn't work well on slow phones
48-
48+
* Bug in World drag
4949

5050
V1.0.0
5151

@@ -90,6 +90,7 @@ V1.0.0
9090
* Added support for minWidth and minHeight to game scale size, so it can never go below those values when scaling.
9191
* Vastly improved orientation detection and response speed.
9292
* Added custom callback support for all Touch and Mouse Events so you can easily hook events to custom APIs.
93+
* Updated Game.loader and its methods. You now load images by: game.load.image() and also: game.load.atlas, game.load.audio, game.load.spritesheet, game.load.text. And you start it with game.load.start().
9394

9495

9596

Tests/Tests.csproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@
6969
<TypeScriptCompile Include="particles\graphic emitter.ts" />
7070
<TypeScriptCompile Include="input\over sprite 1.ts" />
7171
<TypeScriptCompile Include="groups\create group 1.ts" />
72+
<TypeScriptCompile Include="demoscene\ballmover.ts" />
73+
<Content Include="demoscene\ballmover.js">
74+
<DependentUpon>ballmover.ts</DependentUpon>
75+
</Content>
76+
<TypeScriptCompile Include="demoscene\scroller1.ts" />
77+
<TypeScriptCompile Include="demoscene\colorwhirl.ts" />
78+
<Content Include="demoscene\colorwhirl.js">
79+
<DependentUpon>colorwhirl.ts</DependentUpon>
80+
</Content>
81+
<TypeScriptCompile Include="demoscene\fujiboink.ts" />
82+
<TypeScriptCompile Include="demoscene\fruitfall.ts" />
83+
<Content Include="demoscene\fruitfall.js">
84+
<DependentUpon>fruitfall.ts</DependentUpon>
85+
</Content>
86+
<Content Include="demoscene\fujiboink.js">
87+
<DependentUpon>fujiboink.ts</DependentUpon>
88+
</Content>
89+
<TypeScriptCompile Include="demoscene\metalslug.ts" />
90+
<Content Include="demoscene\metalslug.js">
91+
<DependentUpon>metalslug.ts</DependentUpon>
92+
</Content>
93+
<Content Include="demoscene\scroller1.js">
94+
<DependentUpon>scroller1.ts</DependentUpon>
95+
</Content>
96+
<TypeScriptCompile Include="demoscene\starray.ts" />
97+
<Content Include="demoscene\starray.js">
98+
<DependentUpon>starray.ts</DependentUpon>
99+
</Content>
72100
<Content Include="groups\create group 1.js">
73101
<DependentUpon>create group 1.ts</DependentUpon>
74102
</Content>

0 commit comments

Comments
 (0)