Difference between revisions of "Joystick:setVibration"

m
(Example)
 
(3 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
{{param|number|left|Strength of the left vibration motor on the Joystick. Must be in the range of [0, 1].}}
 
{{param|number|left|Strength of the left vibration motor on the Joystick. Must be in the range of [0, 1].}}
 
{{param|number|right|Strength of the right vibration motor on the Joystick. Must be in the range of [0, 1].}}
 
{{param|number|right|Strength of the right vibration motor on the Joystick. Must be in the range of [0, 1].}}
 +
=== Returns ===
 +
{{param|boolean|success|True if the vibration was successfully applied, false if not.}}
 +
 +
== Function ==
 +
Disables vibration.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
success = Joystick:setVibration( )
 +
</source>
 +
=== Arguments ===
 +
None.
 +
=== Returns ===
 +
{{param|boolean|success|True if the vibration was successfully disabled, false if not.}}
 +
 +
== Function ==
 +
{{newin|[[0.9.2]]|092|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
success = Joystick:setVibration( left, right, duration )
 +
</source>
 +
=== Arguments ===
 +
{{param|number|left|Strength of the left vibration motor on the Joystick. Must be in the range of [0, 1].}}
 +
{{param|number|right|Strength of the right vibration motor on the Joystick. Must be in the range of [0, 1].}}
 +
{{param|number|duration (-1)|The duration of the vibration in seconds. A negative value means infinite duration.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|boolean|success|True if the vibration was successfully applied, false if not.}}
 
{{param|boolean|success|True if the vibration was successfully applied, false if not.}}
Line 18: Line 42:
  
 
The very first call to this function may take more time than expected because SDL's Haptic / Force Feedback subsystem needs to be initialized.
 
The very first call to this function may take more time than expected because SDL's Haptic / Force Feedback subsystem needs to be initialized.
 +
 +
== Example ==
 +
<source lang="lua">
 +
function love.gamepadaxis( joystick, axis, value )
 +
if axis == 'triggerleft' or axis == 'triggerright' then
 +
local left = joystick:getGamepadAxis("triggerleft")
 +
local right = joystick:getGamepadAxis("triggerright")
 +
success = joystick:setVibration(left, right)
 +
end
 +
end
 +
</source>
  
 
== See Also ==
 
== See Also ==

Latest revision as of 16:59, 5 November 2021

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Sets the vibration motor speeds on a Joystick with rumble support. Most common gamepads have this functionality, although not all drivers give proper support. Use Joystick:isVibrationSupported to check.

Function

Synopsis

success = Joystick:setVibration( left, right )

Arguments

number left
Strength of the left vibration motor on the Joystick. Must be in the range of [0, 1].
number right
Strength of the right vibration motor on the Joystick. Must be in the range of [0, 1].

Returns

boolean success
True if the vibration was successfully applied, false if not.

Function

Disables vibration.

Synopsis

success = Joystick:setVibration( )

Arguments

None.

Returns

boolean success
True if the vibration was successfully disabled, false if not.

Function

Available since LÖVE 0.9.2
This variant is not supported in earlier versions.

Synopsis

success = Joystick:setVibration( left, right, duration )

Arguments

number left
Strength of the left vibration motor on the Joystick. Must be in the range of [0, 1].
number right
Strength of the right vibration motor on the Joystick. Must be in the range of [0, 1].
number duration (-1)
The duration of the vibration in seconds. A negative value means infinite duration.

Returns

boolean success
True if the vibration was successfully applied, false if not.

Notes

If the Joystick only has a single vibration motor, it will still work but it will use the largest value of the left and right parameters.

The Xbox 360 controller on Mac OS X only has support for vibration if a modified version of the Tattiebogle driver is used.

The very first call to this function may take more time than expected because SDL's Haptic / Force Feedback subsystem needs to be initialized.

Example

function love.gamepadaxis( joystick, axis, value )
	if axis == 'triggerleft' or axis == 'triggerright' then
		local left = joystick:getGamepadAxis("triggerleft")
		local right = joystick:getGamepadAxis("triggerright")
		success = joystick:setVibration(left, right)
	end
end

See Also

Other Languages