Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Slow moving of sprite with background  (Read 5389 times)

0 Members and 1 Guest are viewing this topic.

Fuv

  • Newbie
  • *
  • Posts: 35
    • View Profile
Slow moving of sprite with background
« on: June 04, 2010, 02:01:40 pm »
I have such code:

Code: [Select]
#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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Slow moving of sprite with background
« Reply #1 on: June 04, 2010, 02:19:24 pm »
What is "slow"? How many frames per second (use FRAPS, or display 1/App.GetFrameTime())?
Laurent Gomila - SFML developer

Fuv

  • Newbie
  • *
  • Posts: 35
    • View Profile
Slow moving of sprite with background
« Reply #2 on: June 04, 2010, 05:04:45 pm »
The result is: 4,57.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Slow moving of sprite with background
« Reply #3 on: June 04, 2010, 07:46:34 pm »
What processor, OS and graphics card do you have?
Laurent Gomila - SFML developer

Fuv

  • Newbie
  • *
  • Posts: 35
    • View Profile
Slow moving of sprite with background
« Reply #4 on: June 05, 2010, 10:07:04 am »
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Slow moving of sprite with background
« Reply #5 on: June 05, 2010, 12:01:41 pm »
Your code cannot be more efficient, it does almost nothing.

Are your drivers up-to-date?
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Slow moving of sprite with background
« Reply #6 on: June 06, 2010, 11:26:45 pm »
It isn't the code's fault, nothing at all!!

dunce

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Slow moving of sprite with background
« Reply #7 on: June 08, 2010, 05:54:36 pm »
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.

djmentos

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • http://www.krolnet.pl/
Slow moving of sprite with background
« Reply #8 on: June 08, 2010, 06:39:14 pm »
i have the same problem, and its not problem of hardware and software. When i comment a line:
Code: [Select]
App.Draw(Background);
all is right. so something wrong is with background?

it's jpg 800 x 600

Fuv

  • Newbie
  • *
  • Posts: 35
    • View Profile
Slow moving of sprite with background
« Reply #9 on: June 08, 2010, 07:14:33 pm »
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Slow moving of sprite with background
« Reply #10 on: June 08, 2010, 08:21:49 pm »
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.
Laurent Gomila - SFML developer