Browse code

skip intro with keyboard or gamepad

devnewton authored on 09/03/2018 16:45:14
Showing 1 changed files
... ...
@@ -3,6 +3,9 @@ import { AbstractState } from "./AbstractState"; // you import only AClass
3 3
 
4 4
 export class Intro extends AbstractState {
5 5
 
6
+    lastKey: Phaser.Key;
7
+    video: Phaser.Video;
8
+
6 9
     constructor() {
7 10
         super();
8 11
     }
... ...
@@ -13,14 +16,31 @@ export class Intro extends AbstractState {
13 16
 
14 17
     create() {
15 18
         super.create();
16
-        var video = this.game.add.video('intro');
17
-        video.play();
18
-        video.addToWorld(this.game.world.centerX, this.game.world.centerY, 0.5, 0.5);
19
-        video.onComplete.add(() => this.game.state.start('Title'));
20
-        
19
+        this.video = this.game.add.video('intro');
20
+        this.video.play();
21
+        this.video.addToWorld(this.game.world.centerX, this.game.world.centerY, 0.5, 0.5);
22
+        this.video.onComplete.add(() => this.game.state.start('Title'));
23
+        this.lastKey = this.game.input.keyboard.lastKey;
21 24
         this.game.input.onTap.add(() => {
22
-            video.stop();
23
-            this.game.state.start('Title');
25
+            this.gotoTitle();
24 26
         });
25 27
     }
28
+
29
+    update() {
30
+        if (this.lastKey != this.game.input.keyboard.lastKey) {
31
+            this.gotoTitle();
32
+            return;
33
+        }
34
+        for (let b = 0; b < 16; ++b) {
35
+            if (this.input.gamepad.isDown(b)) {
36
+                this.gotoTitle();
37
+                return;
38
+            }
39
+        }
40
+    }
41
+
42
+    gotoTitle() {
43
+        this.video.stop();
44
+        this.game.state.start('Title');
45
+    }
26 46
 }