我有这个单一的c ++ / SFML代码......
#include <SFML/Graphics.hpp>
#define windowWidth 600
#define windowHeight 300
int main()
{
sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Views");
sf::View view(sf::FloatRect(0,0, windowWidth, windowHeight));
view.zoom(2);
window.setView(view);
sf::RectangleShape back (sf::Vector2f(windowWidth, windowHeight));
back.setFillColor(sf::Color::White);
sf::RectangleShape rect (sf::Vector2f(200, 100));
rect.setFillColor(sf::Color::Red);
rect.setPosition(windowWidth - rect.getSize().x, windowHeight - rect.getSize().y); // position in the lower right corner
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(back);
window.draw(rect);
window.display();
}
return 0;
}
...可能会将红色矩形定位在窗口的右下角。
但是,当我缩放视图时(如在代码中),它显然会像整个窗口一样移动this image。 我有些疑惑:
答案 0 :(得分:1)
有没有更简单的方法将这个矩形放在全局窗口的右下角?
从SFML 2D camera tutorial:&#34;要使用视图绘制内容,必须在调用要绘制的目标的setView函数后绘制它&#34;
所以绘图部分应该是
window.clear();
window.setView(view);
window.draw(back);
window.setView(window.getDefaultView()); //don't zoom red rect
window.draw(rect);
window.display();
如何在同一窗口中拥有多个活动视图?
只需为每个活动视图调用setView()
,然后在该视图中绘制所有内容(如果需要,再次)
window.setView(leftHalfView);
window.draw(a);
window.draw(b);
window.draw(c);
window.setView(rightHalfView);
window.draw(a);
window.draw(b);
window.draw(c);
window.setView(minimap);
window.draw(a);
window.draw(b);
window.setView(window.getDefaultView());
window.draw(x);
window.draw(y);