Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: SpawnJSObject
Source: JSObjects/GamepadHapticActuator.cs
MDN Reference: GamepadHapticActuator on MDN
The GamepadHapticActuator interface of the Gamepad API represents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware. https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator
| Signature | Description |
|---|---|
GamepadHapticActuator(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Property | Type | Access | Description |
|---|---|---|---|
Type |
GamepadHapticActuatorType |
get | Returns an enum representing the type of the haptic hardware. |
PlayEffectSupported |
bool |
get | Returns true if PlayEffect is supported |
PulseSupported |
bool |
get | Returns true if Pulse is supported |
ResetSupported |
bool |
get | Returns true if Reset is supported |
| Method | Return Type | Description |
|---|---|---|
Pulse(double value, double duration) |
Task |
The pulse() method of the GamepadHapticActuator interface makes the hardware pulse at a certain intensity for a specified duration. May be Firefox and not Chrome A double representing the intensity of the pulse. This can vary depending on the hardware type, but generally takes a value between 0.0 (no intensity) and 1.0 (full intensity). A double representing the duration of the pulse, in milliseconds. |
PlayEffect(string type, HapticEffectParams effectParams) |
Task |
The playEffect() method of the GamepadHapticActuator interface makes the hardware play a specific vibration pattern. May be Chrome and not Firefox A string representing the desired effect. This can vary depending on the hardware type. Possible values are "dual-rumble" or "vibration". An object to describe a desired haptic effect. |
Reset() |
void |
Cancels the active Effect May be Chrome specific |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<GamepadHapticActuator>(...)or constructornew GamepadHapticActuator(...)
const gamepad = navigator.getGamepads()[0];
gamepad.hapticActuators[0].pulse(1.0, 200);
gamepad.vibrationActuator.playEffect("dual-rumble", {
startDelay: 0,
duration: 200,
weakMagnitude: 1.0,
strongMagnitude: 1.0,
});