1
Graphics / Clicking app titlebar makes objects skip
« on: March 18, 2011, 09:14:05 pm »
Oh, I can't believe I didn't think of that, thanks.
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.
#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]