@@ -35,50 +35,57 @@ export class KeyManager {
35
35
this . keys [ e . keyCode ] = false ;
36
36
} ;
37
37
38
- // this.mc = new Hammer.Manager(stage);
39
-
40
- // const pan = new Hammer.Pan();
41
- // const tap = new Hammer.Tap();
42
- // const pinch = new Hammer.Pinch({
43
- // enable: true,
44
- // });
45
-
46
- // this.mc.add(pan);
47
- // this.mc.add(tap, {
48
- // interval: 50,
49
- // });
50
- // this.mc.add(pinch);
51
-
52
- // this.mc.on("panup", () => {
53
- // this.thrust(true);
54
- // });
55
-
56
- // this.mc.on("panleft", () => {
57
- // this.rotateLeft(true);
58
- // });
59
-
60
- // this.mc.on("panright", () => {
61
- // this.rotateRight(true);
62
- // });
63
-
64
- // this.mc.on("panend", () => {
65
- // this.thrust(false);
66
- // this.rotateLeft(false);
67
- // this.rotateRight(false);
68
- // });
69
-
70
- // this.mc.on("tap", () => {
71
- // this.fire(true);
72
- // this.touched = true;
73
- // });
74
-
75
- // this.mc.on("pinchout", () => {
76
- // this.hyperspace(true);
77
- // });
78
-
79
- // this.mc.on("pinchend", () => {
80
- // this.hyperspace(false);
81
- // });
38
+ const isTouchDevice = "ontouchstart" in window ;
39
+ if ( isTouchDevice ) {
40
+ console . log ( "Touch device detected" ) ;
41
+ const Hammer = require ( "hammerjs" ) ;
42
+
43
+ this . mc = new Hammer . Manager ( stage ) ;
44
+
45
+ const pan = new Hammer . Pan ( ) ;
46
+ const tap = new Hammer . Tap ( ) ;
47
+ const pinch = new Hammer . Pinch ( {
48
+ enable : true ,
49
+ } ) ;
50
+
51
+ this . mc . add ( pan ) ;
52
+ this . mc . add ( tap , {
53
+ interval : 50 ,
54
+ } ) ;
55
+ this . mc . add ( pinch ) ;
56
+
57
+ this . mc . on ( "panup" , ( ) => {
58
+ this . thrust ( true ) ;
59
+ } ) ;
60
+
61
+ this . mc . on ( "panleft" , ( ) => {
62
+ this . rotateLeft ( true ) ;
63
+ } ) ;
64
+
65
+ this . mc . on ( "panright" , ( ) => {
66
+ this . rotateRight ( true ) ;
67
+ } ) ;
68
+
69
+ this . mc . on ( "panend" , ( ) => {
70
+ this . thrust ( false ) ;
71
+ this . rotateLeft ( false ) ;
72
+ this . rotateRight ( false ) ;
73
+ } ) ;
74
+
75
+ this . mc . on ( "tap" , ( ) => {
76
+ this . fire ( true ) ;
77
+ this . enter ( true ) ;
78
+ this . touched = true ;
79
+ } ) ;
80
+
81
+ this . mc . on ( "pinchout" , ( ) => {
82
+ this . hyperspace ( true ) ;
83
+ } ) ;
84
+
85
+ this . mc . on ( "pinchend" , ( ) => {
86
+ this . hyperspace ( false ) ;
87
+ } ) ;
88
+ }
82
89
}
83
90
84
91
update ( ) {
@@ -168,6 +175,10 @@ export class KeyManager {
168
175
this . keys [ Keys . FIRE ] = active ;
169
176
} ;
170
177
178
+ private enter = ( active : boolean ) => {
179
+ this . keys [ Keys . START ] = active ;
180
+ } ;
181
+
171
182
private hyperspace = ( active : boolean ) => {
172
183
this . keys [ Keys . HYPERSPACE ] = active ;
173
184
} ;
0 commit comments