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\$

1 Answer 1

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\$
1
  • \$\begingroup\$ Thanks Sidar! It works, but i'll search for tweener library! \$\endgroup\$
    – ApheX
    Commented Jun 25, 2013 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .