Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML custom shape, problem with fill vertex  (Read 3734 times)

0 Members and 1 Guest are viewing this topic.

William_Hazem

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML custom shape, problem with fill vertex
« on: May 27, 2021, 10:29:59 pm »
I'm Trynig to make a Arrow Class that extends the sf::Shape, but when i draw the shape this happen:



Outline are correct, but when i set the fill color, it's fill outside the area.


unsigned int Arrow::getPointCount() const {
    return 5;
}

sf::Vector2f Arrow::getPoint(unsigned int index) const {
    float x = origin.x;
    float y = origin.y;

    if(index == 0)
        return {x, y - tickness/2};
    else if(index == 1)
        return {x + length, y - tickness/2};
    else if(index == 2)
        return {x + length, y - tickness/2 - 30.f};
    else if(index == 3)
        return {x + length + 30.f, y};
    return {x , y};
   
   
}
 
« Last Edit: June 01, 2021, 08:33:00 am by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SFML custom shape, problem with fill vertex
« Reply #1 on: June 01, 2021, 08:35:32 am »
Shape can only handle Convex shapes, an arrow is concave, thus you get a wrong shape.

You can either manually do it with a vertex array, or you can use Thor's Concave Shape
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

William_Hazem

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML custom shape, problem with fill vertex
« Reply #2 on: June 19, 2021, 12:38:39 am »
Thanks!

 

anything