/** Transforms the screen coordinates to stage coordinates. * @param screenCoords Input screen coordinates and output for resulting stage coordinates. */ public Vector2 screenToStageCoordinates (Vector2 screenCoords) { viewport.unproject(screenCoords); return screenCoords; }
/** Transforms the screen coordinates to stage coordinates. * @param screenCoords Input screen coordinates and output for resulting stage coordinates. */ public Vector2 screenToStageCoordinates (Vector2 screenCoords) { viewport.unproject(screenCoords); return screenCoords; }
/** Transforms the screen coordinates to stage coordinates. * @param screenCoords Input screen coordinates and output for resulting stage coordinates. */ public Vector2 screenToStageCoordinates (Vector2 screenCoords) { viewport.unproject(screenCoords); return screenCoords; }
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { targetPosition = viewport.unproject(new Vector2(screenX, screenY)); return true; }
private Vector2 worldVector(int screenX, int screenY) { viewport.unproject(tmpVec.set(screenX, screenY)); return tmpVec; }
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { if (flicking){ flicking = false; Vector2 flickEnd = viewport.unproject(new Vector2(screenX, screenY)); velocity.x += 3 * (flickEnd.x - flickStart.x); velocity.y += 3 * (flickEnd.y - flickStart.y); Gdx.app.log("Ball", "End flick"); } following = false; return true; } }
private void getInputUnproject(Viewport v, Vector2 out) { out.set(Gdx.input.getX(), Gdx.input.getY()); v.unproject(out); }
private void getInputUnProject(Vector3 out) { out.set(Gdx.input.getX(), Gdx.input.getY(), 0); viewport.unproject(out); }
private void getInputUnproject(Viewport v, Vector2 out) { out.set(Gdx.input.getX(), Gdx.input.getY()); v.unproject(out); }
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { Vector2 worldClick = viewport.unproject(new Vector2(screenX, screenY)); if (worldClick.dst(position) < baseRadius * radiusMultiplier){ Gdx.app.log("Ball", "Click in the ball, starting flick."); flicking = true; flickStart = worldClick; } else { targetPosition = worldClick; following = true; } return true; }
@Override public Vector3 unproject(Vector3 out) { super.unproject(out); out.x = MathUtils.clamp(out.x, 0, getScreenWidth() - 1); out.y = MathUtils.clamp(out.y, 0, getScreenHeight() - 1); return out; } }
@Override public Vector2 unproject(Vector2 out) { super.unproject(out); out.x = MathUtils.clamp(out.x, 0, getScreenWidth() - 1); out.y = MathUtils.clamp(out.y, 0, getScreenHeight() - 1); return out; }
@Override public Vector3 unproject(Vector3 out) { super.unproject(out); out.x = MathUtils.clamp(out.x, 0, getScreenWidth() - 1); out.y = MathUtils.clamp(out.y, 0, getScreenHeight() - 1); return out; } }
@Override public Vector2 unproject(Vector2 out) { super.unproject(out); out.x = MathUtils.clamp(out.x, 0, getScreenWidth() - 1); out.y = MathUtils.clamp(out.y, 0, getScreenHeight() - 1); return out; }
public void update(float delta) { // Update position movement.set(0.0f, 0.0f); if (Gdx.input.isKeyPressed(Keys.A)) { movement.x = -1.0f; } else if (Gdx.input.isKeyPressed(Keys.D)) { movement.x = 1.0f; } if (Gdx.input.isKeyPressed(Keys.S)) { movement.y = -1.0f; } else if (Gdx.input.isKeyPressed(Keys.W)) { movement.y = 1.0f; } if (movement.len2() > 0.0f) { movement.nor(); position.add(movement.scl(speed * delta)); } // Update direction mousePos.set(Gdx.input.getX(), Gdx.input.getY()); viewport.unproject(mousePos); direction.set(mousePos).sub(position).nor(); } }