Possibility to use the game assets for swing?

Hey, :slight_smile:

I’m facing some problems when trying to build my game. Although the game itself is a JMonkeyApplication, there’s a swing launcher. This launcher uses the assets (e.g. “./assets/Interface/images/some_icon.png”).

When I build the project, those icons aren’t available anymore - Of course, because they are packed into the “./lib/assets.jar” and the project file paths aren’t available anymore.

I thought about several solutions, but none of them seems good to me.

1.) Seperate jME assets and Swing assets - This would mean, I’d insert a new folder in the project root directory that is copied to the directory of the build game. I don’t know if two assets folders is a “clean” solution (Maybe the same asset is used in swing and in the jME app). But this would be my way to go.

2.) Access the images/other files out of the jar - The problem here is that this would be a little more complicated in the code instead of just specify the file path. Moreover, while the project is running, the jar filepath is “./build/assets.jar”, but when building the game, it’s “./lib/assets.jar”. So I’d have to code something unexecutable by hoping, that it runs when building (Very unclean, I would never do that) or copy the assets folder each time I change something from the build-directory to a “./lib” folder - This wouldn’t be very good, too.

3.) Maybe something with the AssetsLoader thing can be done? But I’m not very used to this and it would also result in a more complicated code than just seperating the swing assets from the jME assets.

As you see, I prefer the first solution, but I’d just like to know if there’s another way to do that. :slight_smile:



Just load the image as a class resource. This is pretty common even in swing applications because it means you can keep the whole app packaged up.

Thank you very much - I didn’t knew how to use these “resources” for so long. :smiley:

Now I finally had a reason to look through the javadocs and I have to say, I like this “packed up” thing - I think I’ll use this to read custom *.xml files for my models, too.

It works perfectly with the assets folder and resource paths like “/Interface/images/some_icon.png”. :slight_smile:

Hm, I’ve got a new problem that’s related to the assets resources, the exported game doesn’t find my model files.

After a quick search, I found this hint in the wiki:

The original OgreXML .mesh.xml, .scene, .material, .skeleton.xml and .blend model files will not be included in the distribution assets.jar file of your distributed game, they are only available in the assets folder so you are able to recreate the .j3o file from the original if you ever come to change it in blender and have to export it again.

Is there a way to include the files? (Maybe an option in the IDE what files should be included/excluded from the *.jar file)
I could understand, if the idea behind this decision is that users will use the optimized *.j3o files, but I just wanted to ask, because I use a lot of blender files directly and it would be nice not to convert them each time I change something (Plus an export from blender to *.mesh.xml for the animated ones).

EDIT: I just converted all my models, it wasn't that much effort I think. And it seems to run a little bit faster but that could just be imagination. :D
EDIT²: I found the option in the IDE - "Project properties" -> "Build" -> "Assets" -> "Assets JAR Excludes". Now I'm struggling what to do. :(

j3o files will always load faster than blender or ogre files because the hard work was done before saving the j3o. That is why it is the recommended approach.

It also lets you confirm that the conversion happened properly before running your full game.