Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx Scaling Action with Keeping The Center Position

Tags:

libgdx

I'm creating a pop out action effect on a window after I click on some button in LibGdx.

May I know, Is there any methods available to scale the actor, in a way that keeping its center position at the center (scales in both direction of x and also both direction of y)?

addAction(sequence(scaleTo(1.3f,1.3f,0.2f),scaleTo(1f,1f,0.2f)));

This is the basic scaling method I used.

O →

But I want something like this:

......↑

← O →

......↓

like image 369
Frankey Avatar asked Oct 16 '25 12:10

Frankey


1 Answers

You need to set actor's origin to its center. First set the size, and then call:

actor.setOrigin(Align.center);

Note, that if your actor is a Table (and classes like Button, ImageButton extend Table), then you need to call:

actor.setTransform(true); // But keep in mind that has a performance impact "because {@link Batch#flush()} must be done before and after the transform"
like image 114
Arctic45 Avatar answered Oct 19 '25 14:10

Arctic45



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!