Skip to content

Commit 9eab94d

Browse files
#127: Scene editor: fixes game loop bug.
1 parent b32f51d commit 9eab94d

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/Create.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace PhaserEditor2D {
177177
}
178178

179179
function PixelPerfectHandler(hitArea, x, y, sprite: Phaser.GameObjects.Sprite) {
180+
180181
if (sprite.flipX) {
181182
x = 2 * sprite.displayOriginX - x;
182183
}

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/Editor.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace PhaserEditor2D {
3535
}
3636

3737
stop() {
38+
consoleLog("loop.stop");
3839
this._game.loop.stop();
3940
}
4041

@@ -339,6 +340,8 @@ namespace PhaserEditor2D {
339340
});
340341

341342
this.updateBodyColor();
343+
344+
this.stop();
342345
}
343346

344347
snapValueX(x: number) {
@@ -421,6 +424,13 @@ namespace PhaserEditor2D {
421424

422425
if (loadMsg.pack) {
423426
let scene = this.getObjectScene();
427+
428+
this._loaderIntervalID = setInterval(function () {
429+
self.repaint();
430+
}, 20);
431+
432+
setTimeout(() => self.stop(), 1500);
433+
424434
scene.load.once(Phaser.Loader.Events.COMPLETE,
425435

426436
(function (index2, list2) {
@@ -443,9 +453,6 @@ namespace PhaserEditor2D {
443453
scene.load.crossOrigin = "anonymous";
444454
scene.load.addPack(loadMsg.pack);
445455
scene.load.start();
446-
this._loaderIntervalID = setInterval(function () {
447-
self.repaint();
448-
}, 20);
449456
} else {
450457
this.processMessageList(index + 1, list);
451458
}

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/ObjectScene.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ namespace PhaserEditor2D {
2020
consoleLog("preload()");
2121
this.load.setBaseURL(this._initData.projectUrl);
2222
this.load.pack("pack", this._initData.pack);
23+
setTimeout(() => Editor.getInstance().stop(), 500);
2324
}
2425

2526
create() {
26-
Editor.getInstance().stop();
27+
const editor = Editor.getInstance();
2728

2829
this._dragCameraManager = new DragCameraManager(this);
2930

@@ -37,9 +38,7 @@ namespace PhaserEditor2D {
3738

3839
this.initSelectionScene();
3940

40-
const editor = Editor.getInstance();
41-
42-
editor.getCreate().createWorld(this, this._initData.displayList);
41+
editor.getCreate().createWorld(this, this._initData.displayList);
4342

4443
editor.sceneCreated();
4544

@@ -82,7 +81,7 @@ namespace PhaserEditor2D {
8281
return new Phaser.Math.Vector2(sceneX, sceneY);
8382
}
8483

85-
84+
8685
private initSelectionScene() {
8786
this.scene.launch("ToolScene");
8887
this._toolScene = <ToolScene>this.scene.get("ToolScene");
@@ -100,7 +99,7 @@ namespace PhaserEditor2D {
10099

101100
getToolScene() {
102101
return this._toolScene;
103-
}
102+
}
104103

105104
onMouseWheel(e: WheelEvent) {
106105
var cam = this.cameras.main;
@@ -130,7 +129,7 @@ namespace PhaserEditor2D {
130129
}
131130

132131
performResize() {
133-
this.cameras.main.setSize(window.innerWidth, window.innerHeight);
132+
this.cameras.main.setSize(window.innerWidth, window.innerHeight);
134133
}
135134
}
136135

@@ -141,8 +140,8 @@ namespace PhaserEditor2D {
141140
const editor = Editor.getInstance();
142141

143142
const scene = editor.getObjectScene();
144-
const pointer = scene.input.activePointer;
145-
143+
const pointer = scene.input.activePointer;
144+
146145
if (!isLeftButton(e)) {
147146
return;
148147
}

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/ToolScene.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
namespace PhaserEditor2D {
22

3+
var TICK_COUNT = 0;
4+
35
export class ToolScene extends Phaser.Scene {
46

57

68
private _selectedObjects: Phaser.GameObjects.GameObject[];
79
private _selectionGraphics: Phaser.GameObjects.Graphics;
810
private _gridGraphics: Phaser.GameObjects.Graphics;
11+
private _tick: Phaser.GameObjects.Text;
912
private _tools: InteractiveTool[];
1013

1114

@@ -36,6 +39,9 @@ namespace PhaserEditor2D {
3639
});
3740

3841
this._selectionGraphics.depth = -1;
42+
43+
this._tick = this.add.text(10, 10, "");
44+
this._tick.depth = -1;
3945
}
4046

4147
initCamera() {
@@ -113,6 +119,7 @@ namespace PhaserEditor2D {
113119

114120
let label: Phaser.GameObjects.Text = null;
115121
let labelHeight = 0;
122+
this._axisLabels = [];
116123

117124
for (let x = sx; ; x += dx) {
118125
const x2 = (x - cam.scrollX) * cam.zoom;
@@ -223,6 +230,9 @@ namespace PhaserEditor2D {
223230
this.renderAxis();
224231
this.renderSelection();
225232
this.updateTools();
233+
234+
this._tick.text = TICK_COUNT + "";
235+
TICK_COUNT += 1;
226236
}
227237

228238
setTools(tools: InteractiveTool[]) {

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/Editor.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var PhaserEditor2D;
1616
this._game.loop.step(Date.now());
1717
};
1818
Editor.prototype.stop = function () {
19+
consoleLog("loop.stop");
1920
this._game.loop.stop();
2021
};
2122
Editor.prototype.getCreate = function () {
@@ -255,6 +256,7 @@ var PhaserEditor2D;
255256
self.repaint();
256257
});
257258
this.updateBodyColor();
259+
this.stop();
258260
};
259261
Editor.prototype.snapValueX = function (x) {
260262
var props = this.sceneProperties;
@@ -320,6 +322,10 @@ var PhaserEditor2D;
320322
var self = this;
321323
if (loadMsg.pack) {
322324
var scene = this.getObjectScene();
325+
this._loaderIntervalID = setInterval(function () {
326+
self.repaint();
327+
}, 20);
328+
setTimeout(function () { return self.stop(); }, 1500);
323329
scene.load.once(Phaser.Loader.Events.COMPLETE, (function (index2, list2) {
324330
return function () {
325331
consoleLog("Loader complete.");
@@ -334,9 +340,6 @@ var PhaserEditor2D;
334340
scene.load.crossOrigin = "anonymous";
335341
scene.load.addPack(loadMsg.pack);
336342
scene.load.start();
337-
this._loaderIntervalID = setInterval(function () {
338-
self.repaint();
339-
}, 20);
340343
}
341344
else {
342345
this.processMessageList(index + 1, list);

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/ObjectScene.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ var PhaserEditor2D;
2222
consoleLog("preload()");
2323
this.load.setBaseURL(this._initData.projectUrl);
2424
this.load.pack("pack", this._initData.pack);
25+
setTimeout(function () { return PhaserEditor2D.Editor.getInstance().stop(); }, 500);
2526
};
2627
ObjectScene.prototype.create = function () {
27-
PhaserEditor2D.Editor.getInstance().stop();
28+
var editor = PhaserEditor2D.Editor.getInstance();
2829
this._dragCameraManager = new DragCameraManager(this);
2930
this._dragObjectsManager = new DragObjectsManager();
3031
this._pickManager = new PickObjectManager();
3132
new DropManager();
3233
this.initCamera();
3334
this.initSelectionScene();
34-
var editor = PhaserEditor2D.Editor.getInstance();
3535
editor.getCreate().createWorld(this, this._initData.displayList);
3636
editor.sceneCreated();
3737
editor.repaint();

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/ToolScene.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var __extends = (this && this.__extends) || (function () {
1010
})();
1111
var PhaserEditor2D;
1212
(function (PhaserEditor2D) {
13+
var TICK_COUNT = 0;
1314
var ToolScene = (function (_super) {
1415
__extends(ToolScene, _super);
1516
function ToolScene() {
@@ -42,6 +43,8 @@ var PhaserEditor2D;
4243
}
4344
});
4445
this._selectionGraphics.depth = -1;
46+
this._tick = this.add.text(10, 10, "");
47+
this._tick.depth = -1;
4548
};
4649
ToolScene.prototype.initCamera = function () {
4750
this.cameras.main.setRoundPixels(true);
@@ -93,6 +96,7 @@ var PhaserEditor2D;
9396
}
9497
var label = null;
9598
var labelHeight = 0;
99+
this._axisLabels = [];
96100
for (var x = sx;; x += dx) {
97101
var x2 = (x - cam.scrollX) * cam.zoom;
98102
if (x2 > w) {
@@ -168,6 +172,8 @@ var PhaserEditor2D;
168172
this.renderAxis();
169173
this.renderSelection();
170174
this.updateTools();
175+
this._tick.text = TICK_COUNT + "";
176+
TICK_COUNT += 1;
171177
};
172178
ToolScene.prototype.setTools = function (tools) {
173179
for (var _i = 0, _a = this._tools; _i < _a.length; _i++) {

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/out/workaround.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ window.addEventListener("onerror", function (e) {
22
alert("WebView ERROR: " + e);
33
});
44
window.AudioContext = function () { };
5-
var CONSOLE_LOG = false;
5+
var CONSOLE_LOG = true;
66
function consoleLog(msg) {
77
if (CONSOLE_LOG) {
88
console.log(msg);

source/v2/phasereditor/phasereditor.scene.ui.editor.html/html/workaround.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ window.addEventListener("onerror", function (e) {
77

88

99
// disable log on production
10-
var CONSOLE_LOG = false;
10+
var CONSOLE_LOG = true;
1111
function consoleLog(msg: any) {
1212
if (CONSOLE_LOG) {
1313
console.log(msg);

0 commit comments

Comments
 (0)