我正在尝试制作一个需要处理显示在另一个视图之上的视图的项目。我也想这样做,以便该视图不显示任何内容时它是透明的。尝试执行此操作时,不会绘制我的叠加视图。我已经阅读了本教程,并浏览了一些受欢迎的论坛网站,但找不到任何有用的信息。请帮助。
这是我尝试执行此操作的一些示例代码
int main() {
sf::RenderWindow mainWindow;
mainWindow.create(sf::VideoMode(800, 900, 300), "SFML Works", sf::Style::Close);
sf::View projectsVeiw;
sf::RectangleShape projectsBox;
projectsBox = sf::RectangleShape(sf::Vector2f(400, 225));
projectsBox.setOrigin(sf::Vector2f(-10, -130));
projectsBox.setOutlineColor(sf::Color::Black);
projectsBox.setOutlineThickness(10);
projectsBox.setFillColor(sf::Color::Transparent);
projectsVeiw.setViewport(projectsBox.getGlobalBounds());
sf::RectangleShape randomBox;
randomBox = sf::RectangleShape(sf::Vector2f(100, 100));
randomBox.setOrigin(sf::Vector2f(-50, -50));
randomBox.setOutlineColor(sf::Color::Black);
randomBox.setOutlineThickness(10);
randomBox.setFillColor(sf::Color::Yellow);
while (mainWindow.isOpen()) {
mainWindow.clear(sf::Color::White);
mainWindow.draw(projectsBox);
mainWindow.setView(projectsVeiw);
mainWindow.draw(randomBox);
mainWindow.setView(mainWindow.getDefaultView());
mainWindow.display();
}
}
您应先绘制视图,然后再绘制到mainWindow。因为循环,您实际上是通过默认视图绘制projectsBox并通过projectsView绘制randomBox。
while (mainWindow.isOpen()) {
mainWindow.clear(sf::Color::White);
mainWindow.setView(projectsVeiw);
mainWindow.draw(projectsBox);
mainWindow.setView(mainWindow.getDefaultView());
mainWindow.draw(randomBox);
mainWindow.display();
}
}
当前配置的视图会影响在窗口中绘制事物的方式。视图不是单独的画布。