Skip to content

Commit

Permalink
Fix nested tag with "Ping-Pong" repeat mode causes to skip the first …
Browse files Browse the repository at this point in the history
…frame of the parent tag (fix aseprite#4271)
  • Loading branch information
Gasparoken committed Apr 3, 2024
1 parent 571a396 commit 0805df7
Show file tree
Hide file tree
Showing 2 changed files with 533 additions and 6 deletions.
79 changes: 74 additions & 5 deletions src/doc/playback.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (C) 2021-2022 Igara Studio S.A.
// Copyright (C) 2021-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -473,10 +473,79 @@ bool Playback::decrementRepeat(const frame_t frameDelta)
stop();
return false;
}
if (newFrame < 0)
newFrame = m_sprite->lastFrame();
else if (newFrame > m_sprite->lastFrame())
newFrame = 0;
if (newFrame < 0) {
if (!m_playing.empty() &&
m_playing.back()->tag->fromFrame() == 0) {
if (m_playing.back()->tag->aniDir() == AniDir::PING_PONG_REVERSE) {
if (m_playing.back()->repeat > 1) {
--m_playing.back()->repeat;
m_playing.back()->invertForward();
newFrame = tag->toFrame() + 1;
}
else
newFrame = m_playing.back()->tag->toFrame();
}
else if (m_playing.back()->tag->aniDir() == AniDir::PING_PONG) {
if (m_playing.back()->repeat > 1)
newFrame = tag->toFrame() + 1;
else {
m_frame = 0;
m_playing.back()->invertForward();
m_playing.back()->repeat = m_playing.back()->tag->repeat();
handleEnterFrame(frameDelta, true);
if (m_playing.size() > 1) {
goToFirstTagFrame(m_playing.back()->tag);
}
newFrame = m_frame;
}
}
else
newFrame = m_sprite->lastFrame();
}
else
newFrame = m_sprite->lastFrame();
}
else if (newFrame > m_sprite->lastFrame()) {
if (!m_playing.empty()) {
const bool isPP = m_playing.back()->tag->aniDir() == AniDir::PING_PONG ||
m_playing.back()->tag->aniDir() == AniDir::PING_PONG_REVERSE;
if (tag->toFrame() == m_playing.back()->tag->toFrame()) {
if (m_playing.back()->repeat == 1)
continue;
else if (m_playing.back()->repeat > 1 && isPP) {
if (m_playing.back()->tag->aniDir() == AniDir::PING_PONG)
--m_playing.back()->repeat;
m_playing.back()->invertForward();
newFrame = tag->fromFrame() - 1;
}
else if (m_playing.back()->tag->aniDir() == AniDir::FORWARD &&
m_playing.back()->repeat > 1) {
--m_playing.back()->repeat;
newFrame = m_playing.back()->tag->fromFrame();
}
else
newFrame = 0;
}
else
newFrame = 0;
}
else {
if ((tag->aniDir() == AniDir::PING_PONG_REVERSE ||
tag->aniDir() == AniDir::REVERSE) &&
tag->toFrame() == m_sprite->lastFrame() &&
tag->fromFrame() == 0) {
m_frame = m_sprite->lastFrame();
handleEnterFrame(frameDelta, true);
if (m_playing.size() > 1) {
m_playing.back()->invertForward();
goToFirstTagFrame(m_playing.back()->tag);
}
newFrame = m_frame;
}
else
newFrame = 0;
}
}
}

m_frame = newFrame;
Expand Down
Loading

0 comments on commit 0805df7

Please sign in to comment.