Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(640, 480),"test");
- sf::RectangleShape box;
- box.setSize(sf::Vector2f(32, 32));
- sf::Clock timer;
- window.setFramerateLimit(120);
- float dt;
- sf::Vector2f vel;
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- dt = timer.restart().asSeconds();
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) vel.y = -1;
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) vel.x = -1;
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) vel.y = 1;
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) vel.x = 1;
- box.move(vel.x * dt * 100, vel.y * dt * 100);
- if (vel.x != 0) vel.x = 0;
- if (vel.y != 0) vel.y = 0;
- window.clear();
- window.draw(box);
- window.display();
- std::cout << 1.f/dt << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement