QML —— 顺序动画,足球落地示例(附完整源码)

 

效果

 

源码
cpp 复制代码
import QtQuick 2.12
import QtQuick.Window 2.12

Window
{
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    MouseArea
    {
        anchors.fill: parent
        onClicked:{setSequentialAnimationState(true)}
    }

    Component.onCompleted:{setSequentialAnimationState(false)}
    Component.onDestruction:{setSequentialAnimationState(false)}

    function setSequentialAnimationState(b)
    {
        if(b)
        {
            if(!sequentialAnimation.running){sequentialAnimation.start()}
        }
        else
        {
             if(sequentialAnimation.running){sequentialAnimation.stop()}
        }
    }

    Image
    {
        id: ballImg
        source: "ball.jpeg"
        scale: 0.3
        y: -height
        anchors.horizontalCenter: parent.horizontalCenter

        SequentialAnimation on y
        {
            id: sequentialAnimation
            loops: Animation.Infinite
            NumberAnimation
            {
                id: fallNumberAnimation
                to: ballImg.parent.height - ballImg.height
                easing.type: Easing.OutBounce
                duration: 2000
            }

            PauseAnimation {duration: 1000}

            NumberAnimation
            {
                to: -ballImg.height
                easing.type: Easing.OutQuad
                duration: 500
            }

        }
    }
}

 

关注

笔者 - jxd

 

相关推荐
金色熊族1 小时前
在Qt中使用asan检测内存泄漏(一)
linux·qt·asan
前行中的小猪2 小时前
Qt 5 踩坑实录:多显示器跨屏拖拽导致窗口异常放大与 setGeometry 报错的深度解析与根治
qt·多显示器·高分辨率·多屏幕
想做小南娘,发现自己是女生喵3 小时前
QT项目实战第一周(嵌入式)
开发语言·qt
誰能久伴不乏5 小时前
【无标题】
c++·qt·机器人
金色熊族5 小时前
在Qt中使用asan检测内存泄漏(二)--检查依赖库的内存使用
linux·qt·asan
qq_401700415 小时前
Qt 组播(Multicast)实战详解
开发语言·qt
布莱克6051 天前
QtWidgets 与 QML:两大 UI 开发框架的全面对比
开发语言·c++·qt·ui·架构
qq_401700411 天前
Qt 实时大数据量存储:自己动手实现 TDMS 读写
数据库·qt
NiceBlueChai1 天前
Qt 跨线程传递多容器嵌套结构:一次 Release 实测
开发语言·qt
扶尔魔ocy1 天前
【QT android】模仿行车记录仪案例
android·qt