类型 函数 对象 InputDevice 返回值 无 修订 版本 2024.3703 关键字 设备、输入、震动、canVibrate 另请参阅 对象.canVibrate
使输入设备振动/轰鸣。
这是一项功能,通常只有游戏手柄支持。你可以通过读取其 canVibrate 属性来确定输入设备是否支持振动反馈。
在 Android 上,你必须将以下权限添加到 build.settings
文件。
settings = { android = { usesPermissions = { "android.permission.VIBRATE", }, }, }
-- Called when a key event has been received local function onKeyEvent( event ) -- Vibrate the gamepad if its 'A' button was pressed if ( event.keyName == "buttonA" ) and ( event.phase == "down" ) then if event.device and event.device.canVibrate then event.device:vibrate() end end end -- Set up the above function to receive key events Runtime:addEventListener( "key", onKeyEvent )