Skip to content

Commit f613e58

Browse files
committed
Allowed Keyboard and Gamepad to be optional.
1 parent a7bdce1 commit f613e58

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

src/input/Input.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,18 @@ Phaser.Input.prototype = {
361361
this.addPointer();
362362

363363
this.mouse = new Phaser.Mouse(this.game);
364-
this.keyboard = new Phaser.Keyboard(this.game);
365364
this.touch = new Phaser.Touch(this.game);
366365
this.mspointer = new Phaser.MSPointer(this.game);
367-
this.gamepad = new Phaser.Gamepad(this.game);
366+
367+
if (Phaser.Keyboard)
368+
{
369+
this.keyboard = new Phaser.Keyboard(this.game);
370+
}
371+
372+
if (Phaser.Gamepad)
373+
{
374+
this.gamepad = new Phaser.Gamepad(this.game);
375+
}
368376

369377
this.onDown = new Phaser.Signal();
370378
this.onUp = new Phaser.Signal();
@@ -387,12 +395,17 @@ Phaser.Input.prototype = {
387395
this.hitContext = this.hitCanvas.getContext('2d');
388396

389397
this.mouse.start();
390-
this.keyboard.start();
391398
this.touch.start();
392399
this.mspointer.start();
393400
this.mousePointer.active = true;
394401

402+
if (this.keyboard)
403+
{
404+
this.keyboard.start();
405+
}
406+
395407
var _this = this;
408+
396409
this._onClickTrampoline = function (event) {
397410
_this.onClickTrampoline(event);
398411
};
@@ -409,10 +422,18 @@ Phaser.Input.prototype = {
409422
destroy: function () {
410423

411424
this.mouse.stop();
412-
this.keyboard.stop();
413425
this.touch.stop();
414426
this.mspointer.stop();
415-
this.gamepad.stop();
427+
428+
if (this.keyboard)
429+
{
430+
this.keyboard.stop();
431+
}
432+
433+
if (this.gamepad)
434+
{
435+
this.gamepad.stop();
436+
}
416437

417438
this.moveCallbacks = [];
418439

@@ -489,7 +510,10 @@ Phaser.Input.prototype = {
489510
*/
490511
update: function () {
491512

492-
this.keyboard.update();
513+
if (this.keyboard)
514+
{
515+
this.keyboard.update();
516+
}
493517

494518
if (this.pollRate > 0 && this._pollCounter < this.pollRate)
495519
{
@@ -503,7 +527,10 @@ Phaser.Input.prototype = {
503527
this._oldPosition.copyFrom(this.position);
504528
this.mousePointer.update();
505529

506-
if (this.gamepad.active) { this.gamepad.update(); }
530+
if (this.gamepad && this.gamepad.active)
531+
{
532+
this.gamepad.update();
533+
}
507534

508535
for (var i = 0; i < this.pointers.length; i++)
509536
{
@@ -534,9 +561,17 @@ Phaser.Input.prototype = {
534561

535562
if (typeof hard === 'undefined') { hard = false; }
536563

537-
this.keyboard.reset(hard);
538564
this.mousePointer.reset();
539-
this.gamepad.reset();
565+
566+
if (this.keyboard)
567+
{
568+
this.keyboard.reset(hard);
569+
}
570+
571+
if (this.gamepad)
572+
{
573+
this.gamepad.reset();
574+
}
540575

541576
for (var i = 0; i < this.pointers.length; i++)
542577
{

0 commit comments

Comments
 (0)