SFML community forums

Help => Graphics => Topic started by: SargTeX on June 20, 2012, 01:13:21 am

Title: [solved] SFML 2.0 - Shape.move stretches the shape Oo
Post by: SargTeX on June 20, 2012, 01:13:21 am
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...
}
Title: Re: SFML 2.0 - Shape.move stretches the shape Oo
Post by: SargTeX on June 20, 2012, 02:18:43 am
Screw it, I forgot to clear the window.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Title: Re: [solved] SFML 2.0 - Shape.move stretches the shape Oo
Post by: victorlevasseur on June 20, 2012, 12:18:01 pm
Hello,

You can use
app.clear();
which is more "SFML" than glClear.
Title: Re: [solved] SFML 2.0 - Shape.move stretches the shape Oo
Post by: SargTeX on June 20, 2012, 12:29:53 pm
Thanks :)