1
General / Re: Simplle way to implement an input field
« on: April 09, 2012, 03:59:36 pm »
Thanks both of you! I'll check those libraries out .
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/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::VideoMode VMode(800, 600, 32);
sf::RenderWindow Window(VMode, "Empty Window");
sf::CircleShape circle;
circle.setRadius(8);
circle.setOutlineColor(sf::Color(0, 100, 100));
circle.setOutlineThickness(3);
circle.setPosition(10, 20);
circle.setFillColor(sf::Color(0, 255, 255));
sf::Clock clock;
clock.restart();
int updateNext = clock.getElapsedTime().asMilliseconds();
int cx, cy;
cx = 10;
cy = 20;
while (Window.isOpen())
{
sf::Event Event;
while (Window.pollEvent(Event))
{
switch (Event.type)
{
case sf::Event::Closed:
Window.close();
break;
default:
break;
}
}
Window.draw(circle);
Window.display();
Window.clear(sf::Color(0, 0, 0));
while (clock.getElapsedTime().asMilliseconds() > updateNext)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
circle.setPosition(cx-=2, cy);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
circle.setPosition(cx+=2, cy);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
circle.setPosition(cx, cy-=1);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
circle.setPosition(cx, cy+=1);
}
updateNext += 1/60;
}
}
return EXIT_SUCCESS;
}
while (clock.getElapsedTime().asMilliseconds() > updateNext)
Shouldn't it be the time until the start of this loop (which would increase after every loop)?