So, here we have a 96x64 image, composed of 6 32x32 sprites.
Alright, so I have this loading and drawing to the screen (just to make sure it’s not a problem with loading the texture)
So, here’s the line of code throwing the null-pointer
regions[0][0] = new TextureRegion(playerSheet, 0, 0, 32, 32);
This, from what I understand is supposed to get the first 32x32 pixels starting from 0, 0 in the image, and save it to a TextureRegion.
private TextureRegion[][] regions;
However, It’s throwing a null and I’m not sure why.
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.chris.platformer.entities.Player.loadAssets(Player.java:64)
at com.chris.platformer.entities.Player.<init>(Player.java:33)
at com.chris.platformer.screens.GameScreen.show(GameScreen.java:25)
at com.badlogic.gdx.Game.setScreen(Game.java:62)
at com.chris.platformer.Game.create(Game.java:10)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Here’s my loadAssets() method
private void loadAssets()
{
regions[0][0] = new TextureRegion(playerSheet, 0, 0, 32, 32);
regions[1][0] = new TextureRegion(playerSheet, 32, 0, 32, 32);
regions[2][0] = new TextureRegion(playerSheet, 64, 0, 32, 32);
regions[3][0] = new TextureRegion(playerSheet, 0, 32, 32, 32);
regions[4][0] = new TextureRegion(playerSheet, 32, 32, 32, 32);
regions[5][0] = new TextureRegion(playerSheet, 64, 32, 32, 32);
walkLeft = new Animation(0.40f, regions[0][0], regions[1][0], regions[2][0]);
walkRight = new Animation(0.40f, regions[3][0], regions[4][0], regions[5][0]);
playerSprite = new Texture("graphics/sprites/player/Player.png");
}
I believe that should get all 6 of the images, however it can’t even get the first one.