I a simple program that just make a 32x32 ball bounce around the screen and when I click and hold the the application's titlebar the ball appears to be still, but when I release the ball seems to go past the set boundaries.
#include <SFML/Graphics.hpp>
int vx = 500;
int vy = 150;
const int windowWidth = 800;
const int windowHeight = 600;
const int ballSize = 32;
int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "Physics Simulation");
App.SetFramerateLimit(60);
const sf::Input& Input = App.GetInput();
sf::Image ballImg;
if(!ballImg.LoadFromFile("Ball.png"))
return EXIT_FAILURE;
sf::Sprite Ball(ballImg);
Ball.SetPosition(400,600-32);
///***
while(App.IsOpened())
{
if(Ball.GetPosition().y > windowHeight-ballSize)
vy *= -1;
if(Ball.GetPosition().y < 0)
vy *= -1;
if(Ball.GetPosition().x > windowWidth-ballSize)
vx *= -1;
if(Ball.GetPosition().x < 0)
vx *= -1;
Ball.Move(vx*App.GetFrameTime(), vy*App.GetFrameTime());
sf::Event Event;
while(App.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear(sf::Color(100, 149, 237));
App.Draw(Ball);
App.Display();
}
return EXIT_SUCCESS;
}
[/code]