In Java in LibGDX I'm trying to make my camera follow an object created by shaperenderer. I don't want to use a sprite, but can only find tutorials for sprites. Using spritebatch and such.
I just want it to follow a rect I created in shaperenderer in a different class that I have getters and setters for- but no amount of camera updating and changing the position works. Is it possible to use Orthographic camera without a sprite?
public class Main extends ApplicationAdapter {
Ground g;
ShapeRenderer sr;
Player square;
OrthographicCamera camera;
@Override
public void create() {
sr = new ShapeRenderer();
g = new Ground(0, 20,Gdx.graphics.getWidth(), 5, new Color(Color.WHITE));
square = new Player(20, 25, 50,50, new Color(Color.PURPLE), 3);
camera = new OrthographicCamera();
camera.update();
}
@Override
public void render() {
ScreenUtils.clear(0.15f, 0.15f, 0.2f, 1f);
camera.lookAt(square.getX(), square.getY(), 0);
handleInput();
camera.update();
float dt = Gdx.graphics.getDeltaTime();
square.moveplayer(g, dt);
sr.begin(ShapeRenderer.ShapeType.Filled);
g.draw(sr);
sr.end();
sr.begin(ShapeRenderer.ShapeType.Filled);
square.draw(sr);
sr.end();
}
private void handleInput() {
if (Gdx.input.isKeyPressed(Input.Keys.DPAD_LEFT)) {
camera.translate(-3, 0, 0);
}
if (Gdx.input.isKeyPressed(Input.Keys.DPAD_RIGHT)) {
camera.translate(3, 0, 0);
}
}
As you can see I've tried a bunch of stuff like just moving the screen based on user input, or looking at the object, but maybe I'm missing something silly, because nothing changes/happens.
