Hello guys
what do you think of my animation? it works perfectly, but i though maybe someone has some comments on the code. is there a better way to code it. any advice you can give me is much appreciated.
[Added]
ok i have discovered something where if you use this code with a lot of images, the frame rate drops from 60fps to 10fps and the gpu usage go to 70-90%.
and i have a 5970 graphic card with two gpus !!
any idea how to solve this problem?
[Added last (New)]
very very weird problem. if i add this line of code the frame drop from 60FPS to 7FPS !!!!!
std::cout<< clock.GetElapsedTime()<< "\n"; //DROP FRAME RATE
feel free to use this code in your project.
#include <SFML\Graphics.hpp>
#include <iostream>
int main()
{
sf::Image image1, image2, image3, image4, image5;
sf::Sprite sprite1;
image1.LoadFromFile("water1.png");
image2.LoadFromFile("water2.png");
image3.LoadFromFile("water3.png");
image4.LoadFromFile("water4.png");
image5.LoadFromFile("water5.png");
sprite1.SetImage(image1);
sprite1.SetPosition(200,200);
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "sftool::animation sample");
sf::Clock clock;
while (window.IsOpened())
{
sf::Event Event;
window.SetFramerateLimit(60);
while (window.GetEvent(Event))
{
}
float time1 = clock.GetElapsedTime();
float time2 = clock.GetElapsedTime();
float time3 = clock.GetElapsedTime();
float time4 = clock.GetElapsedTime();
float time5 = clock.GetElapsedTime();
std::cout<<time1 << "\n";
// Draw everything.
window.Clear();
window.Draw(sprite1);
if(time1 >= 0.2)
{
sprite1.SetImage(image2);
window.Draw(sprite1);
}
if(time2 >= 0.6)
{
sprite1.SetImage(image3);
window.Draw(sprite1);
}
if(time3 >= 1.0)
{
sprite1.SetImage(image4);
window.Draw(sprite1);
}
if(time4 >= 1.4)
{
sprite1.SetImage(image5);
window.Draw(sprite1);
clock.Reset();
}
window.Display();
}
return EXIT_SUCCESS;
}
[/code]