Skip to content

Commit

Permalink
Add centerSelectedGameObject parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Oct 10, 2023
1 parent 4db0e6e commit 2ead951
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions templates/gameobjectshell/shell/Shell.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default Shell;

declare namespace Shell {
interface IConfig {
centerSelectedGameObject?: boolean,

onSelectGameObject?: (
shell: Shell,
gameObject: Phaser.GameObjects.GameObject
Expand Down
1 change: 1 addition & 0 deletions templates/gameobjectshell/shell/Shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Shell extends ComponentBase {
super(scene, config);
// this.scene

this.centerSelectedGameObject = GetValue(config, 'centerSelectedGameObject', true);
this.onSelectGameObjectCallback = GetValue(config, 'onSelectGameObject', OnSelectGameObject);
this.onUnSelectGameObjectCallback = GetValue(config, 'onUnSelectGameObject', OnUnSelectGameObject);

Expand Down
22 changes: 13 additions & 9 deletions templates/gameobjectshell/shell/methods/SelectGameObjectMethods.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
var OnSelectGameObject = function (shell, gameObject) {
var camera = shell.scene.cameras.main;
if (shell.lastCameraScrollX == undefined) {
shell.lastCameraScrollX = camera.scrollX;
shell.lastCameraScrollY = camera.scrollY;
if (shell.centerSelectedGameObject) {
var camera = shell.scene.cameras.main;
if (shell.lastCameraScrollX == undefined) {
shell.lastCameraScrollX = camera.scrollX;
shell.lastCameraScrollY = camera.scrollY;
}
}

camera.centerOn(gameObject.x, gameObject.y);
shell.setBindingTarget(gameObject);
}

var OnUnSelectGameObject = function (shell) {
if (shell.lastCameraScrollX !== undefined) {
var camera = shell.scene.cameras.main;
camera.setScroll(shell.lastCameraScrollX, shell.lastCameraScrollY)
shell.lastCameraScrollX = undefined;
shell.lastCameraScrollY = undefined;
if (shell.centerSelectedGameObject) {
if (shell.lastCameraScrollX !== undefined) {
var camera = shell.scene.cameras.main;
camera.setScroll(shell.lastCameraScrollX, shell.lastCameraScrollY)
shell.lastCameraScrollX = undefined;
shell.lastCameraScrollY = undefined;
}
}

shell.clearBindingTarget();
Expand Down

0 comments on commit 2ead951

Please sign in to comment.