有谁知道如何用c ++中的sfml绘制矢量?

时间:2014-06-11 02:33:05

标签: c++ draw sfml

非常确定window.draw(vectorname)

之类的东西

所需行为:绘制一个矩形矢量,具体来说,是3个白色矩形,2个空格,另一个矩形和一个空格

错误 :(我认为)我没有正确地绘制

代码

window.draw(L0[i]) //the name of the vector is L0

"相关代码"

#include <iostream>
#include <SFML/Graphics.hpp>
#include <vector>

using namespace std;
using namespace sf;
int main()
{
//plan how to draw
int x;
vector<RectangleShape> L0; //0 0001101

for (int i=0; i<7; i++) //for which digit were on in L0
{
    x=0;
    if(i==1 or 2 or 3 or 6) //when to print white
    {
        x=x+8;
        RectangleShape white((120,50));
        RectangleShape white(Vector2f(120,50));
        white.setSize(Vector2f(8, 300)); //w and h
        white.setFillColor(Color(255,255,255));
        white.setPosition(x,50)
        L0[i].push_back(white);
    }
    else //when to print a space
    {
        x=x+8;
    }
}
RenderWindow window(VideoMode(800,600), "SFML Saves!")
while (window.pollEvent((event))
{
while (window.pollEvent(event))
{
    if (event.type==Event::Closed)
        window.close();
}
window.clear();
window.draw(L0[i]);
window.display();
}

return 0;
}

1 个答案:

答案 0 :(得分:4)

除了评论中指出的错误代码之外,你可以简单地迭代一个向量并绘制东西。

<强> C ++ 11

window.clear();
for(const auto& rectangle_shape : L0)
    window.draw(rectangle_shape);
window.display();