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?