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

相关推荐
q***23571 天前
RabbitMQ介绍以及基本使用
qt·rabbitmq·ruby
王宪笙1 天前
Qt之数据库使用示例
数据库·qt
Jonathan Star1 天前
JSON-RPC 2.0 详解
qt·rpc·json
一只爱学习的小鱼儿1 天前
QT中3D的使用
开发语言·数据库·qt
FL16238631291 天前
Qt自定义控件之仪表盘和水波纹圆形进度条的完整实现
开发语言·qt
开始了码2 天前
QT::对话框:字体对话框3
qt
rainbow_lucky01062 天前
Word-like编辑器
qt·编辑器·word-like
开始了码2 天前
QT::对话框:颜色对话框2
qt
穆雄雄2 天前
Qt-for-鸿蒙PC Slider 组件开源鸿蒙开发实践
qt·开源·harmonyos
国服第二切图仔2 天前
Qt-for-鸿蒙PC-多线程绘制开源鸿蒙开发实践
qt·开源·鸿蒙pc