I create the render window in a state (I use state manager) in this way:
renderWindow.create(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Xenon", sf::Style::Fullscreen);
where the two macros are 1280 and 800.
in another state(objects are shared among states well, I'm sure), when I create a object that is supposed to be in the center of the screen, it is shifted to the right.
Specifically I have a spaceship class that has 4 "different" spaceship possible. The difference, other than their stats (fire rate, acceleration and so on.. that I will not report since they are not influent), are of course the dimensions of the sprite, that I use to subtract it to the half of the screen dimensions (both in width and height) to move its top left corner and put the spaceship's center in the center of the window.
Three of the spaceships are centred well, one is shifted in the right (correct y-position, x-position shifted to the right side of the screen).
this is how I manage the positioning, I will cut the stats attribution since are irrelevant:
xPos=((float)WINDOW_WIDTH - sprite.getLocalBounds().width)/2;
yPos=((float)WINDOW_HEIGHT - sprite.getLocalBounds().height)/2;
std::cout << xPos << ", " << yPos << std::endl;
sprite.setPosition(xPos, yPos);
std::cout << "position is" << sprite.getPosition().x << ", " << sprite.getPosition().y << std::endl;
sprite.setOrigin(sprite.getLocalBounds().width/2,sprite.getLocalBounds().height/2);
I use the same code for all the 4 spaceships, in facts the constructor use a switch case for the texture selection and appropriate stats attribution, than it has a shared part (out of the switch case) with this portion of code.
What's the problem? I added the first cout to see what value is assigned to xPos and yPos but it always print the value it should have, and it is the same printed to the second cout, every time i run the program, for all the spaceships.
EDIT: now I changed a minor thing in the program, the entities life is considered as boolean and not as int and now randomly 2 spaceship are in the correct position and 2 are shifted (once i experienced a shift on the left)...