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

Author Topic: [solved] SFML 2.0 - Shape.move stretches the shape Oo  (Read 2525 times)

0 Members and 1 Guest are viewing this topic.

SargTeX

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
[solved] SFML 2.0 - Shape.move stretches the shape Oo
« 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...
}
« Last Edit: June 20, 2012, 02:18:59 am by SargTeX »

SargTeX

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: SFML 2.0 - Shape.move stretches the shape Oo
« Reply #1 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);

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: [solved] SFML 2.0 - Shape.move stretches the shape Oo
« Reply #2 on: June 20, 2012, 12:18:01 pm »
Hello,

You can use
app.clear();
which is more "SFML" than glClear.

SargTeX

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: [solved] SFML 2.0 - Shape.move stretches the shape Oo
« Reply #3 on: June 20, 2012, 12:29:53 pm »
Thanks :)

 

anything