Package playn.core
Class Assets
java.lang.Object
playn.core.Assets
Fetches and returns assets.
-
Method Summary
Modifier and TypeMethodDescriptionLoads binary data asynchronously.abstract ByteBuffer
getBytesSync
(String path) Loads and returns the raw bytes of the asset - useful for custom binary formatted files.Asynchronously loads and returns an image.getImageSync
(String path) Synchronously loads and returns an image.Asynchronously loads and returns a music resource.getRemoteImage
(String url) Asynchronously loads and returns the image at the specified URL.getRemoteImage
(String url, int width, int height) Asynchronously loads and returns the image at the specified URL.abstract Sound
Asynchronously loads and returns a short sound effect.Loads UTF-8 encoded text asynchronously.abstract String
getTextSync
(String path) Loads and returns a UTF-8 encoded text asset.
-
Method Details
-
getImageSync
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
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. UseImage.state
to be notified when loading succeeds or fails.- Parameters:
path
- the path to the image asset.
-
getRemoteImage
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
Asynchronously loads and returns the image at the specified URL. The width and height of the image will be the suppliedwidth
andheight
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
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
Asynchronously loads and returns a music resource. On some platforms, the backend will use a different implementation fromgetSound(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
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
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
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
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.
-