SFML community forums

Help => Graphics => Topic started by: lorence30 on June 01, 2015, 07:00:33 pm

Title: sfml background lagging
Post by: lorence30 on June 01, 2015, 07:00:33 pm
I already tried everything, update my driver to the latest, running under release mode but still when theres background in my game its lagging my game.

any solutions?


Title: Re: sfml background lagging
Post by: DarkRoku12 on June 01, 2015, 07:24:34 pm
If you dont post details of what you call "lagging" few we can do bro,
Title: Re: sfml background lagging
Post by: lorence30 on June 01, 2015, 07:29:58 pm
@DarkRoku

its slowing down my game, like the fps is getting low
Title: Re: sfml background lagging
Post by: G. on June 01, 2015, 07:38:41 pm
Bored people could try to guess for a while (ie: "load the texture only once, not every frame") or you could provide us with more information: source code and clear description of the problem (how much is "low"?).
Title: Re: sfml background lagging
Post by: Hapax on June 02, 2015, 01:58:43 am
We don't even know what your background is - a single image, tilemap, vector art, solid colour...

I already tried everything
I feel it necessary that I should point out that your statement is factually inaccurate.
Title: Re: sfml background lagging
Post by: lorence30 on June 02, 2015, 10:11:35 am
Heres my game background see the picture below,

heres the code:

int main()
{
     sf::RenderWindow window(sf::VideoMode(500,500),"SFML TEST");
     
    sf::Texture texture;
texture.loadFromFile("images.png");

sf::Sprite sprite(texture;

while(window.isOpen())
{

//events
     sprite.move(-1,0);
    window.clear();
   window.draw(sprite);
   window.display();
}

}
Title: Re: sfml background lagging
Post by: Hapax on June 03, 2015, 01:15:21 am
Please use code tags i.e. [code=cpp] (code goes here) [/code]

In your code, the sprite you are displaying is moving one pixel to the left each frame/cycle. What problems are you having?

Note that frame times are inconsistent so it would be better to move by an amount multiplied by the amount of time passed.
Add before the main loop:
const float scrollSpeed = 100.f; // pixels per second
sf::Clock clock;

Then, change the move(-1, 0) to:
const float frameTime = clock.restart().asSeconds();
move(-scrollSpeed * frameTime, 0);

Then, let us know if that fixes the problem or you are still having troubles and let us know what those problems are.