Without the subrect function, it simply shows the whole spritesheet, no flickering of black thing. The flickering only happens when its animated(using subrect).
Heres my whole program code:
#include <SFML/Graphics.hpp>
int main()
{
sf::VideoMode vmode(800,600,32);
sf::RenderWindow Window(vmode, "Animation Training");
sf::Texture texture;
texture.LoadFromFile("Walker.png");
sf::Sprite sprite;
sprite.SetTexture(texture);
int frame = 0;
int frame2 = 0;
sf::Clock clock;
while(Window.IsOpened())
{
sf::Event Event;
while(Window.PollEvent(Event))
{
if(Event.Type == sf::Event::Closed || sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
{
Window.Close();
}
}
Window.Clear(sf::Color::Cyan);
if(clock.GetElapsedTime() >= 100)
{
sprite.SetSubRect(sf::IntRect(frame * 68,frame2,68,68));
++frame;
if(frame > 5)
{
frame = 0;
++frame2;
}
if(frame2 > 5)
{
frame2 = 0;
}
clock.Reset();
}
Window.Draw(sprite);
Window.Display();
}
return 0;
}
Oh yes and btw the whole sprite sheet is 340 by 340(in pixels). And theres 5 columns and 5 rows of images(frames) in the sprite sheet. And frame2 is for when the subrect "moves" to the next row so i increment it by 1 when frame is greater then five and then when frame2 reaches the last frame in the last row and frame also reaches the last image in the last row, they both reset to 0 which restarts the animation process.