Why is sfml slowing down my computer tremendously?
I'm using sfml and when I run a simple application it uses tremendous amount of resources.
Is this because it has no limit to the amount of resources it takes and I need to give it a limit?
I just definitely notice it is taking up a great deal of resources.
I'm very new as I started using it yesterday.
maybe you're leaking memory somewhere. Can you post the code for the program you're running?
I doubt it... It's a simple program.
EDIT: I'm running this on a linux box btw.
This code is also something I made independently to be used in my pong game. Obviously just to see how the ball would/could work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <SFML/Graphics.hpp>
#include <iostream>
int dir;
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Ball Test 2");
sf::Vector2f xx(1.f, 1.f);
sf::Shape Ball = sf::Shape::Circle(xx, 5.f, sf::Color::Blue);
sf::Vector2f xy(400.f,300.f);
Ball.SetPosition(xy);
while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if (ev1.Type == sf::Event::Closed)
App.Close();
if(dir == 0 && int(Ball.GetPosition().y) == 595)
dir = 1;
if(dir == 0 && int(Ball.GetPosition().x) == 5)
dir = 3;
if(dir == 1 && int(Ball.GetPosition().y) == 5)
dir = 0;
if(dir == 1 && int(Ball.GetPosition().x) == 5)
dir = 2;
if(dir == 2 && int(Ball.GetPosition().y) == 5)
dir = 3;
if(dir == 2 && int(Ball.GetPosition().x) == 795)
dir = 1;
if(dir == 3 && int(Ball.GetPosition().y) == 595)
dir = 2;
if (dir == 3 && int(Ball.GetPosition().x) == 795)
dir = 0;
if( dir == 0 && Ball.GetPosition().x > 0 && Ball.GetPosition().y < 600)
Ball.Move(-.05f, .05f);
if(dir == 1 && Ball.GetPosition().x > 0 && Ball.GetPosition().y > 0)
Ball.Move(-.05f, -.05f);
if(dir == 2 && Ball.GetPosition().x < 800 && Ball.GetPosition().y > 0)
Ball.Move(.05f, -.05f);
if(dir == 3 && Ball.GetPosition().x < 800 && Ball.GetPosition().y < 600)
Ball.Move(.05f, .05f);
App.Clear();
App.Draw(Ball);
App.Display();
}
return EXIT_SUCCESS;
}
|
Last edited on
You're not limiting your frame rate anywhere, so it's going as fast as it can.
On my machine, this runs at more than 1500 fps (with 9% CPU usage).
Topic archived. No new replies allowed.