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 - Ubiquité

Pages: [1]
1
Graphics / How to get the position of a Shape within a window !?
« on: July 02, 2011, 05:43:12 pm »
My  bad. It is my first SFML program ^^ (and I appreciate the "real C++" way)

2
Graphics / How to get the position of a Shape within a window !?
« on: July 02, 2011, 04:54:23 pm »
Ok thank you. I think it worth mentioning in the tutorials.

3
Graphics / How to get the position of a Shape within a window !?
« on: July 02, 2011, 04:36:23 pm »
Thank you but is it normal if GetPosition behave so strangely ?
Currently my code looks like that :
Code: [Select]

//Pong
int main(void)
{
  const float PlayerSpeed = 2200;
  sf::Vector2<float> ballMove(-500.,00);
 

  sf::RenderWindow app(sf::VideoMode(800,600,32), "My Pong");
  sf::Shape player1 = sf::Shape::Rectangle(30,250,40,350,sf::Color::White);
  sf::Shape player2 = sf::Shape::Rectangle(800-40,250,800-30,350,sf::Color::White);
  sf::Shape ball = sf::Shape::Rectangle(800-405,295,800-395,305,sf::Color::White);

  // ball.SetCenter(5,5);

  const sf::Input& in = app.GetInput();

  sf::Clock clock;

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

      //Move player1 (a & q)
      if(in.IsKeyDown(sf::Key::A))
        player1.Move(0,-PlayerSpeed*clock.GetElapsedTime());
     
      if(in.IsKeyDown(sf::Key::Q))
        player1.Move(0,PlayerSpeed*clock.GetElapsedTime());
     
      //Move player2 (p & m)
      if(in.IsKeyDown(sf::Key::P))
        player2.Move(0,-PlayerSpeed*clock.GetElapsedTime());
             
      if(in.IsKeyDown(sf::Key::M))
        player2.Move(0,PlayerSpeed*clock.GetElapsedTime());
             
      //Move the ball
     
      //test collisions between ball and frame borders
      //sf::Vector2<float> c = ball.GetPosition();
     
      //std::cerr << c.x << std::endl;
      //std::cerr << c.y << std::endl;
      std::cerr << ball.GetPointPosition(0).y << std::endl;

      if(ball.GetPointPosition(0).x <= 0. && ballMove.x < 0.)
         ballMove.x -= ballMove.x;
       if(ball.GetPointPosition(0).y <= 0. && ballMove.y < 0.)
         ballMove.y -= ballMove.y;

      ball.Move(ballMove.x*clock.GetElapsedTime(),ballMove.y*clock.GetElapsedTime());

      //Draw everything
      app.Draw(player1);
      app.Draw(player2);
      app.Draw(ball);
     
      app.Display();
      clock.Reset();
     
    }
}


The std::cerr always display the same value.

4
Graphics / How to get the position of a Shape within a window !?
« on: July 02, 2011, 02:28:06 pm »
Hi,
I am making a pong and the ball an the players are simple shapes (rectangles). I move them with Shape::Move but when I use Shape::GetPosition, I expected to get the position of the shape relatives to the origine of the window but it appears to be relatives to the original position of the shape.
Could you help me?

Pages: [1]