Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (474)
Games in Android Showcase (105)
games submitted by our members
Games in WIP (524)
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 - how do I load local assets without an android project?  (Read 2798 times)
0 Members and 1 Guest are viewing this topic.
Offline Runcible

Senior Newbie





« Posted 2013-03-30 17:39:03 »

Hi all,

I've been getting to grips with using libgdx to develop my game, but as I'm only creating this for desktop, I'm using a single project rather than the default split of base game / desktop project / android project. Now I've been trying to use the following line to load a textureatlas:

1  
atlas = new TextureAtlas(Gdx.files.internal("assets/packed/game.atlas"));
where the 'assets' directory is in the root of the project directory. However running this code just gives me a NullPointerException. From what I can gather though, GDX.files.internal is expecting there to be an assets folder in the android project directory - which I'm not using.

So my question is, how can I correctly reference and load a local file in my project? Thanks.
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #1 - Posted 2013-03-30 17:42:08 »

The android project is necessary for this reason. Even if your not using it on android that is where your assets are stored. I'm not sure if there is a way around this however...

Offline Runcible

Senior Newbie





« Reply #2 - Posted 2013-03-30 17:43:54 »

There are other methods on GDX.files as well though, I wondered if one of these can be used instead? (e.g. classpath(), but I've not figured out how)

It seems odd that I must have this separate android project folder simply to store my assets in when I'm not going to be using it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #3 - Posted 2013-03-30 18:02:58 »

Hi all,

I've been getting to grips with using libgdx to develop my game, but as I'm only creating this for desktop, I'm using a single project rather than the default split of base game / desktop project / android project. Now I've been trying to use the following line to load a textureatlas:

1  
atlas = new TextureAtlas(Gdx.files.internal("assets/packed/game.atlas"));
where the 'assets' directory is in the root of the project directory. However running this code just gives me a NullPointerException. From what I can gather though, GDX.files.internal is expecting there to be an assets folder in the android project directory - which I'm not using.

So my question is, how can I correctly reference and load a local file in my project? Thanks.

Hey man.
Our big project is also desktop-only and uses libgdx - this shouldnt be a problem.
You seem to be doing it right - I suspect that you created the project with the libgdx gui ?  which is nice and all IF you want those other ports... but if not, just make one yourself and add the jars
pretty sure it should work then.
also: if you wanna know where libgdx is really searching you can do sysout of Gdx.files.internal("assets/packed/game.atlas").file().absolutePath()

Offline davedes
« Reply #4 - Posted 2013-03-30 18:14:23 »

You can create a desktop-only project with GDX just like you would with any Java class library. Here's how to do it in Eclipse.

1. Create a new project.


2. Right click your project and select Properties. In the "Java Build Path" tab, add the necessary GDX dependencies. In my project I copied them from the LibGDX Nightlies into the folder
my_project/lib
, then used Add JARs to select a JAR within the project path. If you want to keep your GDX JARs in the same folder for all your projects, you would select "Add External JARs" instead.


3. Create a new source folder called "assets", like so:


Inside that source folder, add a new folder like "res" or "data" for your resources. For example, if you have "assets/data" for your resources, then you'll use the following to access it:
Gdx.files.internal("data/myTex.png")


Another option is to include your resources in your "src" folder, but this is not always recommended.

4. Compile and run a basic test:
http://www.java-gaming.org/?action=pastebin&id=521

Offline Cero
« Reply #5 - Posted 2013-03-30 18:30:29 »

3. In your "src" folder, create a new folder called "data" (or "res" or whatever). This is where your images will go.

I respectfully disagree since resources/assets aren't source files - but it works in both ways.
I have also no interest in packaging my resources into jars, so yeah...



old screenshot I made for a similar discussion, click to enlarge =P

edit: Gdx.files.internal("content/loading_symbol.png") works in this case, not sure what happens when you put it all in the src folder

Offline Runcible

Senior Newbie





« Reply #6 - Posted 2013-03-30 19:59:44 »

Thanks all, that has helped me narrow things down to it being a problem only when I use TextureAtlas. My .atlas and .png file are in the same directory as I think libgdx expects, so I'm not sure what else could be wrong as I'm only seeing a generic NullPointerException.
Offline Cero
« Reply #7 - Posted 2013-03-30 23:02:49 »

Thanks all, that has helped me narrow things down to it being a problem only when I use TextureAtlas. My .atlas and .png file are in the same directory as I think libgdx expects, so I'm not sure what else could be wrong as I'm only seeing a generic NullPointerException.

which line ? you may be searching for a texture in the atlas which isn't there. possible typo

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.

Riven (25 views)
2014-07-10 20:20:18

CopyableCougar4 (23 views)
2014-07-10 02:26:14

CopyableCougar4 (30 views)
2014-07-09 02:55:38

Code Mage (30 views)
2014-07-08 23:57:00

Code Mage (17 views)
2014-07-08 23:49:08

AppleSauce (26 views)
2014-07-08 19:25:32

CopyableCougar4 (26 views)
2014-07-06 01:51:26

ipe369 (32 views)
2014-07-05 14:18:25

vastrolorde (42 views)
2014-07-04 18:45:44

theagentd (59 views)
2014-07-02 22:19:37
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

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!