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

Author Topic: How to move a line smoothly?  (Read 2239 times)

0 Members and 1 Guest are viewing this topic.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
How to move a line smoothly?
« on: May 19, 2011, 04:47:46 pm »
Hello everyone,

I want to move a line from left to right and it must look like a smooth movement.
Unfortuantely I didnt get this working so far, the movement seems not to be smooth, especially, when I maximize the screen.
I looks like sometimes the line jumps a bit and sometimes it seems to flicker and so, it just doesen't look good.

Here is the code which I used:
Code: [Select]
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   //both with and without verticalsync it doesent look good.
App.UseVerticalSync(true);
sf::Shape line(sf::Shape::Line(0,0,200,200,2,sf::Color::Green));
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear();

line.Move(App.GetFrameTime() * 50, 0);
if(line.GetPosition().x > App.GetWidth())
{
line.SetPosition(0, line.GetPosition().y);
}

App.Draw(line);
App.Display();
}

return EXIT_SUCCESS;
}


Would be nice if you have any suggestions to improve this.

Edit: I Just tested it on other pcs and there it just runs fine, so its probably a problem with the graphics driver or my hardware is too old (which I dont think).
I'm using a GForce 6200 Graphics card at this pc, which is indeed not very new, but I think it should be good enough to display some lines :-)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6288
  • Thor Developer
    • View Profile
    • Bromeon
How to move a line smoothly?
« Reply #1 on: May 19, 2011, 11:05:06 pm »
There are two ways to move objects:
  • Smooth when they move parts of pixels. However, this may look blurry or distorted in some situations.
  • Pixel-perfect, only take on integral coordinates and avoid rotations or scales (with few exceptions). This can look rough, especially for low resolutions.
You can also increase the anti-aliasing value of your window (third parameter of the sf::RenderWindow constructor).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: