gamepad.d.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { Observable } from "../Misc/observable";
  2. /**
  3. * Represents a gamepad control stick position
  4. */
  5. export declare class StickValues {
  6. /**
  7. * The x component of the control stick
  8. */
  9. x: number;
  10. /**
  11. * The y component of the control stick
  12. */
  13. y: number;
  14. /**
  15. * Initializes the gamepad x and y control stick values
  16. * @param x The x component of the gamepad control stick value
  17. * @param y The y component of the gamepad control stick value
  18. */
  19. constructor(
  20. /**
  21. * The x component of the control stick
  22. */
  23. x: number,
  24. /**
  25. * The y component of the control stick
  26. */
  27. y: number);
  28. }
  29. /**
  30. * An interface which manages callbacks for gamepad button changes
  31. */
  32. export interface GamepadButtonChanges {
  33. /**
  34. * Called when a gamepad has been changed
  35. */
  36. changed: boolean;
  37. /**
  38. * Called when a gamepad press event has been triggered
  39. */
  40. pressChanged: boolean;
  41. /**
  42. * Called when a touch event has been triggered
  43. */
  44. touchChanged: boolean;
  45. /**
  46. * Called when a value has changed
  47. */
  48. valueChanged: boolean;
  49. }
  50. /**
  51. * Represents a gamepad
  52. */
  53. export declare class Gamepad {
  54. /**
  55. * The id of the gamepad
  56. */
  57. id: string;
  58. /**
  59. * The index of the gamepad
  60. */
  61. index: number;
  62. /**
  63. * The browser gamepad
  64. */
  65. browserGamepad: any;
  66. /**
  67. * Specifies what type of gamepad this represents
  68. */
  69. type: number;
  70. private _leftStick;
  71. private _rightStick;
  72. /** @internal */
  73. _isConnected: boolean;
  74. private _leftStickAxisX;
  75. private _leftStickAxisY;
  76. private _rightStickAxisX;
  77. private _rightStickAxisY;
  78. /**
  79. * Triggered when the left control stick has been changed
  80. */
  81. private _onleftstickchanged;
  82. /**
  83. * Triggered when the right control stick has been changed
  84. */
  85. private _onrightstickchanged;
  86. /**
  87. * Represents a gamepad controller
  88. */
  89. static GAMEPAD: number;
  90. /**
  91. * Represents a generic controller
  92. */
  93. static GENERIC: number;
  94. /**
  95. * Represents an XBox controller
  96. */
  97. static XBOX: number;
  98. /**
  99. * Represents a pose-enabled controller
  100. */
  101. static POSE_ENABLED: number;
  102. /**
  103. * Represents an Dual Shock controller
  104. */
  105. static DUALSHOCK: number;
  106. /**
  107. * Specifies whether the left control stick should be Y-inverted
  108. */
  109. protected _invertLeftStickY: boolean;
  110. /**
  111. * Specifies if the gamepad has been connected
  112. */
  113. get isConnected(): boolean;
  114. /**
  115. * Initializes the gamepad
  116. * @param id The id of the gamepad
  117. * @param index The index of the gamepad
  118. * @param browserGamepad The browser gamepad
  119. * @param leftStickX The x component of the left joystick
  120. * @param leftStickY The y component of the left joystick
  121. * @param rightStickX The x component of the right joystick
  122. * @param rightStickY The y component of the right joystick
  123. */
  124. constructor(
  125. /**
  126. * The id of the gamepad
  127. */
  128. id: string,
  129. /**
  130. * The index of the gamepad
  131. */
  132. index: number,
  133. /**
  134. * The browser gamepad
  135. */
  136. browserGamepad: any, leftStickX?: number, leftStickY?: number, rightStickX?: number, rightStickY?: number);
  137. /**
  138. * Callback triggered when the left joystick has changed
  139. * @param callback callback to trigger
  140. */
  141. onleftstickchanged(callback: (values: StickValues) => void): void;
  142. /**
  143. * Callback triggered when the right joystick has changed
  144. * @param callback callback to trigger
  145. */
  146. onrightstickchanged(callback: (values: StickValues) => void): void;
  147. /**
  148. * Gets the left joystick
  149. */
  150. get leftStick(): StickValues;
  151. /**
  152. * Sets the left joystick values
  153. */
  154. set leftStick(newValues: StickValues);
  155. /**
  156. * Gets the right joystick
  157. */
  158. get rightStick(): StickValues;
  159. /**
  160. * Sets the right joystick value
  161. */
  162. set rightStick(newValues: StickValues);
  163. /**
  164. * Updates the gamepad joystick positions
  165. */
  166. update(): void;
  167. /**
  168. * Disposes the gamepad
  169. */
  170. dispose(): void;
  171. }
  172. /**
  173. * Represents a generic gamepad
  174. */
  175. export declare class GenericPad extends Gamepad {
  176. private _buttons;
  177. private _onbuttondown;
  178. private _onbuttonup;
  179. /**
  180. * Observable triggered when a button has been pressed
  181. */
  182. onButtonDownObservable: Observable<number>;
  183. /**
  184. * Observable triggered when a button has been released
  185. */
  186. onButtonUpObservable: Observable<number>;
  187. /**
  188. * Callback triggered when a button has been pressed
  189. * @param callback Called when a button has been pressed
  190. */
  191. onbuttondown(callback: (buttonPressed: number) => void): void;
  192. /**
  193. * Callback triggered when a button has been released
  194. * @param callback Called when a button has been released
  195. */
  196. onbuttonup(callback: (buttonReleased: number) => void): void;
  197. /**
  198. * Initializes the generic gamepad
  199. * @param id The id of the generic gamepad
  200. * @param index The index of the generic gamepad
  201. * @param browserGamepad The browser gamepad
  202. */
  203. constructor(id: string, index: number, browserGamepad: any);
  204. private _setButtonValue;
  205. /**
  206. * Updates the generic gamepad
  207. */
  208. update(): void;
  209. /**
  210. * Disposes the generic gamepad
  211. */
  212. dispose(): void;
  213. }