Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayerToaster extends Actor {
- int mX, mY;
- Sprite s;
- ShapeRenderer sR;
- Camera mainCamera;
- public PlayerToaster(float x, float y, Camera c)
- {
- this.setX(x);
- this.setY(y);
- mainCamera = c;
- this.setVisible(true);
- s = new Sprite(Assets.toaster);
- s.setPosition(Gdx.graphics.getWidth()/2 - s.getWidth()/2,
- Gdx.graphics.getHeight()/2 - s.getHeight()/2);
- sR = new ShapeRenderer();
- }
- @Override
- public void act(float delta) {
- super.act(delta);
- /* float degrees = (float) Math.toDegrees(Math.atan2(Gdx.input.getX() - this.getOriginX(), Gdx.input.getY() - this.getOriginY()));
- s.setRotation(degrees); */
- Vector2 centerPosition = new Vector2(s.getOriginX(), s.getOriginY());
- Vector3 worldCoordinates = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
- mainCamera.unproject(worldCoordinates);
- Vector2 mouseLoc = new Vector2(worldCoordinates.x, worldCoordinates.y);
- Vector2 direction = mouseLoc.sub(centerPosition);
- float mouseAngle = direction.angle();
- s.setRotation(mouseAngle);
- //s.rotate((float) (Math.atan2(deltaY, deltaX) * 180 / Math.PI));
- }
- @Override
- public void draw(SpriteBatch batch, float parentAlpha) {
- s.draw(batch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment