Advertisement
Guest User

ScalableButton

a guest
Mar 6th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. public class ScalableButton extends Image {
  2.    
  3.     public ScalableButton(TextureRegion t) {
  4.         super(t);
  5.         setOrigin(getWidth() / 2, getHeight() / 2);
  6.     }
  7.     public ScalableButton(Texture t) {
  8.         super(t);
  9.         setOrigin(getWidth() / 2, getHeight() / 2);
  10.     }
  11.    
  12.     public boolean addMyListener(final RunnableAction clickAction) {
  13.         EventListener clickListener = new InputListener() {
  14.             @Override
  15.             public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
  16.                 MusicHandler.playClick();
  17.                 addAction(Actions.scaleTo(0.8f, 0.8f, 0.03f, Interpolation.fade));
  18.                 return true;
  19.             }
  20.            
  21.             @Override
  22.             public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
  23.                 clearActions();
  24.                 addAction(Actions.scaleTo(1,1, 0.05f, Interpolation.fade));
  25.                 clickAction.run();
  26.                 super.touchUp(event, x, y, pointer, button);
  27.             }
  28.         };
  29.         return super.addListener(clickListener);
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement