2011-04-29 31 views
5

我試圖將動畫放在一起,我可以在其中指定速度(而不是持續時間)以及永遠循環的動畫。我想出了兩個非工作的例子:同時具有「速度」和無限「循環」的QML動畫

FirstTry.qml

import Qt 4.7 

Rectangle { 
    width: 100; height: 100 
    Text { 
    text: "hello" 
    NumberAnimation on x { 
     to: 50; 
     loops: Animation.Infinite; 
     duration: 50 * Math.abs(to - from) 
    } 
    } 
} 

我得到以下運行時警告而hello去堅果屏幕(不夠公平)上。

QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties: 
    QDeclarativeNumberAnimation::to 
    QDeclarativeNumberAnimation::from 

SecondTry.qml

import Qt 4.7 

Rectangle { 
    width: 100; height: 100 
    Text { 
    text: "hello" 
    SmoothedAnimation on x { 
     to: 50; 
     loops: Animation.Infinite; 
     velocity: 50 
    } 
    } 
} 

這更是一個謎的 - SmoothedAnimation只是拒絕循環!動畫運行一次,然後就是這樣。

所以,我有以下問題:

是否有指定的第一個例子速度的合法途徑?據我所知,SmoothedAnimation源自NumberAnimation,所以也許在QML中是可能的,而不僅僅是在C++中。

有沒有辦法讓SmoothedAnimation循環?第二個例子不是在操作錯誤還是我錯過了某些東西?

有沒有其他辦法可以同時實現這兩種行爲?

回答

1

這就是我作爲臨時解決方案所做的,我不確定它是否足夠,但它似乎只是做我所需要的。

SmoothedAnimation on x { 
    to: 50; 
    //loops: Animation.Infinite; 
    velocity: 50 
    onComplete: { restart(); } 
} 

雖然我仍然對這些問題的答案感興趣。

3

只需添加「從」參數明確:

import Qt 4.7 

Rectangle { 
    width: 100; height: 100 
    Text { 
    text: "hello" 
    NumberAnimation on x { 
     from: 0; 
     to: 50; 
     loops: Animation.Infinite; 
     duration: 50 * Math.abs(to - from) 
    } 
    } 
} 
0

即使SmoothedAnimation不接受循環參數,你可以把它裏面SequentialAnimation和應用循環這個外蓋。作爲一種效果,您的平滑動畫將連續播放。