sfml 在 defaultVeiw 之上放置一个 sf::View
sfml put a sf::View on top of the defaultVeiw
我正在尝试创建一个项目,该项目需要操作显示在另一个视图之上的视图。我还想让它在该视图不显示任何内容的地方是透明的。尝试这样做时,它不会绘制我的叠加视图。我已经通读了教程并浏览了一些流行的论坛网站,但找不到任何有用的东西。请帮忙
这是我如何尝试执行此操作的一些示例代码
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();
}
}
您应该在绘制到主窗口之前设置您的视图。由于循环,您实际上是通过默认视图绘制 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();
}
}
当前配置的视图会影响 window 中事物的绘制方式(缩放、平移等)。视图不是单独的 canvas。您需要使用普通视图绘制主 window,然后在设置新的覆盖视图后在世界其他地方绘制覆盖 window,以便它在屏幕上的正确位置。
什么都不画就是透明的
我正在尝试创建一个项目,该项目需要操作显示在另一个视图之上的视图。我还想让它在该视图不显示任何内容的地方是透明的。尝试这样做时,它不会绘制我的叠加视图。我已经通读了教程并浏览了一些流行的论坛网站,但找不到任何有用的东西。请帮忙
这是我如何尝试执行此操作的一些示例代码
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();
}
}
您应该在绘制到主窗口之前设置您的视图。由于循环,您实际上是通过默认视图绘制 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();
}
}
当前配置的视图会影响 window 中事物的绘制方式(缩放、平移等)。视图不是单独的 canvas。您需要使用普通视图绘制主 window,然后在设置新的覆盖视图后在世界其他地方绘制覆盖 window,以便它在屏幕上的正确位置。
什么都不画就是透明的