So my problem is that I am trying to position a sprite in the middle of the screen. How to do that is very simple but the calculations made during runtime are wrong. I have come to the conclusion that it is about floating points being messy in Java.
So, this is the code I have right now, which works:
float posX = ((1280f / 2f) - 128f);
float posY = ((720f / 2f) - 112.5f);
splash.setScale(1.5f);
splash.setPosition((posX), (posY));
But if I replace the divisions above with these variables:
private float screenCenterW = (1280.0f / 2f);
private float screenCenterH = (720.0f / 2f);
private float splashCenterW = (225.0f / 2f);
private float splashCenterH = (256.0f / 2f);
Things does not seem to work anymore. It seems to me that the first part of the posX and posY calculations result in a 0.0 and my sprite ends up in the upper left corner, half-visible.
Why is it that if I replace the different calculations with these variables, it stops working?
EDIT:
So to clarify:
This is how I want the code to look like:
private float screenCenterW = (1280.0f / 2f);
private float screenCenterH = (720.0f / 2f);
private float splashCenterW = (225.0f / 2f);
private float splashCenterH = (256.0f / 2f);
float posX = (screenCenterW - splashCenterW);
float posY = (screenCenterH - splashCenterH);
splash.setScale(1.5f);
splash.setPosition((posX), (posY));
This, however, makes something go wrong. Even though, to me, they look exactly the same as the other calculation. Am I making a rookie mistake somewhere? I have been constructing this calculation from the bottom to the top with just numbers, and it works, but as soon as I substitute one of the calculations with a variable (saving it in a variable) it stops working, and the sprite goes off the screen, as if the screenCenterW and screenCenterH is calculated to 0.0 through the division of 2f. Example of screenWidthH: (1280f / 2f) = 0 | 0 - 112.5f = -112.5f
Why I have issues debuging this is because I don't know how to show these calculations on the screen in the AndEngine for Android that I am using. I sincerely apologise for not being detailed and I realise now that the question didn't say much at the start, but I hope this clarifies what I'm asking about. And if somebody out there that use AndEngine could help me that would be amazing.