Import asset from internet


For my game, I need to be able to download assets from the internet, then add them to the assets of the game so they can be used multiple times witouth having to connect to the internet every time. But I noticed that when a project is tested in the IDE, the assets are in a normal folder, but when it’s built and the game in the dist folder is run, it takes the assets from an asset.jar file. How do I add downloaded files to that jar file, and should I check if it’s running from the IDE or from the dist folder to handle assets correctly? (If so, how?)

Many thanks in advance.

There is no built in solution for this. You could use a resource locator but that would download it each time. You should probably just download the file and save it somewhere yourself. A few people have been experimenting with and while it does work very well it also has some nasty limitations so it’s not perfect.

I’m facing a similar requirement as beniboy.

In DesktopAssetManager, near line 251 there’s a comment about loading an asset from the filesystem if it’s cached already.

What exactly is this block doing? Does it check for the existence of that assets.jar?

Further, when using a UrlLocator to retrieve files online, do these files get cached and saved to the file system at all?


It just caches the data in memory, also from Urls, yeah. Its so that no image is loaded twice for example, models share data they can share etc. It will automatically clear old assets so you can just use the assetManager all the time to instantiate models and textures etc. most efficiently.