Browse code

ingame menu cursor controls

devnewton authored on 08/03/2018 16:15:37
Showing 2 changed files
... ...
@@ -186,7 +186,7 @@ export class Level extends AbstractState {
186 186
             }
187 187
         }, null);
188 188
 
189
-        this.menu = new Menu(this.game, false);
189
+        this.menu = new Menu(this.game);
190 190
         this.menu.alive = false;
191 191
         this.menu.visible = false;
192 192
         this.menu.button("Continue", 200, 260, () => {
... ...
@@ -35,7 +35,7 @@ export class MenuCursor extends Phaser.Text {
35 35
 
36 36
     update() {
37 37
         super.update();
38
-        if(this.game.time.time > this.waitUntil && this.processPad()) {
38
+        if (this.parent.visible && this.game.time.time > this.waitUntil && this.processPad()) {
39 39
             this.waitUntil = this.game.time.time + 230;
40 40
         }
41 41
     }
... ...
@@ -65,7 +65,7 @@ export class MenuCursor extends Phaser.Text {
65 65
     }
66 66
 
67 67
     moveToButton(direction: number) {
68
-        if (this.buttons.children.length > 0) {
68
+        if (this.parent.visible && this.buttons.children.length > 0) {
69 69
             this.visible = true;
70 70
             this.currentButton += direction;
71 71
             if (this.currentButton >= this.buttons.length) {
... ...
@@ -80,12 +80,14 @@ export class MenuCursor extends Phaser.Text {
80 80
         }
81 81
     }
82 82
     activateButton() {
83
-        if (!this.visible) {
84
-            this.moveToButton(0);
85
-        } else if (this.buttons.children.length > 0) {
86
-            const button = <Togglable>this.buttons.children[this.currentButton];
87
-            if (button.toggle) {
88
-                button.toggle();
83
+        if (this.parent.visible) {
84
+            if (!this.visible) {
85
+                this.moveToButton(0);
86
+            } else if (this.buttons.children.length > 0) {
87
+                const button = <Togglable>this.buttons.children[this.currentButton];
88
+                if (button.toggle) {
89
+                    button.toggle();
90
+                }
89 91
             }
90 92
         }
91 93
     }