Is there a way to scale a libgdx actor by a multiplier, taking into account the current scale?

212 Views Asked by At

In libgdx the Actor.scaleBy(float) method just adds the value to the current scale. However if I want an actor to appear twice as big as it currently is, and it's current scale is 3, then that means I need it to be 6. However scaleBy(2) brings it only to 5, because it only adds the value.

Is there a method that actually applies the scale factor via multiplication? Or am I understanding it wrong?

Edit: I realize I can do it manually, but I'm wondering if there's a preferred way that uses the API. Another complicating factor is that I need this to happen in an Action as well, meaning I'll likely have to build a custom action.

1

There are 1 best solutions below

0
Tenfour04 On

There is no better way to do it than

actor.setScale(actor.getScaleX() * multiplier, actor.getScaleyY() * multiplier);

If you're doing it as an Action, you would get the current scale, multiply it by something, and use a ScaleToAction:

actor.addAction(Actions.scaleTo(actor.getScaleX() * multiplier, actor.getScaleyY() * multiplier, duration));