SFML community forums

Help => General => Topic started by: mark973 on January 15, 2013, 04:34:52 am

Title: What is wrong with this code?
Post by: mark973 on January 15, 2013, 04:34:52 am
Hi, Im new here on sfml forums and right now im trying to make a simple pong game in sfml 1.6.
When I get to making the shape of the second paddle, when I compile, it doesn't show up right. Like I put the exact parameters but it shows up in a different place.
Here's the code I have so far:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow Window (sf::VideoMode(640, 480, 32), "Pong");
    sf::Shape paddle1 = sf::Shape::Rectangle(0, 100, 10, 10, sf::Color(255, 0, 0));
    sf::Shape paddle2 = sf::Shape::Rectangle(0, 0, 10, 10, sf::Color(255,0,0)); // I put the parameters 0, 0 in here but the rectangle shows up in a different spot on the screen
    sf::Shape ball = sf::Shape::Circle(320, 240, 10, sf::Color(255,0,0));

    while(Window.IsOpened())
    {
        sf::Event Event;
        while(Window.GetEvent(Event))
        {
            if(Event.Type == sf::Event::Closed)
                Window.Close();
        }

        if(Window.GetInput().IsKeyDown(sf::Key::Down))
            paddle1.Move(0.0, 2.0);
        if(Window.GetInput().IsKeyDown(sf::Key::Up))
            paddle1.Move(0.0, -2.0);

        Window.Clear(sf::Color(255,255,255));
        Window.Draw(paddle1);
        Window.Draw(paddle2);
        Window.Draw(ball);
        Window.Display();
        sf::Sleep(0.06);
    }
}
Title: Re: What is wrong with this code?
Post by: cire on January 15, 2013, 04:50:59 am
1.6 Shape::Rectangle Documentation (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Shape.php#a9b1796e22c45bb59918867d37a76a0f4)

Note what the third and fourth parameter are.

Title: What is wrong with this code?
Post by: eXpl0it3r on January 15, 2013, 05:24:14 am
Also keep in mind that SFML 1.6 is 2.5 years old, has many bugs and lacks quite a few features. So in mostly all cases it's better to use SFML 2. ;)
Title: Re: What is wrong with this code?
Post by: mark973 on January 15, 2013, 09:05:48 pm
I still don't know what I'm doing wrong. Is my code wrong or something. Am I just not putting in the parameters in right?
Title: Re: What is wrong with this code?
Post by: mark973 on January 15, 2013, 09:14:49 pm
Wait never mind, I think I figured it out. I was doing it the way I would have in SDL. I didn't realize that SFML has a different system of making rectangles lol.