Skip to content

Commit

Permalink
Updated keyboard controls
Browse files Browse the repository at this point in the history
  • Loading branch information
n00begon committed Feb 5, 2024
1 parent 9a53d70 commit a77686e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/ControlManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ export class ControlManager {
*/
constructor(scene: Phaser.Scene) {
this.scene = scene;
this.jumpKey = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
this.jumpKey2 = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
this.leftKey = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
this.rightKey = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
this.leftKey2 = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
this.rightKey2 = scene.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
let keyboard = scene.input.keyboard;
if(!keyboard){
keyboard = new Phaser.Input.Keyboard.KeyboardPlugin(scene.input)
}

this.jumpKey = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
this.jumpKey2 = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
this.leftKey = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
this.rightKey = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
this.leftKey2 = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
this.rightKey2 = keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);

scene.input.on("pointerdown", (pointer: Phaser.Input.Pointer) => {
this.currentPointer = pointer;
});
Expand Down Expand Up @@ -74,7 +79,7 @@ export class ControlManager {
}

private gamepadInput() {
if (this.scene.input.gamepad.total === 0) {
if (!this.scene.input.gamepad || this.scene.input.gamepad.total === 0) {
return;
}

Expand Down

0 comments on commit a77686e

Please sign in to comment.