diff options
Diffstat (limited to 'src/quick/items/qquickanimatedsprite.cpp')
-rw-r--r-- | src/quick/items/qquickanimatedsprite.cpp | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp index 3aaec53c54..e816975827 100644 --- a/src/quick/items/qquickanimatedsprite.cpp +++ b/src/quick/items/qquickanimatedsprite.cpp @@ -388,8 +388,8 @@ void QQuickAnimatedSprite::advance(int frames) //TODO-C: May not work when running - only when paused m_curFrame += frames; while (m_curFrame < 0) - m_curFrame += m_sprite->frames(); - m_curFrame = m_curFrame % m_sprite->frames(); + m_curFrame += m_spriteEngine->maxFrames(); + m_curFrame = m_curFrame % m_spriteEngine->maxFrames(); emit currentFrameChanged(m_curFrame); } @@ -574,35 +574,41 @@ void QQuickAnimatedSprite::prepareNextFrame() int timeInt = m_timestamp.elapsed() + m_pauseOffset; qreal time = timeInt / 1000.; - double frameAt; //double just for modf + int frameAt; qreal progress = 0.0; int lastFrame = m_curFrame; if (m_running && !m_paused) { + const int nColumns = int(m_sheetSize.width()) / m_spriteEngine->spriteWidth(); //Advance State (keeps time for psuedostates) m_spriteEngine->updateSprites(timeInt); //Advance AnimatedSprite qreal animT = m_spriteEngine->spriteStart()/1000.0; - qreal frameCount = m_spriteEngine->spriteFrames(); - qreal frameDuration = m_spriteEngine->spriteDuration()/frameCount; + const int frameCountInRow = m_spriteEngine->spriteFrames(); + const qreal frameDuration = m_spriteEngine->spriteDuration()/frameCountInRow; if (frameDuration > 0) { qreal frame = (time - animT)/(frameDuration / 1000.0); bool lastLoop = m_loops > 0 && m_curLoop == m_loops-1; //don't visually interpolate for the last frame of the last loop - qreal max = lastLoop ? frameCount - qreal(1.0) : frameCount; - frame = qBound(qreal(0.0), frame, max); - progress = modf(frame,&frameAt); - if (m_curFrame > frameAt) //went around + const int max = lastLoop ? frameCountInRow - 1 : frameCountInRow; + frame = qBound(qreal(0.0), frame, qreal(max)); + double intpart; + progress = modf(frame,&intpart); + frameAt = (int)intpart; + const int rowIndex = m_spriteEngine->spriteY()/frameHeight(); + const int newFrame = rowIndex * nColumns + frameAt; + if (m_curFrame > newFrame) //went around m_curLoop++; - m_curFrame = frameAt; + m_curFrame = newFrame; } else { m_curFrame++; - if (m_curFrame >= frameCount){ + if (m_curFrame >= m_spriteEngine->maxFrames()) { // maxFrames: total number of frames including all rows m_curFrame = 0; m_curLoop++; - m_spriteEngine->advance(); } - frameAt = m_curFrame; + frameAt = m_curFrame % nColumns; + if (frameAt == 0) + m_spriteEngine->advance(); progress = 0; } if (m_loops > 0 && m_curLoop >= m_loops) { |