Guest User

Untitled

a guest
Oct 4th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. public class PlayerToaster extends Actor  {
  2.     int mX, mY;
  3.     Sprite s;
  4.     ShapeRenderer sR;
  5.     Camera mainCamera;
  6.     public PlayerToaster(float x, float y, Camera c)
  7.     {
  8.         this.setX(x);
  9.         this.setY(y);
  10.         mainCamera = c;
  11.         this.setVisible(true);
  12.         s = new Sprite(Assets.toaster);
  13.         s.setPosition(Gdx.graphics.getWidth()/2 - s.getWidth()/2,
  14.                 Gdx.graphics.getHeight()/2 - s.getHeight()/2);
  15.         sR = new ShapeRenderer();
  16.        
  17.        
  18.     }
  19.    
  20.     @Override
  21.      public void act(float delta) {
  22.       super.act(delta);
  23.     /* float degrees = (float) Math.toDegrees(Math.atan2(Gdx.input.getX() - this.getOriginX(), Gdx.input.getY() - this.getOriginY()));
  24.         s.setRotation(degrees); */
  25.         Vector2 centerPosition = new Vector2(s.getOriginX(), s.getOriginY());
  26.  
  27.         Vector3 worldCoordinates = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
  28.         mainCamera.unproject(worldCoordinates);
  29.  
  30.         Vector2 mouseLoc = new Vector2(worldCoordinates.x, worldCoordinates.y);
  31.  
  32.         Vector2 direction = mouseLoc.sub(centerPosition);
  33.         float mouseAngle  = direction.angle();
  34.         s.setRotation(mouseAngle);
  35.      //s.rotate((float) (Math.atan2(deltaY, deltaX) * 180 / Math.PI));
  36.     }
  37.    
  38.      @Override
  39.      public void draw(SpriteBatch batch, float parentAlpha) {
  40.          s.draw(batch);
  41.          }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment