#include #include #include struct MoveAnimation{ MoveAnimation(const sf::Vector2f& from, const sf::Vector2f& to): from(from), direction(to-from) { } void operator()(sf::Transformable& animated, float progress){ auto pos = from + progress*direction; animated.setPosition(pos); } const sf::Vector2f from; const sf::Vector2f direction; }; int main() { sf::RenderWindow window(sf::VideoMode(600, 600), "Move animation"); //input thor::ActionMap actionMap; thor::ActionMap::CallbackSystem system; actionMap["Close"] = thor::Action(sf::Event::Closed); system.connect0("Close", [&window] { window.close(); }); //shape to animate sf::RectangleShape shape({100.f, 100.f}); shape.setFillColor(sf::Color::Green); shape.setPosition({100.f, 100.f}); //set up animation thor::AnimationMap animationMap; thor::Animator animator(animationMap); auto from = shape.getPosition(); auto to = sf::Vector2f(400.f, 400.f); MoveAnimation move(from, to); auto duration = sf::seconds(1.f); animationMap.addAnimation("Move", move, duration); animator.play() << "Move"; //main loop sf::Clock clock; while (window.isOpen()){ actionMap.update(window); actionMap.invokeCallbacks(system, &window); //animate shape auto frameTime = clock.restart(); animator.update(frameTime); animator.animate(shape); window.clear(); window.draw(shape); window.display(); } }