Hi,
I'm currently working on SFML 2.0 project where you control a rectangle that is moving around on a playing field.
The problem I'm having right now is that the movement is very stuttery and inconsistent.
I'll try to copy in some code so you can see what I've done.
This is from my game class, I've taken away the non essential parts.
void Game::GameLoop()
{
sf::Event currentEvent;
while(_mainWindow.pollEvent(currentEvent))
{
switch(_gameState)
{
case Game::Playing:
{
player.Update(_mainWindow, currentEvent);
break;
}
}
}
}
This is in my player class:
void Player::Update(sf::RenderWindow& mW, sf::Event Event)
{
_Event = Event;
Move(mW);
}
void Player::Move(sf::RenderWindow& mW)
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
_sprite.move(-5, 0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
_sprite.move(5,0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
_sprite.move(0, -5);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
_sprite.move(0, 5);
}
So I've figured out what some of the problems are, when using isKeyPressed there is a natural short"pause" right after I press the key and then it goes smooth. Is there anyway I can get rid of this ?
And also while holding down 2 keys, up and left for example, it seems like it going alot faster, like it's calling the Update twice and therefor calling the Move twice and therefor updating the position twice as fast.
This is my first time using SFML and I havn't been using C++ for that long either, I started coding in C# and XNA.
Anyways, any help and/or input is appreciated!
BR,
Fredrik