Hey.
I got a strange error.
I am using RectangleShape::move(10, 0) in an inherited class and it stretches the rectangle Oo. The start position X seems to stay the same, only the width seems to increase.
The method "beforeDraw()" is called before the texture is drawn in the window. The code is very small and simple, so I don't see where my error is...
Any suggestions? :/
Greetings,
SargTeX
class Jake : public sf::RectangleShape {
private:
sf::Vector2f targetPosition;
float speed;
public:
Jake(sf::Vector2f size):RectangleShape(size),targetPosition(0, 0),speed(0.5) {
setFillColor(sf::Color::Red);
setPosition(10, 100);
targetPosition = getPosition();
}
//Setter...
void beforeDraw() {
//the target position was changed of course
if (targetPosition != getPosition()) {
if (targetPosition.x > getPosition().x) {
move(speed, 0); //this seems to stretch the shape/change the width, not to change its x
cout << "move!" << endl; //this makes the correct output
}
}
}
};
int gameMain() {
sf::RenderWindow app(sf::VideoMode(800, 600), "Adventure Time!", sf::Style::Default);
//SFML & OpenGL Settings...
Jake jake(sf::Vector2f(20, 20));
//draw frames
while (running) {
//event polling aso...
//draw
jake.beforeDraw();
app.draw(jake, sf::RenderStates::Default);
//display
app.display();
}
//Shutdown everything...
}