[Help] Smooth movement SFML 2.1

Hi, i'm trying to move a sf::RectangleShape :

1
2
3
4
5
6
7
8
9
10
  if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) 
	{
		m_Rectangle.move(15 * -1, 0);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) 
	{
		m_Rectangle.move(15, 0);
	}
	
	Sleep(10);


but it's very jerky.
Plus when I press a Key there is a little latency.

Can you help me pls :)
What is m_Rectangle?
Last edited on
It's a sf::RectangleShape
Why are you calling "Sleep()"? This might be your problem.
Thanks for your answer but I tried with and without with some different values but I've always the same problem.
Then check to see what event you are triggering this check on. Or better yet post your entire running loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
while (window.isOpen())
	{
	
		sf::Event event;
		while (window.pollEvent(event))
		{
			
			if (event.type == sf::Event::Closed)
				window.close();

			window.clear();
			mapManager.drawAll(window);


			mapManager.updateAll();
			
			
			window.display();

		}
	}



mapManager is an object which stocks my objects into a std::map<std::string, Obj*>
It's use to update all my Obj with updateAll()

1
2
for (std::map<std::string, Blocks*>::const_iterator i = m_VecMap.begin(); i != m_VecMap.end(); ++i)
		i->second->update();


One of my Obj is a Rectangle that I try to move with the first code I posted


You definately don't want that call to Sleep, maybe you want to set window.setFramerateLimit()?

Are you setting the velocity back to zero when the key is released?
Topic archived. No new replies allowed.