2017-02-19 47 views
0

我使用SFML库和Visual-C++创建条形图。我想设置条形图的起点,所以我尝试使用move和setOrigin函数,但它不能成功。如何设置条形图的起点

sf::RectangleShape rec1(sf::Vector2f(stage1x*1000, stage1y*1000)); 
sf::RectangleShape rec2(sf::Vector2f(stage2x*1000, stage2y*1000)); 
sf::RectangleShape rec3(sf::Vector2f(stage3x*1000, stage3y*1000)); 

rec1.setOrigin(0, 0); 
rec2.setOrigin(0, 0); 
rec3.setOrigin(0, 0); 

rec1.move(200, 700); // This moves the Rectangle over 200 pixels and down 700 pixels 
rec2.move(300, 700); // This moves the Rectangle over 300 pixels and down 700 pixels 
rec3.move(400, 700); // This moves the Rectangle over 400 pixels and down 700 pixels 

rec1.setFillColor(sf::Color(100, 250, 50)); 
rec2.setFillColor(sf::Color(10, 20, 100)); 
rec3.setFillColor(sf::Color(500, 600, 700)); 

This is a picture of my bar chart

回答

1

的这种不同的方法很多。例如,您可以将窗口的高度sf::View设置为负值,这将实质上将所有内容垂直翻转(坐标从下到上)。

setOrigin()在SFML的可绘图上将只移动它们的本地原点,即确定哪个点与setPosition()̀中给出的位置对齐。默认情况下,原点设置为(0, 0),所以您的代码不会更改任何内容。

而不是使用move(),我直接打电话setPosition()(这是设置绝对位置,而不是相对的)。如果您想让酒吧向上走,请按上述方法翻转视图,或者简单地从酒吧的Y位置减去酒吧的高度。

相关问题