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

Author Topic: SFML 2.0 - Movement lag issue  (Read 3826 times)

0 Members and 1 Guest are viewing this topic.

AltF4ToWin

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
SFML 2.0 - Movement lag issue
« on: May 10, 2013, 08:51:17 pm »
I'm fairly new to SFML 2.0, used SFML 1.6 for a while so not completely new to SFML.

Basically, since 2.0 was released I figured I'd rewrite the game I'm working on to use SFML 2.0. The process went smoother than I thought it would do, but I've hit a snag. It's not exactly a big error, but the movement in all directions is fairly jittery, even with VSync/framelimits.

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
//#include "projectile.h"
#include <iostream>

int main()
{
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Asteroids");
   sf::Texture Ship;
   sf::Texture Space;
   if(!Ship.loadFromFile("ship.png"))
           return EXIT_FAILURE;
   if(!Space.loadFromFile("space-1.png"))
           return EXIT_FAILURE;

   sf::Sprite Ship_s;
   Ship_s.setTexture(Ship);
   sf::Sprite Space_s(Space);
   Ship_s.setPosition(200.f, 100.f);
   Ship_s.setScale(1.f, 1.f);

   sf::Clock clock;
   App.setFramerateLimit(120);
   //App.setVerticalSyncEnabled(true);
   while (App.isOpen())
   {
      sf::Time dt=clock.restart();
      sf::Event Event;
      while (App.pollEvent(Event))
      {
         if (Event.type == sf::Event::Closed)
            App.close();
      }

     
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))  
              Ship_s.move(-1 * 100 *dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
              Ship_s.move( 1 * 50 * dt.asSeconds(), 0);
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))    
              Ship_s.move( 0,-1 * 50 * dt.asSeconds());
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))  
              Ship_s.move( 0, 1 * 50 * dt.asSeconds());

      App.clear();
      App.draw(Space_s);
      App.draw(Ship_s);
      App.display();
   }
   return EXIT_SUCCESS;
}

 

If needed, I can post a video of what it looks like. Currently running this on the latest version of Fedora 18 x86_64 on an Acer Aspire 7730. Is there anything I can do to reduce the lag?
« Last Edit: May 10, 2013, 09:12:23 pm by AltF4ToWin »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML 2.0 - Movement lag issue
« Reply #1 on: May 10, 2013, 11:23:16 pm »
Your code looks allright, its weird that you get jitter. Update graphics card drivers and so on.. I don't see what could it be..

AltF4ToWin

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: SFML 2.0 - Movement lag issue
« Reply #2 on: May 10, 2013, 11:24:22 pm »
Nothing to update, crappy onboard. If the code seems fine, I guess I'll just have to live with it. Thanks anyway.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML 2.0 - Movement lag issue
« Reply #3 on: May 11, 2013, 12:43:32 am »
Yeah... It really should work better.. :/ try to limit the Frame rate to 30 or something. That could get more performance..

AltF4ToWin

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: SFML 2.0 - Movement lag issue
« Reply #4 on: May 12, 2013, 04:44:27 pm »
I've limited from 10-120 to no avail sadly.

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: SFML 2.0 - Movement lag issue
« Reply #5 on: May 13, 2013, 08:58:53 pm »
In my experience with SFML, on board laptop graphics have poor implementations (drivers?) of OpenGL. I always had lagging/jittering/performance problems on those compared to a desktop with a dedicated card.

AltF4ToWin

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: SFML 2.0 - Movement lag issue
« Reply #6 on: May 13, 2013, 11:17:36 pm »
Same really, I just figured it was the code before my system. It manages to full whole games perfectly fine, I can get 50-60fps on most CS games.