如何在Ubuntu QML应用中震动(vibration)
来源:互联网 发布:unity3d 跳跃代码 编辑:程序博客网 时间:2024/05/15 04:17
对于有些QML应用来说,震动是非常重要的一个功能。特别是对一下游戏来说。那么我们怎么在QML应用中震动呢?
我们官方有一个API HapticsEffect,这个API的功能就是让我们的应用来震动的。使用这个API非常容易:
import QtQuick 2.0import Ubuntu.Components 1.1import QtFeedback 5.0/*! \brief MainView with a Label and Button elements.*/MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "vibration.liu-xiao-guo" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(100) height: units.gu(75) Page { title: i18n.tr("vibration") HapticsEffect { id: rumbleEffect attackIntensity: 0.0 attackTime: 250 intensity: 1.0 duration: 100 fadeTime: 250 fadeIntensity: 0.0 } Column { spacing: units.gu(1) anchors { margins: units.gu(2) fill: parent } Button { objectName: "button" width: parent.width text: i18n.tr("Vibrate me!") onClicked: { rumbleEffect.start(); // plays a rumble effect } } } }}
这里我们import了我们需要的库:
import QtFeedback 5.0
然后,实例化我们的HapticsEffect:
HapticsEffect { id: rumbleEffect attackIntensity: 0.0 attackTime: 250 intensity: 1.0 duration: 100 fadeTime: 250 fadeIntensity: 0.0 }
当我们按下我们的按钮时,我们及开始震动了。当然这个必须是在手机上才可以测试到。
整个项目的源码在:https://github.com/liu-xiao-guo/vibration
0 0
- 如何在Ubuntu QML应用中震动(vibration)
- 如何在Ubuntu QML应用中使用Push Notification
- 如何在Ubuntu QML应用中播放音乐
- 如何在Ubuntu QML应用中播放视频
- 如何在Ubuntu QML应用中进行语言录音
- 如何在Ubuntu QML应用中实现MultipleSelectionListView
- 如何在Ubuntu QML应用中实现ComboBox的功能
- 如何在QML应用中读写文件
- 如何在QML应用中启动Scope
- 如何在Ubuntu QML应用中判断应用的方位(landscape或portrait)
- 如何在Ubuntu QML应用中实现一个垂直的Slider
- 如何在Ubuntu QML应用中设计像微信对话那样的UI
- 如何优化在Ubuntu手机中的QML应用
- 怎么在Ubuntu QML应用中侦测到Swipe手势
- 在Ubuntu QML应用中实现Particle特效
- 如何在QML应用中使用Javascript解析JSON
- 如何在QML应用中使用Javascript来解析XML
- 如何在QML应用中实现一个Splash画面
- 【Java-常用类】String类,StringBuffer类,StringBuilder类
- linux驱动之模块驱动makefile详细分析
- 11AC ath10k的移植
- 学习安卓推荐的一些资源和准备
- Asp.net中的<@register%>
- 如何在Ubuntu QML应用中震动(vibration)
- c# web站点提交报错 从客户端(Submit="...")中检测到有潜在危险的 Request.Form 值。
- android 第三方登录和分享(5)
- rman备份恢复命令之switch
- TabHost 和 FragmentTabHost
- iOS开发经验之iOS开发学习路径的一些建议
- ios开发-Runtime理解,应用,基本知识
- 分治法--循环赛事日程表
- redis-cluster研究和使用