I’m having some trouble getting the camera to even work at times. Thankfully, its some-what working now. I’m trying to get the camera to follow the players movement but nothing happens.
(cut out the parts that are useless)
public class GameCore extends Game {
private OrthographicCamera cam;
private Player player;
private ShapeRenderer shape;
@Override
public void create() {
cam = new OrthographicCamera(1280 ,720);
cam.translate(Gdx.graphics.getWidth()/2, Gdx.graphics.getWidth()/2, 0);
cam.update();
shape = new ShapeRenderer();
player = new Player();
player.setPos((int)cam.position.x, (int)cam.position.y);
}
@Override
public void dispose() {
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
super.render();
player.render(shape, cam);
player.update();
}
GameCore class (my main one)
public class Player {
public int x,y;
public int dx, dy;
public int width, height;
public double area;
public int hp;
public Player(){
hp = 100;
width = 1150;
height = 500;
area = width*height;
x = Gdx.graphics.getWidth()/2;
y = Gdx.graphics.getHeight()/2;
dx = 5;
dy = 5;
}
public void render(ShapeRenderer shape, OrthographicCamera camera){
shape.setProjectionMatrix(camera.combined);
shape.begin(ShapeType.Line);
shape.circle(x, y, 32);
shape.end();
}
public void update(){
if(Gdx.input.isKeyPressed(Input.Keys.A)){
x -= dx;
}
if(Gdx.input.isKeyPressed(Input.Keys.D)){
x += dx;
}
if(Gdx.input.isKeyPressed(Input.Keys.S)){
y -= dy;
}
if(Gdx.input.isKeyPressed(Input.Keys.W)){
y += dy;
}
}
public void setPos(int x, int y){
x = this.x;
y = this.y;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
}
Player class
Hopefully someone here can also point out if i’m doing something wrong with the camera -_-. The docs don’t really provide much information on how these classes are used. Thank you!