So, I am trying to read images off an atlas in libGDX. I have packed my images into a .atlas file and a .png file already, and I am reading them like this:
TextureRegion player = getAtlas().findRegion("player-model-fiona");
Error code:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: java.lang.NullPointerException
at com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable.setRegion(TextureRegionDrawable.java:46)
at com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable.<init>(TextureRegionDrawable.java:32)
at com.devhub.improvgames.magicgame.StartGameScreen.updateValues(StartGameScreen.java:152)
at com.devhub.improvgames.magicgame.StartGameScreen.show(StartGameScreen.java:126)
at com.badlogic.gdx.Game.setScreen(Game.java:59)
at com.devhub.improvgames.magicgame.MagicGame.setScreen(MagicGame.java:127)
at com.devhub.improvgames.magicgame.MenuScreen$1.touchUp(MenuScreen.java:30)
at com.badlogic.gdx.scenes.scene2d.InputListener.handle(InputListener.java:43)
at com.badlogic.gdx.scenes.scene2d.Stage.touchUp(Stage.java:309)
at com.badlogic.gdx.backends.lwjgl.LwjglInput.processEvents(LwjglInput.java:297)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:186)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)
The specific error happens at
playerModelImage.setDrawable(new TextureRegionDrawable(player));
because I am trying to set the drawable to a textureregiondrawable that has a null argument.
So, basically it can’t find the region, making player null. I have no idea why
Manually getting the images (manually setting x/y/width/height) works though. I’m probably too vague and this is probably some obscure but easy to solve bug but I’m stumped.
pages.png (source pic for atlas), test pics obviously
pack file:
pages.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
player-model-aidan
rotate: false
xy: 1, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
player-model-azrael
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
player-model-raven
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
robe-adept
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
robe-god
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
staff-master
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
staff-neophyte
rotate: false
xy: 25, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
player-model-elysia
rotate: false
xy: 49, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
robe-neophyte
rotate: false
xy: 49, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
staff-god
rotate: false
xy: 49, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
player-model-fiona
rotate: false
xy: 73, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
robe-master
rotate: false
xy: 73, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
staff-epic
rotate: false
xy: 73, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
player-model-raiden
rotate: false
xy: 97, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
robe-epic
rotate: false
xy: 97, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1
staff-adept
rotate: false
xy: 97, 1
size: 22, 28
orig: 22, 28
offset: 0, 0
index: -1