Hello guys,
I'm making drawing program as my school project and i have little trouble with it. I have several shapes which you can draw like triangles, rectangles,... , and I want to include user's own shapes.
void Shapes::getShape(int mousePositionXShapes, int mousePositionYShapes //gets mouse position from another function)
{
sf::VertexArray userShape(sf::TrianglesStrip, arrayLength);
if (clickRelease)
{
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
userShape[n].position = sf::Vector2f(mousePositionXShapes, mousePositionYShapes);
userShape[n].color = sf::Color::Yellow;
if (n != 0)
{
int positionX = userShape[n - 1].position.x;
int currentPositionX = userShape[n].position.x;
cout << "previous position: " << positionX << endl;
cout << "current position: " << currentPositionX << endl;
}
clickRelease = false;
}
}
else if (!sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
if (!clickRelease)
{
clickRelease = true;
arrayLength++;
n++;
}
}
window.clear(sf::Color::White);
window.draw(userShape);
window.display();
//drawShape(userShape);
}
This part of code should let user choose his own points by clicking. If he will click 3 points it will form into triangle and each next point will add next triangle. It's basically this:
https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php -> Primitive Types -> sf::TriangleStrip.
Problem comes when I start the program. First click will define position for first vertex but if i click again for another vertex position, previous vertex will be removed.
Console output looks like this:
previous position: 0
current position: 683
previous position: 0
current position: 1021
previous position: 0
current position: 451
previous position: 0
current position: 527
Why is this happening ?