Search code examples
androidassetsplayn

Where do I put assets in a PlayN project?


I've set up a new PlayN project, and it runs some trivial code. I want to add asset files and load them, but where do I put the assets? I found the documentation for the Assets class, but it doesn't say anything about where the actual files go, and how I know what path to request.


Solution

  • After some more digging, I found an article describing the migration from PlayN 1.5 to 1.6. That includes a description of where to put your asset files in versions 1.6 and up.

    In the new app organization, games have a top-level assets submodule which contains all of their assets. The android and ios submodules do not depend (in the Maven sense) on the assets submodule, but instead symlink the assets directly into their respective project directories so that they can be found by the Android and iOS build systems. This ensures that the assets are not included twice into the project (once in the jar file and once via the custom Android and iOS build systems). The other backends (HTML, Flash, Java) still load assets via the classpath and do have a dependency on the new assets submodule (in addition to their existing dependecy on the core submodule).

    When Maven creates the project skeleton, you should see a project called yourapp-assets with a folder src/main/resources/assets. Anything you put in there can be loaded with the Assets class. If you create a file src/main/resources/assets/images/smile.png, then you can load it with PlayN.assets().getImage("images/smile.png").