I am having a problem with drawing entities at positive coordinates. The 0,0 coordinate draws correctly, but as the x and y setPosition/setOrigin/etc values increase the entity moves up and to the left. I have to enter negative values for it to show up in the window.
Also, setOrigin is acting like setPosition and not centering the circle in the window, instead it is offset like the top left "corner" of the circle is in the middle of the window.
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>
int main()
{
sf::RenderWindow window;
window.create(sf::VideoMode(300,300),"!!!");
sf::CircleShape circle(30);
circle.setOrigin(-150,-150); //This has to be negative to show up at (150,150)
window.clear(sf::Color(100,100,100));
window.draw(circle);
window.display();
std::cin.get();
}
Thanks
Setting the origin moves the origin within the local bounds and setting the position changes the global position of the shape so that its origin is at that position. If the shape is not rotated or scaled, the origin works as a negative position.
It seems as if you want to position the circle using its centre?
First, set the origin so that it is no longer in its top-left corner but in its centre:
circle.setOrigin({ circle.getRadius(), circle.getRadius() });
Then, you can place that centre of the circle where you want it to be. For example, the centre of the window:
circle.setPosition(sf::Vector2f(window.getSize() / 2u));
That places your circle in the centre of the window.
IMPORTANT NOTE: in your code, your window becomes immediately unresponsive and your operating system will be unhappy that it isn't dealing with the events that it is sending to it.
Remember the main loop as shown in the tutorials, including the getting started ones.