Having trouble with the screen class..

I’m just getting back into this after a long break so bare with me…Basically, i’m making a 2d tiled game and having a big issue off gate…I’m implementing Screens with libgdx and basically, I immediately set it to the gamescreen and render tiles…I’m getting a NPE on my camera and my renderer in the render method…I think it’s calling the render class before calling create() where the objects are created…I made a post over at stack exchange with the code:

I know it’s gotta be something simple that i’m just missing…I just can’t find it.

Looks like the problem is here:

OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map,unitScale);
OrthographicCamera camera = new OrthographicCamera();

You’re creating a camera and map renderer that have a scope that is just that show method,and your camera and renderer in your screen class aren’t being created, which is why they are still null, even after show().

Ah…I see what you’re saying…I forgot more than I thought…so I should be passing the objects through to the render class? That doesn’t seem right…It could get pretty lengthy.

No, sorry if I didn’t make it more clear. Instead of doing:

TiledMap map = new TmxMapLoader().load("tdmap1.tmx");
OrthogonalTiledMapRenderer renderer = new OrthogonalTiledMapRenderer(map,unitScale);
OrthographicCamera camera = new OrthographicCamera();

try making it

map = new TmxMapLoader().load("tdmap1.tmx");
renderer = new OrthogonalTiledMapRenderer(map,unitScale);
camera = new OrthographicCamera();

because then you are using your class variables that are used in the render method.

Wow, i’m an idiot haha. I don’t know how I missed that. I knew it was something dumb. I appreciate it! I guess I need to brush up on everything.