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 - kubala

Pages: [1]
1
Graphics / Re: Problem with object location
« on: April 11, 2012, 05:23:40 pm »
Thank you for help   :).

2
Graphics / Problem with object location
« on: April 11, 2012, 04:32:37 pm »
Hi.

The circle(ball) in my programme should be in center of the window, but it's not. I noticed, that rectangle don't go how it should(it goes too far in down). What's wrong?
#include<SFML/Graphics.hpp>
#include<cstdio>
int main()
{
    sf::RenderWindow Window(sf::VideoMode(800,600,32), "Pong"/*, sf::Style::Close*/ );
    sf::Event Event;
    Window.SetFramerateLimit(60);

    sf::Image Image(50,200,sf::Color::White);
    sf::Sprite Sprite(Image);
    Sprite.SetCenter(Image.GetWidth()/2.0f, Image.GetHeight()/2.0f);
    Sprite.SetPosition(25, 100);

    sf::Shape Ball=sf::Shape::Circle(Window.GetWidth()/2.0f, Window.GetHeight()/2.0f,30,sf::Color::Green);
    Ball.SetPosition(Ball.GetPosition().x/2.0f, Ball.GetPosition().y/2.0f);

    while(Window.IsOpened())
    {
        //sf::Vector2f spr=Sprite.TransformToLocal(sf::Vector2f(Ball.GetPosition().x, Ball.GetPosition().y)  );

        Ball.Move(-2,0);
        printf("Ball %f",Ball.GetPosition().x);
        printf("\nSprite%f ",  Sprite.GetPosition().x,"\n\n");
        if(Ball.GetPosition().x<=Sprite.GetPosition().x)Ball.SetPosition(300,300);
        const sf::Input& Input = Window.GetInput();
        bool up = Input.IsKeyDown(sf::Key::Up);
        bool down = Input.IsKeyDown(sf::Key::Down);


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


        }
        if(down) Sprite.Move(0, 10);
        if(up) Sprite.Move(0,-10);
        if(Sprite.GetPosition().x<=0) Sprite.SetX(0);
        if(Sprite.GetPosition().y<=0) Sprite.SetY(100);
        if(Sprite.GetPosition().y>=Window.GetHeight()) Sprite.SetY(Window.GetHeight()-100);
        Window.Draw(Sprite);
        Window.Draw(Ball);
        Window.Display();
        Window.Clear();

    }

    return 0;
}

Thank's for help.

Pages: [1]