Package playn.java

Class JavaAssets

java.lang.Object
playn.core.Assets
playn.java.JavaAssets

public class JavaAssets
extends Assets
Loads Java assets via the classpath.
  • Constructor Details

    • JavaAssets

      public JavaAssets​(JavaPlatform plat)
      Creates a new java assets.
  • Method Details

    • setPathPrefix

      public void setPathPrefix​(String prefix)
      Configures the prefix prepended to asset paths before fetching them from the classpath. For example, if your assets are in src/main/java/com/mygame/assets (or in src/main/resources/com/mygame/assets), you can pass com/mygame/assets to this method and then load your assets without prefixing their path with that value every time. The value supplied to this method should not contain leading or trailing slashes. Note that this prefix should always use '/' as a path separator as it is used to construct URLs, not filesystem paths.

      NOTE: the path prefix is not used when searching extra directories

    • getPathPrefix

      public String getPathPrefix()
      Returns the currently configured path prefix. Note that this value will always have a trailing slash.
    • addDirectory

      public void addDirectory​(File dir)
      Adds the given directory to the search path for resources.

      TODO: remove? get?

    • setAssetScale

      public void setAssetScale​(float scaleFactor)
      Configures the default scale to use for assets. This allows one to specify an intermediate graphics scale (like 1.5) and scale the 2x imagery down to 1.5x instead of scaling the 1.5x imagery up (or displaying nothing at all).
    • getFont

      public Font getFont​(String path) throws Exception
      Loads a Java font from path. Currently only TrueType (.ttf) fonts are supported.
      Parameters:
      path - the path to the font resource (relative to the asset manager's path prefix).
      Throws:
      Exception - if an error occurs loading or decoding the font.
    • getRemoteImage

      public Image getRemoteImage​(String url, int width, int height)
      Overrides:
      getRemoteImage in class Assets
    • getSound

      public Sound getSound​(String path)
      Specified by:
      getSound in class Assets
    • getMusic

      public Sound getMusic​(String path)
      Overrides:
      getMusic in class Assets
    • getTextSync

      public String getTextSync​(String path) throws Exception
      Specified by:
      getTextSync in class Assets
      Throws:
      Exception
    • getBytesSync

      public ByteBuffer getBytesSync​(String path) throws Exception
      Specified by:
      getBytesSync in class Assets
      Throws:
      Exception