Advertisement
H1151

Untitled

Feb 14th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. package fi.tiko.tamk;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.graphics.Texture;
  5. import com.badlogic.gdx.graphics.g2d.Batch;
  6. import com.badlogic.gdx.math.Interpolation;
  7. import com.badlogic.gdx.scenes.scene2d.Actor;
  8. import com.badlogic.gdx.scenes.scene2d.InputEvent;
  9. import com.badlogic.gdx.scenes.scene2d.InputListener;
  10. import com.badlogic.gdx.scenes.scene2d.Touchable;
  11. import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
  12.  
  13. public class RockActor extends Actor
  14. {
  15.     private Texture rockPic;
  16.  
  17.     public Texture getRockPic()
  18.     {
  19.         return rockPic;
  20.     }
  21.  
  22.     public RockActor()
  23.     {
  24.         rockPic = new Texture(Gdx.files.internal("Rock.png"));
  25.         setTouchable(Touchable.enabled);
  26.         setBounds(0, 0, rockPic.getWidth(), rockPic.getHeight());
  27.         addListener(new RockListener());
  28.  
  29.         Gdx.app.log("ROCK", ": " + this);
  30.         Gdx.app.log("ROCKw", ": " + this.getWidth());
  31.         Gdx.app.log("ROCKx", ": " + this.getX());
  32.     }
  33.  
  34.     @Override
  35.     public void act(float delta)
  36.     {
  37.         super.act(delta);
  38.     }
  39.  
  40.     @Override
  41.     public void draw(Batch batch, float alpha)
  42.     {
  43.         batch.draw(rockPic,
  44.                 this.getX(), this.getY(),
  45.                 this.getOriginX(),
  46.                 this.getOriginY(),
  47.                 rockPic.getWidth(),
  48.                 rockPic.getHeight(),
  49.                 this.getScaleX(),
  50.                 this.getScaleY(),
  51.                 this.getRotation(), 0, 0,
  52.                 rockPic.getWidth(), rockPic.getHeight(), false, false);
  53.  
  54.     }
  55.  
  56.     class RockListener extends InputListener
  57.     {
  58.         @Override
  59.         public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor)
  60.         {
  61.             Gdx.app.log("Boom", ": " + event+" "+x+" "+y+" "+pointer+" "+fromActor);
  62.         }
  63.  
  64.         @Override
  65.         public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
  66.         {
  67.             Gdx.app.log("X", ": " + x);
  68.             Gdx.app.log("Y", ": " + y);
  69.  
  70.             MoveToAction moveToAction = new MoveToAction();
  71.             moveToAction.setPosition(420, 300);
  72.             moveToAction.setDuration(1f);
  73.             moveToAction.setInterpolation(Interpolation.bounceOut);
  74.  
  75.             addAction(moveToAction);
  76.  
  77.             return true;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement