@@ -8,6 +8,7 @@ var Axis = require('./Axis');
88var Button = require ( './Button' ) ;
99var Class = require ( '../../utils/Class' ) ;
1010var EventEmitter = require ( 'eventemitter3' ) ;
11+ var Vector2 = require ( '../../math/Vector2' ) ;
1112
1213/**
1314 * @classdesc
@@ -112,7 +113,8 @@ var Gamepad = new Class({
112113
113114 /**
114115 * The Gamepad's Haptic Actuator (Vibration / Rumble support).
115- * Only set if present on the device and exposed by both the hardware and browser.
116+ * This is highly experimental and only set if both present on the device,
117+ * and exposed by both the hardware and browser.
116118 *
117119 * @name Phaser.Input.Gamepad.Gamepad#vibration
118120 * @type {GamepadHapticActuator }
@@ -285,6 +287,32 @@ var Gamepad = new Class({
285287 * @since 3.10.0
286288 */
287289 this . _VAxisRight = ( axes [ 3 ] ) ? axes [ 3 ] : _noAxis ;
290+
291+ /**
292+ * A Vector2 containing the most recent values from the Gamepad's left axis stick.
293+ * This is updated automatically as part of the Gamepad.update cycle.
294+ * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property.
295+ * The values are based on the Axis thresholds.
296+ * If the Gamepad does not have a left axis stick, the values will always be zero.
297+ *
298+ * @name Phaser.Input.Gamepad.Gamepad#leftStick
299+ * @type {Phaser.Math.Vector2 }
300+ * @since 3.10.0
301+ */
302+ this . leftStick = new Vector2 ( ) ;
303+
304+ /**
305+ * A Vector2 containing the most recent values from the Gamepad's right axis stick.
306+ * This is updated automatically as part of the Gamepad.update cycle.
307+ * The H Axis is mapped to the `Vector2.x` property, and the V Axis to the `Vector2.y` property.
308+ * The values are based on the Axis thresholds.
309+ * If the Gamepad does not have a right axis stick, the values will always be zero.
310+ *
311+ * @name Phaser.Input.Gamepad.Gamepad#rightStick
312+ * @type {Phaser.Math.Vector2 }
313+ * @since 3.10.0
314+ */
315+ this . rightStick = new Vector2 ( ) ;
288316 } ,
289317
290318 /**
@@ -339,7 +367,9 @@ var Gamepad = new Class({
339367 var localButtons = this . buttons ;
340368 var gamepadButtons = pad . buttons ;
341369
342- for ( i = 0 ; i < localButtons . length ; i ++ )
370+ var len = localButtons . length ;
371+
372+ for ( i = 0 ; i < len ; i ++ )
343373 {
344374 localButtons [ i ] . update ( gamepadButtons [ i ] . value ) ;
345375 }
@@ -348,11 +378,23 @@ var Gamepad = new Class({
348378
349379 var localAxes = this . axes ;
350380 var gamepadAxes = pad . axes ;
381+
382+ len = localAxes . length ;
351383
352- for ( i = 0 ; i < localAxes . length ; i ++ )
384+ for ( i = 0 ; i < len ; i ++ )
353385 {
354386 localAxes [ i ] . update ( gamepadAxes [ i ] ) ;
355387 }
388+
389+ if ( len >= 2 )
390+ {
391+ this . leftStick . set ( localAxes [ 0 ] . getValue ( ) , localAxes [ 1 ] . getValue ( ) ) ;
392+
393+ if ( len >= 4 )
394+ {
395+ this . rightStick . set ( localAxes [ 2 ] . getValue ( ) , localAxes [ 3 ] . getValue ( ) ) ;
396+ }
397+ }
356398 } ,
357399
358400 /**
@@ -419,6 +461,7 @@ var Gamepad = new Class({
419461
420462 /**
421463 * Is the Gamepad's Left button being pressed?
464+ * If the Gamepad doesn't have this button it will always return false.
422465 * This is the d-pad left button under standard Gamepad mapping.
423466 *
424467 * @name Phaser.Input.Gamepad.Gamepad#left
@@ -436,6 +479,7 @@ var Gamepad = new Class({
436479
437480 /**
438481 * Is the Gamepad's Right button being pressed?
482+ * If the Gamepad doesn't have this button it will always return false.
439483 * This is the d-pad right button under standard Gamepad mapping.
440484 *
441485 * @name Phaser.Input.Gamepad.Gamepad#right
@@ -453,6 +497,7 @@ var Gamepad = new Class({
453497
454498 /**
455499 * Is the Gamepad's Up button being pressed?
500+ * If the Gamepad doesn't have this button it will always return false.
456501 * This is the d-pad up button under standard Gamepad mapping.
457502 *
458503 * @name Phaser.Input.Gamepad.Gamepad#up
@@ -470,6 +515,7 @@ var Gamepad = new Class({
470515
471516 /**
472517 * Is the Gamepad's Down button being pressed?
518+ * If the Gamepad doesn't have this button it will always return false.
473519 * This is the d-pad down button under standard Gamepad mapping.
474520 *
475521 * @name Phaser.Input.Gamepad.Gamepad#down
@@ -487,6 +533,7 @@ var Gamepad = new Class({
487533
488534 /**
489535 * Is the Gamepad's bottom button in the right button cluster being pressed?
536+ * If the Gamepad doesn't have this button it will always return false.
490537 * On a Dual Shock controller it's the X button.
491538 * On an XBox controller it's the A button.
492539 *
@@ -505,6 +552,7 @@ var Gamepad = new Class({
505552
506553 /**
507554 * Is the Gamepad's top button in the right button cluster being pressed?
555+ * If the Gamepad doesn't have this button it will always return false.
508556 * On a Dual Shock controller it's the Triangle button.
509557 * On an XBox controller it's the Y button.
510558 *
@@ -523,6 +571,7 @@ var Gamepad = new Class({
523571
524572 /**
525573 * Is the Gamepad's left button in the right button cluster being pressed?
574+ * If the Gamepad doesn't have this button it will always return false.
526575 * On a Dual Shock controller it's the Square button.
527576 * On an XBox controller it's the X button.
528577 *
@@ -541,6 +590,7 @@ var Gamepad = new Class({
541590
542591 /**
543592 * Is the Gamepad's right button in the right button cluster being pressed?
593+ * If the Gamepad doesn't have this button it will always return false.
544594 * On a Dual Shock controller it's the Circle button.
545595 * On an XBox controller it's the B button.
546596 *
@@ -555,6 +605,86 @@ var Gamepad = new Class({
555605 return this . _RCRight . pressed ;
556606 }
557607
608+ } ,
609+
610+ /**
611+ * Returns the value of the Gamepad's top left shoulder button.
612+ * If the Gamepad doesn't have this button it will always return zero.
613+ * The value is a float between 0 and 1, corresponding to how depressed the button is.
614+ * On a Dual Shock controller it's the L1 button.
615+ * On an XBox controller it's the LB button.
616+ *
617+ * @name Phaser.Input.Gamepad.Gamepad#L1
618+ * @type {number }
619+ * @since 3.10.0
620+ */
621+ L1 : {
622+
623+ get : function ( )
624+ {
625+ return this . _FBLeftTop . value
626+ }
627+
628+ } ,
629+
630+ /**
631+ * Returns the value of the Gamepad's bottom left shoulder button.
632+ * If the Gamepad doesn't have this button it will always return zero.
633+ * The value is a float between 0 and 1, corresponding to how depressed the button is.
634+ * On a Dual Shock controller it's the L2 button.
635+ * On an XBox controller it's the LT button.
636+ *
637+ * @name Phaser.Input.Gamepad.Gamepad#L2
638+ * @type {number }
639+ * @since 3.10.0
640+ */
641+ L2 : {
642+
643+ get : function ( )
644+ {
645+ return this . _FBLeftBottom . value
646+ }
647+
648+ } ,
649+
650+ /**
651+ * Returns the value of the Gamepad's top right shoulder button.
652+ * If the Gamepad doesn't have this button it will always return zero.
653+ * The value is a float between 0 and 1, corresponding to how depressed the button is.
654+ * On a Dual Shock controller it's the R1 button.
655+ * On an XBox controller it's the RB button.
656+ *
657+ * @name Phaser.Input.Gamepad.Gamepad#R1
658+ * @type {number }
659+ * @since 3.10.0
660+ */
661+ R1 : {
662+
663+ get : function ( )
664+ {
665+ return this . _FBRightTop . value
666+ }
667+
668+ } ,
669+
670+ /**
671+ * Returns the value of the Gamepad's bottom right shoulder button.
672+ * If the Gamepad doesn't have this button it will always return zero.
673+ * The value is a float between 0 and 1, corresponding to how depressed the button is.
674+ * On a Dual Shock controller it's the R2 button.
675+ * On an XBox controller it's the RT button.
676+ *
677+ * @name Phaser.Input.Gamepad.Gamepad#R2
678+ * @type {number }
679+ * @since 3.10.0
680+ */
681+ R2 : {
682+
683+ get : function ( )
684+ {
685+ return this . _FBRightBottom . value
686+ }
687+
558688 }
559689
560690} ) ;
0 commit comments