Thank you but is it normal if GetPosition behave so strangely ?
Currently my code looks like that :
//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.