Eventually you convinced me on switching to SFML 2
After the conversion the Task Manager shows a CPU load around 35%.
Since I was testing a simple movement system of an array of objects, I'm wondering if there's a bottle-neck somewhere that I haven't noticed.
Minimal code below.
main.cpp
int main()
{
sf::Uint32 ElapsedTime;
sf::RenderWindow App(sf::VideoMode(800, 480, 32), "SFML 2 Engine");
App.SetFramerateLimit(60);
App.EnableVerticalSync(true);
sf::Texture background_texture;
if (!background_texture.LoadFromFile("background.png")) return EXIT_FAILURE;
sf::Sprite background_sprite(background_texture);
background_sprite.SetPosition(0, 0);
while (App.IsOpened())
{
sf::Event event;
while (App.PollEvent(event))
{
if (event.Type == sf::Event::Closed) App.Close();
}
ElapsedTime = App.GetFrameTime();
ElapsedTime /= 10;
App.Clear();
App.Draw(background_sprite);
for(int i = 0; i < 8; i++) { targets[i].move_sprite(ElapsedTime, App); }
App.Display();
}
return EXIT_SUCCESS;
}
target.h
class Target {
private:
sf::Sprite sprite;
public:
Target(float x, float y);
void move_sprite(sf::Uint32 t, sf::RenderWindow &App);
};
Target::Target(float x, float y) {
static sf::Texture tex;
tex.LoadFromFile("target_1.png");
sprite.SetTexture(tex);
sprite.SetOrigin(0, 44);
sprite.SetPosition(x, y);
}
void Target::move_sprite(sf::Uint32 t, sf::RenderWindow &App) {
sprite.Move(3.f*t, 0);
if (sprite.GetPosition().x > 850) { sprite.SetPosition(-800, 240); }
App.Draw(sprite);
}
// create targets
Target Target_1( 0.f, 240.f );
Target Target_2( 60.f, 240.f );
Target Target_3( 120.f, 240.f );
Target Target_4( 180.f, 240.f );
Target Target_5( 240.f, 240.f );
Target Target_6( 300.f, 240.f );
Target Target_7( 360.f, 240.f );
Target Target_8( 420.f, 240.f );
Target targets[] = { Target_1, Target_2, Target_3, Target_4, Target_5, Target_6, Target_7, Target_8 };
There's something wrong that I'm doing which could be the cause of the unjustified cpu consumption?
Also, deleting the GetFrameTime() control doesn't affect the cpu consumption, but improves the smoothness of the movement (every tot frames I can observe some lag in the movement).
Thank you in advance guy, I would really appreciate any help.