[Edit] Solved it, I had it creating an instance of a class before it initialize the camera
So I have this problem were my Orthographic Camera is coming up null when I try to use a getter on it. It also comes up null when i make it public and try to access it.
this is the main class were i set cam = new OrthographicCamera(); which makes cam != null.
public class Main extends ApplicationAdapter {
public static final String Title = "Mead Walla";
public static final int Width = 360;
public static final int Height = 240;
public static final int Scale = 2;
private SpriteBatch sb;
private OrthographicCamera cam;
private OrthographicCamera hudCam;
private GameStateHandler gsh;
public static ContentHandler res;
public void create() {
//initialize handlers
res = new ContentHandler();
gsh = new GameStateHandler(this);
//initialize LibGDX elements
sb = new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(false, Width, Height);
hudCam = new OrthographicCamera();
hudCam.setToOrtho(false, Width, Height);
Gdx.input.setInputProcessor(new InputHandler());
//load content
try {
res.loadTexture("player/testPlayer.png", "testPlayer");
}
catch(Exception e) {
System.out.println("Cannot find file: testPlayer");
Gdx.app.exit();
}
}
public void render() {
Gdx.graphics.setTitle(Title + " -- FPS: " + Gdx.graphics.getFramesPerSecond());
gsh.update(Gdx.graphics.getDeltaTime());
gsh.render();
InputHandler.update();
sb.setProjectionMatrix(hudCam.combined);
sb.begin();
sb.draw(res.getTexture("testPlayer"), 0, 0);
sb.end();
}
public SpriteBatch getSpriteBatch() {
return sb;
}
public OrthographicCamera getCam() {
return cam;
}
public OrthographicCamera getHudCam() {
return hudCam;
}
but when i try to use the getCam() it sets cam to null and i have no clue why
public abstract class State {
protected GameStateHandler gsh;
protected Main game;
protected SpriteBatch sb;
protected OrthographicCamera cam;
protected OrthographicCamera hudCam;
protected State(GameStateHandler gsh) {
this.gsh = gsh;
game = gsh.getGame();
sb = game.getSpriteBatch();
cam = game.getCam(); //this returns null for some reason when it should return the cam from main
hudCam = game.getHudCam();
}
public abstract void handleInput();
public abstract void update(float dt);
public abstract void render();
public abstract void dispose();
}
Any help would be appreciated.