Hello
I'm trying to make this:
draw(convexshape with 4 points)
getBounds
getPosition
draw(rectangle) //frame arround convex sahpe
If convexshape's first coordinate is different from "0" then getPosition returns (pos - firstCoord).
is it normal behaviour ?
rect.setPosition(shape.getPosition());
[/code]
#include <SFML/Graphics.hpp>
int main ()
{
sf::ConvexShape shape(4);
shape.setFillColor(sf::Color::Red);
sf::RectangleShape rect;
rect.setFillColor(sf::Color::Green);
shape.setPoint(0, sf::Vector2f(40,50));
//shape.setPoint(0, sf::Vector2f(0,0));
shape.setPoint(1, sf::Vector2f(140,60));
shape.setPoint(2, sf::Vector2f(150,250));
shape.setPoint(3, sf::Vector2f(30,240));
shape.setPosition(200, 200);
rect.setSize(sf::Vector2f(shape.getGlobalBounds().width, shape.getGlobalBounds().height));
rect.setPosition(shape.getPosition());
sf::RenderWindow window(sf::VideoMode(800, 600), "ConvexShape");
sf::Event event;
while (window.isOpen()) {
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
window.close();
break;
}
}
window.clear();
window.draw(rect);
window.draw(shape);
window.display();
}
}
I think this way is right ... :-\
rect.setPosition(
sf::Vector2f(
shape.getGlobalBounds().left,
shape.getGlobalBounds().top
// shape.getPosition().x + shape.getLocalBounds().left,
// shape.getPosition().y + shape.getLocalBounds().top
)
);