I am developing game using LibGDX . I want to create beautiful menu and to scale buttons when they are pressed but not in this way , when it is pressed scale it 1.5f , I want to scale it with animation . I am using imagebuttons .
2 Answers
Since you are using Actors you can simply give the actor an Action. For scaling you could use this method:
myActor.addAction(Actions.scaleTo(scaleX, scaleY, duration);
Then when the user stops pressing the button you can cancel the current action and give the actor a new one that scales back down to the original size.
You could change the scale by a factor n each time in the render loop when the button is pressed.
Initialisation of your ImageButton:
button = new ImageButton(Assets.button_style);
button.addListener(new InputListener(){
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
// enable scaling when button is pressed
scale = true;
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
button.setChecked(false);
// disable scaling when button is released
scale = false;
}
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
// disable scaling when button is exited with mouse
scale = false;
}
});
Render Loop:
if(scale) {
// set width and height (add n to current size)
button.setWidth(button.getWidth() + n);
button.setHeight(button.getHeight() + n);
// re-adjust position
button.setPosition(button.getX() - n/2, button.getY() - n/2);
}
Hope that helps. Limitations are that your animation has to be linear, if you want another kind of Interpolation you should read something about Interpolation.