Hello,
My colleague and I ran into an issue with views.
The following method
void GameWindow::redrawMap(const int width, const int height, const bool recreateMap)
{
sf::View view, view2;
sf::RectangleShape rect;
int altColor = 0;
int posX = 0, posY = 0;
int caseWidth = 32, caseHeight = 32;
int sidePanelWidth = 200;
sf::Sprite sidepanelImage;
sidepanelImage.setTexture(sidePanel);
screenWidth = caseWidth * 20 + sidePanelWidth;
screenHeight = caseHeight * 20;
if (recreateMap)
renderWindow.create(sf::VideoMode(screenWidth, screenHeight), "UI", sf::Style::Titlebar | sf::Style::Close);
renderWindow.clear(sf::Color(139, 115, 85));
rect.setSize(sf::Vector2f(caseWidth, caseHeight));
rect.setOutlineColor(sf::Color::Yellow);
rect.setOutlineThickness(1);
sidepanelImage.setPosition(screenWidth - sidePanelWidth, 0);
rect.setPosition(posX, posY);
view.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
view.zoom(curZoom);
renderWindow.setView(view);
while (posY <= caseHeight * height)
{
while (posX < caseWidth * width)
{
renderWindow.draw(rect);
rect.setPosition(posX, posY);
posX += caseWidth;
rect.setFillColor(sf::Color(0, 123, 12));
altColor++;
}
posX = 0;
posY += caseHeight;
}
view2.reset(sf::FloatRect(0, 0, screenWidth, screenHeight));
view2.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
renderWindow.setView(view2);
renderWindow.draw(sidepanelImage);
renderWindow.display();
}
Allow us to redraw the content of the window each time we want to zoom in or zoom out on this view by modifying the curZoom variable before entering this method.
The problem is that we have to redraw the whole content of the window each time we want to modify the view.
Our window look like this:
The green squares are all we want to zoom into.
The problem we are facing is that because the views are passed by copy into our renderWindow we can not find a way to access it later or to keep a reference on it. So we are just redrawing the squares as well as the other view on the right ( the grey "box").
If there was a way to do it in a "cleaner" way or any help idea or solution on that problem would be greatly appreciated.
Thanks