SFML community forums
Help => General => Topic started by: Fuv on June 04, 2010, 02:01:40 pm
-
I have such code:
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow App(VideoMode(800, 600, 32), "Game", Style::Fullscreen);
sf::Image IMGBackground, IMGLudzik;
if(!IMGBackground.LoadFromFile("back.jpg"))
return 1;
if(!IMGLudzik.LoadFromFile("lud.png"))
return 1;
Sprite Background(IMGBackground);
Sprite Ludzik(IMGLudzik);
Background.SetPosition(0.f, 0.f);
Background.Resize(800, 600);
Ludzik.SetPosition(200.f, 100.f);
Ludzik.SetScale(1.f, 1.f);
Event evt;
while(App.IsOpened())
{
while(App.GetEvent(evt))
{
if(evt.Type == Event::Closed)
App.Close();
if(evt.Type == Event::KeyPressed && evt.Key.Code == Key::Escape)
App.Close();
}
float time = App.GetFrameTime();
if(App.GetInput().IsKeyDown(Key::Down))
Ludzik.Move(0, 100 * time);
if(App.GetInput().IsKeyDown(Key::Left))
Ludzik.Move(-100 * time, 0);
App.Clear();
App.Draw(Background);
App.Draw(Ludzik);
App.Display();
}
}
But its working really slow and not fluently. I read that I should use class or something as it was said in this tutorial:
http://sfml-dev.org/tutorials/1.6/graphics-sprite.php
about sprite management, but I dont know how to use it in practice. Might somebody tell me how to change the code?
Kind Regards
Fuv
-
What is "slow"? How many frames per second (use FRAPS, or display 1/App.GetFrameTime())?
-
The result is: 4,57.
-
What processor, OS and graphics card do you have?
-
Intel Core 2 Quad Q6600 @2.40GHz
Windows XP x32
NVIDIA GeForce 8800 GTS
In my opinion it's not my hardware's fault, but code that it is not efficient.
Kind Regards
Fuv
-
Your code cannot be more efficient, it does almost nothing.
Are your drivers up-to-date?
-
It isn't the code's fault, nothing at all!!
-
While your app is running, something else i.e. some app or sevice that is running simultaneously such as virus scanner or alike might be eating the CPU's clocks. It seems that nothing else could slow the PC with such a configuration unless it has not enough RAM. BTW you did not mention what build you are running release or debug.
-
i have the same problem, and its not problem of hardware and software. When i comment a line:
App.Draw(Background);
all is right. so something wrong is with background?
it's jpg 800 x 600
-
Is it necessary to redraw background every loop? It s quite heavy image and takes some time to draw it on the screen.
Kind Regards
Fuv
-
Yes it is necessary, but no it isn't "heavy". Compare 800x600 pixels to the fillrate of current (or even older) GPUs. If you can't draw one 800x600 sprite at 60 FPS, then there's something wrong and you probably won't be able to display any decent graphics.