2017-02-19 108 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位置減去酒吧的高度。

相關問題