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

Author Topic: Smooth movement.  (Read 7101 times)

0 Members and 2 Guests are viewing this topic.

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Smooth movement.
« on: October 01, 2013, 08:15:54 am »
I see a lot of this topics and still doesn't work for me:
    sf::RenderWindow window(sf::VideoMode(640, 480), "My window");
        window.setFramerateLimit(60);
       
        sf::Texture tex;
        tex.loadFromFile("bomberman.png");
        sf::Sprite sprite;
        sprite.setTexture( tex );      

        auto move = 100.f;
        auto dt   = 0.f;
        sf::Clock clock;
    while (window.isOpen()){        
        sf::Event event;
        while (window.pollEvent(event)){    
            if (event.type == sf::Event::Closed)
                window.close();
        }  
        sprite.move( move * dt, 0 );

        window.clear();        
        window.draw( sprite );
        window.display();

        auto& pos = sprite.getPosition();
        if((pos.x > 640) || (pos.x < 0)) move = -move;

        dt = clock.restart().asSeconds();                    
    }
 

The sprite speed up randomly (small but perceptible jumps).
I read about here
http://gafferongames.com/game-physics/fix-your-timestep/ and here http://gamedev.tutsplus.com/tutorials/implementation/how-to-create-a-custom-2d-physics-engine-the-core-engine/.
Implemented the timestepping and the interpolation rendering.
Implemented everything on sdl2.
Tried also on different computers.
And run the sfml examples.
All have the same problem.
And in all cases, without frame limit or vsync (or with framelimit >=75 (+-) ) all runs smooth.
At 60fps or less the problem continues.

Thank you for the patience!

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Smooth movement.
« Reply #1 on: October 01, 2013, 12:53:14 pm »
Floats are inaccurate when so low.
Try following:
auto move = 100.f / 1000;
dt = clock.restart().asMiliseconds();
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth movement.
« Reply #2 on: October 02, 2013, 03:50:34 am »
Same problem.
Only render more than 60fps make it look smooth.
If I update the movement at 30fps and render at eg. 100fps, its looks ok. Which is the reverse of what I read o.O

Izman

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Smooth movement.
« Reply #3 on: October 02, 2013, 10:00:20 am »
Same problem.
Only render more than 60fps make it look smooth.
If I update the movement at 30fps and render at eg. 100fps, its looks ok. Which is the reverse of what I read o.O

No, that should be correct, assuming you're using frame interpolation.

I've found that, especially at a strictly 2D level, there's a big notice in quality from 30fps to 60fps.

For example, http://boallen.com/fps-compare.html

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth movement.
« Reply #4 on: October 02, 2013, 10:28:08 am »
hm, right, thanks ^^
But the problem is really that small jumps that occurs when render at 60 fps.
It get better at 75, and are almost gone at 100fps (and vanish with more).
The delta time is very stable so i was unable to detect where this jumps come from.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Smooth movement.
« Reply #5 on: October 02, 2013, 01:36:13 pm »
The issue is obviously with float type for position & how is drawing done.

Do following.
Add two floats.
Code: [Select]
float posX, posY;
Then for movement update posX,posY with coordinates.
Code: [Select]
posX += (move * dt);
posY += 0;
Before drawing, update sprite position from the posX, posY
Code: [Select]
sprite.setPosition(static_cast<int>(posX), static_cast<int>(posY);

Tada! smooth movement
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth movement.
« Reply #6 on: October 02, 2013, 10:08:10 pm »
Unfortunately doesn't work. ;(
I also have the same code on SDL and there it uses your solution since SDL_Rect positions are ints, but it shows the same problem.
Thank you anyway ^^
Im starting to think that my eyes see more frames that it should ;)

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Smooth movement.
« Reply #7 on: October 02, 2013, 10:48:18 pm »
Unfortunately doesn't work. ;(
I also have the same code on SDL and there it uses your solution since SDL_Rect positions are ints, but it shows the same problem.
Thank you anyway ^^
Im starting to think that my eyes see more frames that it should ;)
Pass me exe file, i need/want to see that.

I used your code, just made the adjustments i suggested and it was fine, perfect movement.
« Last Edit: October 02, 2013, 10:50:49 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth movement.
« Reply #8 on: October 02, 2013, 11:12:52 pm »
Yes, i was thinking that may be my pc, but i tested on another and see the same..
https://dl.dropboxusercontent.com/u/8711710/base_testing.rar
2 images, 2 .exe (with and without frame limit for comparison), and source. no dlls.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Smooth movement.
« Reply #9 on: October 03, 2013, 01:32:13 pm »
I do not notice the issue, somehow turning Vsync on makes it look even smoother.
« Last Edit: October 03, 2013, 02:15:48 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

thisdyingsoul

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth movement.
« Reply #10 on: October 03, 2013, 11:30:58 pm »
Ok, seems that me and my brother have better frame perception o.O
I send to some friends and they also didn't see the problem.
This is awkward. Thank you anyway ^^

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: Smooth movement.
« Reply #11 on: October 07, 2013, 09:33:08 pm »
eXpl0it3r
Don't mix real-time inputs and event handling.
Read the linked tutorials (again), especially pay attention to when you should use what and where you should use what. :)

Read true tutorials, you will figure you why the movement is jaggy.
Its pretty highlighted in certain parts you wont miss it!
« Last Edit: October 07, 2013, 09:35:23 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

 

anything