Package playn.core

Class Assets

java.lang.Object
playn.core.Assets

public abstract class Assets extends Object
Fetches and returns assets.
  • Method Details

    • getImageSync

      public Image getImageSync(String path)
      Synchronously loads and returns an image. The calling thread will block while the image is loaded from disk and decoded. When this call returns, the image's width and height will be valid, and the image can be immediately converted to a texture and drawn into a canvas.
      Parameters:
      path - the path to the image asset.
      Throws:
      UnsupportedOperationException - on platforms that cannot support synchronous asset loading (HTML).
    • getImage

      public Image getImage(String path)
      Asynchronously loads and returns an image. The calling thread will not block. The returned image will not be immediately usable, will not report valid width and height, and cannot be immediately rendered into a canvas or converted into a texture. Use Image.state to be notified when loading succeeds or fails.
      Parameters:
      path - the path to the image asset.
    • getRemoteImage

      public Image getRemoteImage(String url)
      Asynchronously loads and returns the image at the specified URL. The width and height of the image will be unset (0) until the image is loaded. Note: on non-HTML platforms, this spawns a new thread for each loaded image. Thus, attempts to load large numbers of remote images simultaneously may result in poor performance.
    • getRemoteImage

      public Image getRemoteImage(String url, int width, int height)
      Asynchronously loads and returns the image at the specified URL. The width and height of the image will be the supplied width and height until the image is loaded. Note: on non-HTML platforms, this spawns a new thread for each loaded image. Thus, attempts to load large numbers of remote images simultaneously may result in poor performance.
    • getSound

      public abstract Sound getSound(String path)
      Asynchronously loads and returns a short sound effect.

      Note: if a request to play the sound is made before the sound is loaded, it will be noted and the sound will be played when loading has completed.

      Parameters:
      path - the path to the sound resource. NOTE: this should not include a file extension, PlayN will automatically add .mp3, (or .caf on iOS).
    • getMusic

      public Sound getMusic(String path)
      Asynchronously loads and returns a music resource. On some platforms, the backend will use a different implementation from getSound(java.lang.String) which is better suited to the much larger size of music audio data.

      Note: if a request to play the sound is made before the sound is loaded, it will be noted and the sound will be played when loading has completed.

      Parameters:
      path - the path to the sound resource. NOTE: this should not include a file extension, PlayN will automatically add .mp3, (or .caf on iOS).
    • getTextSync

      public abstract String getTextSync(String path) throws Exception
      Loads and returns a UTF-8 encoded text asset.
      Parameters:
      path - the path to the text asset.
      Throws:
      Exception - if there is an error loading the text (for example, if it does not exist).
      UnsupportedOperationException - on platforms that cannot support synchronous asset loading (e.g. HTML5 and Flash).
    • getText

      public RFuture<String> getText(String path)
      Loads UTF-8 encoded text asynchronously. The returned state instance provides a means to listen for the arrival of the text.
      Parameters:
      path - the path to the text asset.
    • getBytesSync

      public abstract ByteBuffer getBytesSync(String path) throws Exception
      Loads and returns the raw bytes of the asset - useful for custom binary formatted files.
      Parameters:
      path - the path to the text asset.
      Throws:
      Exception - if there is an error loading the data (for example, if it does not exist).
      UnsupportedOperationException - on platforms that cannot support synchronous asset loading (e.g. HTML5 and Flash).
    • getBytes

      public RFuture<ByteBuffer> getBytes(String path)
      Loads binary data asynchronously. The returned state instance provides a means to listen for the arrival of the data.
      Parameters:
      path - the path to the binary asset.