Same thing applies with some of the other tutorials.
But not with your specific problem.
There are examples of event loops everywhere (tutorials, documentation, SDK examples, forum posts, wiki), and none of them makes the same mistake as you. So I'm 100% sure that you can figure out what's wrong in your code by looking at these examples. And in case you don't, your mistake is explicitely mentioned in the events tutorial.
sf::Event instances are filled by the pollEvent (or waitEvent) function of the sf::Window class. Only these two functions can produce valid events, any attempt to use a sf::Event without first a successful call to pollEvent (or waitEvent) will result in the same undefined behaviour that I mentioned above.
To be clear, here is what a typical event loop looks like:
sf::Event event;
// while there are pending events...
while (window.pollEvent(event))
{
// check the type of the event...
switch (event.type)
{
// window closed
case sf::Event::Closed:
window.close();
break;
// key pressed
case sf::Event::KeyPressed:
...
break;
// we don't process other types of events
default:
break;
}
}
[/code
I thought it was inside?
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(2200, 1300), "SFML window");
window.clear(sf::Color(128,128,128));
sf::RectangleShape shape(sf::Vector2f(50,50));
shape.setFillColor(sf::Color(255,0,0));
shape.setPosition(100,650);
window.draw(shape);
window.display();
// Start the game loop
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window : exit
if (event.type == sf::Event::Closed)
{
window.close();
}
if((sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
&& (sf::Event::MouseMoved))
{
shape.setPosition(sf::Event::MouseMoveEvent().x,sf::Event::MouseMoveEvent().y);
window.clear(sf::Color(128,128,128));
window.draw(shape);
window.display();
}
}
}
return EXIT_SUCCESS;
}
if((sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
&& (sf::Event::MouseMoved))
{
shape.setPosition(sf::Event::MouseMoveEvent().x,sf::Event::MouseMoveEvent().y);
window.clear(sf::Color(128,128,128));
window.draw(shape);
window.display();
}
It doesn't look like what's in the tutorial, not even remotely. In this small part of code, your way to check the type of the event is wrong, and your way to get the positions of the mouse is also wrong. And you don't want to put your clear/draw/display inside the event loop (if you want to know what a basic game loop is supposed to look like, read and understand the first part of the graphics tutorial (http://www.sfml-dev.org/tutorials/2.0/graphics-draw.php#the-drawing-window)).
Why didn't you take a look at the link I gave (http://www.sfml-dev.org/tutorials/2.0/window-events.php#the-mousemoved-event)? It directly points to what you have to do to get mouse coordinates, and there's only 3 lines of code so it's easy even for copypasters.
Seriously, why does your code look like nothing you can find in the tutorial? Why don't you read them after everyone told you to? There isn't a tutorial where you can find "sf::Event::MouseMoveEvent().x".