So I animated a sprite sheet for a game I'm making, but for some reason It's lagging my game a lot.
The sprite sheet is a 1248x120 .png file, each sprite is 156x120 pixels in size.
Code I'm using to animate:
void Entity::AnimateHorizontal(sf::Texture tex, int width, int hight)
{
sprite.setTextureRect(sf::IntRect(source.x * width, 0, width, hight));
frameCounter += frameSpeed * frameTimer.restart().asSeconds();
if (frameCounter >= switchFrame)
{
frameCounter = 0;
source.x++;
if (source.x * width >= tex.getSize().x) source.x = 0;
}
}
And:
Object.AnimateHorizontal(tex_Mech1Feet,156,120);
In my game loop.
FPS just loading the sheet, no animation: Click me!
FPS with animating the sheet: Click me!
Also note that this is currently the only thing I'm actually doing in my game, so it definitely shouldn't be lagging this bad.
I'm still a complete novice when it comes to programming with C++, so please bear with me.
That being said, I appreciate any and all advice, thanks in advance!