Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PingPong style in Animate2D #354

Open
Moros1138 opened this issue Nov 16, 2023 · 1 comment
Open

Implement PingPong style in Animate2D #354

Moros1138 opened this issue Nov 16, 2023 · 1 comment

Comments

@Moros1138
Copy link
Collaborator

I took a stab at implementing PingPong, this is the way that seems to make sense to me, might be able to be expressed better.

        case Style::PingPong:
        {
            // calculate time period with time frames of 2 complete sequences
            float pingPongTime =
                fmod(fTime * m_fFrameRate, m_vFrames.size() * 2);

            // calculate the current frame index
            size_t index = (size_t(pingPongTime) % m_vFrames.size());

            // if we're on the second sequence, run in reverse
            if(pingPongTime > m_vFrames.size())
                return (m_vFrames.size() - 1) - index;

            // if we made it here, we're handing the first sequence, run forward
            return index;
        }
        break;

case Style::PingPong:

@Moros1138
Copy link
Collaborator Author

Not even 5 minutes later this occurred to me... no conditionals in our code

        case Style::PingPong:
        {
            float pingPongTime =
                std::abs(std::fmod(fTime * m_fFrameRate, m_vFrames.size() * 2) -
                         m_vFrames.size());

            return (size_t(pingPongTime) % m_vFrames.size());
        }
        break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant