Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  libgdx: can't find region in atlas  (Read 2237 times)
0 Members and 1 Guest are viewing this topic.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Posted 2012-12-22 06:51:41 »

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:
1  
TextureRegion player = getAtlas().findRegion("player-model-fiona");            

Error code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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
1  
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 Sad
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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
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
Offline ReBirth
« Reply #1 - Posted 2012-12-22 13:14:10 »

Previously I had problem with atlas too when upgrading to 0.9.7. It's not "-" but "_". My quick fix was removing the underscore. Maybe you can try it.

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #2 - Posted 2012-12-22 13:54:39 »

player-model-fiona is in your pack file, should work. Refresh Eclipse, maybe it isn't picking up the latest files if you are loading it through the classpath. I use a -Declipse flag when running in Eclipse (in the vm arguments for your run configuration), then:

1  
2  
3  
4  
      if (System.getProperty("eclipse") != null)
         skin = new Skin(Gdx.files.internal("../assets/skin/skin.json"));
      else
         skin = new Skin(Gdx.files.internal("skin/skin.json"));

The same could be done to load your atlas. This way I load directly from disk when running in Eclipse but load from the classpath otherwise without changing any code. Note Gdx.files.internal checks on disk for the path first, then the classpath. You could also use Gdx.files.absolute, etc.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2012-12-22 18:25:35 »

Previously I had problem with atlas too when upgrading to 0.9.7. It's not "-" but "_". My quick fix was removing the underscore. Maybe you can try it.
So it should be player_model_fiona?  And I have to change the atlas file too, right?
EDIT: doesn't seem to work. Tried all combinations of the atlas file and the code between "-" and "_".

@Nate the file is the latest, I can view it through eclipse and it is the correct version.
I am currently loading the atlas like so:
1  
2  
3  
4  
5  
6  
public TextureAtlas getAtlas() {
      if (atlas == null) {
         atlas = new TextureAtlas(Gdx.files.internal("image-atlases/pages.atlas"));      
      }
      return atlas;
   }

EDIT: I think you may be on to something, I replaced my working pack file from steigert with the error one and it still worked, I tried running with -Declipse but I get
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Cannot open a stream to a directory: C:\Users\Jimmt\Documents\Jimmt\EclipseWorkspace\MagicGame-Android\assets\image-atlases (Internal)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Cannot open a stream to a directory: C:\Users\Jimmt\Documents\Jimmt\EclipseWorkspace\MagicGame-Android\assets\image-atlases (Internal)
   at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:134)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:97)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:222)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:217)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:207)
   at com.devhub.improvgames.magicgame.StartGameScreen.updateValues(StartGameScreen.java:141)
   at com.devhub.improvgames.magicgame.StartGameScreen.show(StartGameScreen.java:127)
   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)
Caused by: java.io.FileNotFoundException: C:\Users\Jimmt\Documents\Jimmt\EclipseWorkspace\MagicGame-Android\assets\image-atlases (Access is denied)
   at java.io.FileInputStream.open(Native Method)
   at java.io.FileInputStream.<init>(Unknown Source)
   at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:131)
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2012-12-22 19:23:35 »

Yay, it works(I think)
Used Nate's method of
1  
2  
3  
4  
 if (System.getProperty("eclipse") != null)
         skin = new Skin(Gdx.files.internal("../assets/skin/skin.json"));
      else
         skin = new Skin(Gdx.files.internal("skin/skin.json"));

and the -Declipse vm flag
Not sure if it's good to use an absolute path like that though...
Offline ReBirth
« Reply #5 - Posted 2012-12-23 03:56:08 »

No I meant remove _ and -. Glad you made it. I never countered this before, as I always remember to refresh the android project.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!