Skip to content

Commit 3b17544

Browse files
Scene editor: use fake hitTest by default.
Change to avoid run the hitTest routine each time the mouse is moved. The real routine is run only at mouse down, to select the objects.
1 parent 7de7596 commit 3b17544

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ namespace PhaserEditor2D {
33

44
export class Editor {
55

6+
hitTestPointer(scene: Phaser.Scene, pointer: Phaser.Input.Pointer): any {
7+
const input: any = scene.game.input;
8+
9+
const real = input.real_hitTest;
10+
const fake = input.hitTest;
11+
12+
input.hitTest = real;
13+
14+
const result = scene.input.hitTestPointer(pointer);
15+
16+
input.hitTest = fake;
17+
18+
return result;
19+
}
20+
621

722
private static _instance: Editor;
823
private _socket: WebSocket;
@@ -305,11 +320,19 @@ namespace PhaserEditor2D {
305320
}
306321
});
307322

308-
(<any>this._game.config).postBoot = function (game : Phaser.Game) {
323+
(<any>this._game.config).postBoot = function (game: Phaser.Game) {
309324
consoleLog("Game booted");
310325
setTimeout(() => self.stop(), 500);
311326
};
312327

328+
// default hitTest is a NOOP, so it does not run heavy tests in all mouse moves.
329+
const input: any = this._game.input;
330+
input.real_hitTest = input.hitTest;
331+
input.hitTest = function () {
332+
return [];
333+
};
334+
// --
335+
313336
this._objectScene = new ObjectScene();
314337

315338
this._game.scene.add("ObjectScene", this._objectScene);
@@ -448,7 +471,7 @@ namespace PhaserEditor2D {
448471
scene.load.crossOrigin = "anonymous";
449472
scene.load.addPack(loadMsg.pack);
450473
scene.load.start();
451-
setTimeout( ()=> this.repaint(), 100);
474+
setTimeout(() => this.repaint(), 100);
452475
} else {
453476
this.processMessageList(index + 1, list);
454477
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace PhaserEditor2D {
145145
return;
146146
}
147147

148-
const result = scene.input.hitTestPointer(pointer);
148+
const result = editor.hitTestPointer(scene, pointer);
149149

150150
consoleLog(result);
151151

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ var PhaserEditor2D;
99
Editor._instance = this;
1010
this.openSocket();
1111
}
12+
Editor.prototype.hitTestPointer = function (scene, pointer) {
13+
var input = scene.game.input;
14+
var real = input.real_hitTest;
15+
var fake = input.hitTest;
16+
input.hitTest = real;
17+
var result = scene.input.hitTestPointer(pointer);
18+
input.hitTest = fake;
19+
return result;
20+
};
1221
Editor.getInstance = function () {
1322
return Editor._instance;
1423
};
@@ -231,6 +240,11 @@ var PhaserEditor2D;
231240
consoleLog("Game booted");
232241
setTimeout(function () { return self.stop(); }, 500);
233242
};
243+
var input = this._game.input;
244+
input.real_hitTest = input.hitTest;
245+
input.hitTest = function () {
246+
return [];
247+
};
234248
this._objectScene = new PhaserEditor2D.ObjectScene();
235249
this._game.scene.add("ObjectScene", this._objectScene);
236250
this._game.scene.add("ToolScene", PhaserEditor2D.ToolScene);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var PhaserEditor2D;
114114
if (!PhaserEditor2D.isLeftButton(e)) {
115115
return;
116116
}
117-
var result = scene.input.hitTestPointer(pointer);
117+
var result = editor.hitTestPointer(scene, pointer);
118118
consoleLog(result);
119119
var gameObj = result.pop();
120120
editor.sendMessage({

0 commit comments

Comments
 (0)