Hello, I just started using SFML not too long ago and I decided to try to make a checker game project. I'm also new to C++ as well (figured I should mention that as a disclaimer...).
This post is about an issue I have with resizing the window and the checkerboard not updating. The attatched screenshot ("Window_Resize_Test_1.png") shows how the checkerboard doesn't scale with the size of the window, but the checkerpieces do! In my code, I use a main game loop that does the event handling and a window.clear(), "draw stuff", and then window.display() cycle like in the tutorials. The checkerboard in the screenshot is made using the Shape class.
void Checkerboard :: drawGrid(sf::RenderWindow& window, int mouseOverX, int mouseOverY)
{
int xOffset = 0, yOffset = 0;
for(int i = 0; i < SQUARES_VERTICAL; ++i)
{
for(int j = 0; j < SQUARES_HORIZONTAL; ++j)
{
if((j % 2 == 0 && i % 2 == 0) || (j % 2 != 0 && i % 2 != 0)) // find the white squares
squareArray[i][j]->setFillColor(sf::Color::White);
else
squareArray[i][j]->setFillColor(sf::Color::Black);
squareArray[i][j]->setPosition(xOffset, yOffset); // set the position for drawing
squareArray[i][j]->setSize(sf::Vector2f(window.getSize().x / SQUARES_HORIZONTAL, window.getSize().y / SQUARES_VERTICAL));
window.draw(*squareArray[i][j]);
xOffset += window.getSize().x / SQUARES_HORIZONTAL;
}
yOffset += window.getSize().y / SQUARES_VERTICAL;
xOffset = 0;
}
}
It was my hope that passing the window reference in the draw cycle of the main game loop would keep the checkerboard size updated. What really confuses me is that the checkerpieces scale perfectly with the window, so I think I'm just overlooking something altogether (I can post the checkerpiece draw function but its functionally the same as drawGrid). I Googled the issue and saw this guy had a similiar issue
http://chrisheydrick.com/2013/06/04/problems-re-sizing-sfml-renderwindow/. Needless to say I tried it and it didn't work out. Lastly, I should mention that I can initialize the window to any reasonable size when the RenderWindow object is constructed in the main function and the checkerboard looks fine. The issue is only when I resize the window.