I have the following code:
this->position.y = (window->getSize().y - (GRID_HEIGHT * TILE_SIZE)) / 2;
When window->getSize().y - (GRID_HEIGHT * TILE_SIZE) < 0, it overflows.
this->position.y = -60 / 2; // reaches correct answer of -30
this->position.y = (window->getSize().y - (GRID_HEIGHT * TILE_SIZE)); // reaches correct answer of -60
this->position.y = (window->getSize().y - (GRID_HEIGHT * TILE_SIZE)) / 2; // overflows
Either I'm missing something crazy obvious, or there's something weird going on here. How can line 1 work fine, but line 3 overflows when it's essentially the same equation?
If I replace all values with their actual values it works fine:
this->position.y = (window->getSize().y - (GRID_HEIGHT * TILE_SIZE)) / 2; // overflow. result is 2147483618
this->position.y = (1080 - (19 * 60)) / 2; // exact same values as the above line, just hard-coded, and results in -15
Any help would be greatly appretiated, I'm very confused right now!