2017-02-25 83 views
0

我正在使用QTimeLine在指定的時間內處理動畫/動作,讓玩家在屏幕上移動。Qt QTimeLine跳過第一幀

在我的播放器的構造函數:

timeLine = new QTimeLine(500); 
timeLine->setFrameRange(1, 4); 
timeLine->setCurveShape(QTimeLine::CurveShape::LinearCurve); 
QObject::connect(timeLine, SIGNAL(frameChanged(int)), this, SLOT(animatedMove(int))); 

我刪除了動畫的東西,只是顯示問題:

void PlayerSprite::animatedMove(int frame) 
{ 
    qDebug() << "Frame: " << frame; 
} 

的計時器開始在一個被稱爲上的按鍵插槽:

void PlayerSprite::move(Direction direction) 
{ 
    timeLine->start(); 
} 

輸出結果爲:

GameView: Player is moving 
Frame: 2 
Frame: 3 
Frame: 4 
GameView: Player is moving 
Frame: 1 
Frame: 2 
Frame: 3 
Frame: 4 

但它應該是:

GameView: Player is moving 
Frame: 1 
Frame: 2 
Frame: 3 
Frame: 4 
GameView: Player is moving 
Frame: 1 
Frame: 2 
Frame: 3 
Frame: 4 

在每個幀期間玩家例如移動2個步驟。因此應該移動4x2 = 8步......但在第一幀時它只移動6步,這意味着我的角色脫離了遊戲網格。我正在做一個小的16位RPG;)

這是因爲假設我的播放器已經在它的第一幀? 如果是這樣可以重寫?

回答

1

這似乎是一個已知的錯誤:

https://bugreports.qt.io/browse/QTBUG-41610

最簡單的工作,圍繞你的情況是時間線的當前時間設置爲時間上的創作:

timeLine = new QTimeLine(500); 
timeLine->setFrameRange(1, 4); 
timeLine->setCurveShape(QTimeLine::CurveShape::LinearCurve); 
// Add this line: 
timeLine->setCurrentTime(timeLine->duration()); 
+0

我想知道爲什麼會這樣。對我沒有多大意義。非常感謝您的輕鬆解決方法。對於未來,你是如何跟蹤這一點的?谷歌根本沒有幫助。 – ovg

+0

我確切的Google搜索詞是「qt bug qtimeline」。 –

+0

哦,好的。我應該嘗試下一次這樣簡單的事情;) – ovg