SHOW:
|
|
- or go back to the newest paste.
1 | - | if(Gdx.input.isTouched()){ |
1 | + | // in show() method |
2 | - | if(Gdx.input.getY() <= 180){ |
2 | + | Gdx.input.setInputProcessor(new InputAdapter() { |
3 | - | movement.y = -speed; |
3 | + | |
4 | - | }else if(Gdx.input.getY() > 180){ |
4 | + | @Override |
5 | - | if(Gdx.input.getX() >= 250){ |
5 | + | public boolean touchDown(int screenX, int screenY, int pointer, int button) { |
6 | if(screenX < Gdx.graphics.getWidth() / 4) // adjust the number to divide with | |
7 | - | }else if(Gdx.input.getX() < 250){ |
7 | + | |
8 | else if(screenX > Gdx.graphics.getWidth() - Gdx.graphics.getWidth() / 4) | |
9 | - | } |
9 | + | |
10 | if(screenY < Gdx.graphics.getWidth() / 4) // y axis is inverted because it's in screen coordinates | |
11 | movement.y = speed; | |
12 | - | }else{ |
12 | + | return true; |
13 | - | movement.y = 0; |
13 | + | |
14 | - | movement.x = 0; |
14 | + | |
15 | - | } |
15 | + | @Override |
16 | - | |
16 | + | public boolean touchUp (int screenX, int screenY, int pointer, int button) { |
17 | movement.set(0, 0); | |
18 | return true; | |
19 | } | |
20 | ||
21 | }); | |
22 | ||
23 | // in render(float) method | |
24 | ball.applyForceToCenter(movement, true); | |
25 | ||
26 | camera.position.set(ball.getPosition().x, 1.5F, 0); | |
27 | camera.update(); | |
28 | ||
29 | debugRenderer.render(world, camera.combined); | |
30 | } |