Advertisement
dermetfan

Tiled Map Game Player touch controls

Apr 4th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. @Override
  2. public boolean touchDown(int screenX, int screenY, int pointer, int button) {
  3.     animationTime = 0;
  4.  
  5.     float width = Gdx.graphics.getWidth();
  6.     velocity.x = speed * Math.signum(screenX - width / 2); // hard
  7.     // velocity.x = speed * (screenX - width / 2) / width * 2; // fade
  8.  
  9.     float height = Gdx.graphics.getHeight();
  10.     if(canJump && screenY < height / 2) { // experiment by changing the 2 to change how high the touch has to be to jump
  11.         velocity.y = speed / 1.8f;
  12.         canJump = false;
  13.     }
  14.  
  15.     return true;
  16. }
  17.  
  18. @Override
  19. public boolean touchUp(int screenX, int screenY, int pointer, int button) {
  20.     animationTime = 0;
  21.     velocity.x = 0;
  22.     return true;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement