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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Idea

Pages: [1]
1
Graphics / How to create a Rect, the same size/location as a Shape
« on: January 24, 2012, 12:19:55 am »
Hello, I'm trying to create a rect, that is the same size as a shape and I've been having trouble.
Here's my code.
Code: [Select]


int main()
{
    //declare variables
    bool Falling;
    Falling = true;
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
    const sf::Input& Input = App.GetInput();

    // Load a sprite to display
    sf::Shape Player = sf::Shape::Rectangle(50,50,100,100,sf::Color::White);
    Player.SetPosition(200,200);
    sf::Shape CollisionTest = sf::Shape::Rectangle(50,50,150,150,sf::Color::Cyan);
    CollisionTest.SetPosition(200,400);

    // Start the game loop
    while (App.IsOpened())
    {
        //timer
        float Time = Clock.GetElapsedTime();
        Clock.Reset();

        //Rectangles for Collision Detection
        sf::IntRect ghostRect;
        ghostRect.Left = Player.GetPosition().x;
        ghostRect.Top = Player.GetPosition().y;
        ghostRect.Right = Player.GetScale().x;
        ghostRect.Bottom = Player.GetScale().y;

        sf::IntRect TestRect;
        TestRect.Left = CollisionTest.GetPosition().x;
        TestRect.Top = CollisionTest.GetPosition().y;
        TestRect.Right = CollisionTest.GetScale().x;
        TestRect.Bottom = CollisionTest.GetScale().y;



        //Handles various If statements such as falling,input, and collision

        if(Falling == true)
        {
            Player.Move(0,100*Time);
        }

        if(App.GetInput().IsKeyDown(sf::Key::A))
        {
            Player.Move(-100 * Time,0);
        }
        if(App.GetInput().IsKeyDown(sf::Key::D))
        {
            Player.Move(100 * Time,0);
        }
        if(App.GetInput().IsKeyDown(sf::Key::Left))
        {
            Player.Move(-100 * Time,0);
        }
        if(App.GetInput().IsKeyDown(sf::Key::Right))
        {
            Player.Move(100 * Time,0);
        }
        if(ghostRect.Intersects(TestRect))
        {
            break;
        }
}

Some code has been taken out because it has nothing to do with the Rectangle problem.

2
Graphics / The Last Three Points of my shape will not Change Colour
« on: January 08, 2012, 02:34:56 pm »
Quote from: "Tex Killer"
In C++, which I assume you are using, ifs with more than 1 line inside must have brackets, like this:

Code: [Select]
           if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1)) {
                Player.SetPointColor(0,sf::Color::Blue);
                Player.SetPointColor(1,sf::Color::Blue);
                Player.SetPointColor(2,sf::Color::Blue);
                Player.SetPointColor(3,sf::Color::Blue);
            }

The way you did it, only the first line after each if is conditional, all the others happens every time.


Thanks, the tutorials didn't really make that clear.

3
Graphics / The Last Three Points of my shape will not Change Colour
« on: January 08, 2012, 01:33:30 am »
Hello, I am new to SFML, so please excuse any questions that have obvious answers. The problem is that only the first point of the shape changes colour while the rest simply sticks to the last colour (which in this case is green) declared in the code.

Here's my code
Code: [Select]

while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num1))
                Player.SetPointColor(0,sf::Color::Blue);
                Player.SetPointColor(1,sf::Color::Blue);
                Player.SetPointColor(2,sf::Color::Blue);
                Player.SetPointColor(3,sf::Color::Blue);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R))
                Player.SetPointColor(0,sf::Color::White);
                Player.SetPointColor(1,sf::Color::White);
                Player.SetPointColor(2,sf::Color::White);
                Player.SetPointColor(3,sf::Color::White);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num2))
                Player.SetPointColor(0,sf::Color::Red);
                Player.SetPointColor(1,sf::Color::Red);
                Player.SetPointColor(2,sf::Color::Red);
                Player.SetPointColor(3,sf::Color::Red);

            if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Num3))
                Player.SetPointColor(0,sf::Color::Green);
                Player.SetPointColor(1,sf::Color::Green);
                Player.SetPointColor(2,sf::Color::Green);
                Player.SetPointColor(3,sf::Color::Green);
        }

Pages: [1]