#include "gamelib/sprite/SpriteData.hpp"
#include <cmath>

namespace gamelib
{
    AnimationData::AnimationData() :
        length(1),
        speed(0),
        offset(0)
    { }

    void AnimationData::update(float fps)
    {
        offset = std::fmod(offset + speed / fps, length);
    }

    sf::IntRect AnimationData::getRect(int texw, int texh) const
    {
        int x = rect.left + (int)offset * rect.width;
        return sf::IntRect(x % texw, (rect.top + x / texw * rect.height) % texh, rect.width, rect.height);
    }
}

#include "gamelib/sprite/SpriteData.hpp"
#include <cmath>

namespace gamelib
{
    AnimationData::AnimationData() :
        length(1),
        speed(0),
        offset(0)
    { }

    void AnimationData::update(float fps)
    {
        if (length > 1 && speed != 0)
            offset = std::fmod(offset + speed / fps, length);
    }

    sf::IntRect AnimationData::getRect(int texw, int texh) const
    {
        int x = rect.left + (int)offset * rect.width;
        return sf::IntRect(x % texw, (rect.top + x / texw * rect.height) % texh, rect.width, rect.height);
    }
}

Fix bug causing a wrong frame index
Fix bug causing a wrong frame index

Using this formula to calculate the image index
    offset = std::fmod(offset + speed / fps, length),
a length of 1 or speed = 0 and an offset > 0 would result in a wrong
index.
