3
\$\begingroup\$

Is there any way to animate a transformation on sf::Sprite like setScale or setPosition?

ie: sprite.setScale(0.5f,0.5f);. I want the transition between normal and half scale be smooth.

Thanks!

\$\endgroup\$
2
\$\begingroup\$

Simply use interpolation between the two values.

A simple form:

Vector2 goalScale = new Vector2(1,1);
Vector2 resultScale = sprite.getScale();

resultScale+= (goalScale - resultScale)/2; // increase division for stronger easing

sprite.setScale(resultScale);

Alternatively use a C++ tweener library.

\$\endgroup\$
  • \$\begingroup\$ Thanks Sidar! It works, but i'll search for tweener library! \$\endgroup\$ – ApheX Jun 25 '13 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.