2014-12-04 552 views
2

我在精靈中有紋理,我想讓背景看不見(白色)。如何在SFML中將顏色設置爲alpha(移除顏色)?

sf::Texture texBohatera; 
texBohatera.loadFromFile("bohater.png"); 

sf::Sprite bohater; 
bohater.setTexture(texBohatera); 
+0

無法計算。需要更多數據。 – 2014-12-04 22:48:20

+0

@RafaelBaptista我有一個白色背景顏色的PNG文件,我想在沒有白色背景顏色的SFML中顯示此圖像(僅限於我的播放器圖像) – Saibamen 2014-12-04 23:15:27

回答

4

像這樣的東西應該工作。

sf::Image image; 
image.LoadFromFile("bohater.png"); 
image.CreateMaskFromColor(sf::Color::White); 

sf::Texture texBohatera; 
texBohatera.LoadFromImage(image); 

sf::Sprite bohater; 
bohater.SetTexture(texture); 

(聲明,我沒有測試它,因爲我不想安裝SFML)

1

你可以

window.clear(sf::Color::White);

或找到一個方案,允許您繪製pisk文件,如piskel。

您可以導入文件並擦除要透明的區域。 或繪製自己的精靈。