如何在SFML中为线条着色?

时间:2017-02-14 14:01:34

标签: c++ colors sfml

这是我在sfml中的代码,我正在尝试为该行上色,但由于某种原因,它一直给我错误。我能得到建议吗?

sf::VertexArray lines(sf::Lines, line.size()-1);

for (int i = 0; i < line.size()-1; i++) 
{
    lines[i].position.x = c[i].x;
    lines[i].position.y = c[i].y;
}
window.draw(Lines);

1 个答案:

答案 0 :(得分:1)

您应该在顶点数组中设置顶点的成员color。例如:

sf::VertexArray lines(sf::Lines, line.size()-1);

for (int i = 0; i < line.size()-1; i++) 
{
    lines[i].position.x = c[i].x;
    lines[i].position.y = c[i].y;
    lines[i].color = sf::Color::Green;
}
window.draw(lines);

有关详细信息,请参阅this link