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

 

相关推荐
ShineWinsu6 小时前
对于Qt:QWidget通用属性的解析—上
数据库·qt·microsoft·面试·gui·属性·qwidget
Quz8 小时前
QML 字体度量与文本度量:FontMetrics 与 TextMetrics
qt
Quz8 小时前
QML 字体加载:FontLoader 与 FontInfo
qt
奇树谦9 小时前
Qt | 基于 GVCP 协议的 GigE 工业相机 IP 配置工具
数码相机·qt·tcp/ip
扶尔魔ocy1 天前
【qt openGL入门笔记】windows编译MinGW版本的osgearth(2.10.1)
qt·opengl·osg
小王C语言1 天前
Qt常用控件:按钮类控件,普通按键、单选、复选
开发语言·qt
初阳7852 天前
【基于Qt5仿音乐播放器(六)】——细节打磨与总结
qt·1024程序员节
小鱼仙官2 天前
使用Qt封装C/C++ 动态库 用于第三方调用
c语言·c++·qt
扶尔魔ocy2 天前
【QT OpenGL】知识点编目及传送门
qt·opengl·osg
qq_401700412 天前
Qt Modbus 源码剖析:从 QModbusClient 到工业级通信框架
开发语言·qt·系统架构