libgdx API

com.badlogic.gdx.assets
Class AssetManager

java.lang.Object
  extended by com.badlogic.gdx.assets.AssetManager
All Implemented Interfaces:
Disposable

public class AssetManager
extends java.lang.Object
implements Disposable

Loads and stores assets like textures, bitmapfonts, tile maps, sounds, music and so on.

Author:
mzechner

Constructor Summary
AssetManager()
          Creates a new AssetManager with all default loaders.
AssetManager(FileHandleResolver resolver)
          Creates a new AssetManager with all default loaders.
 
Method Summary
 void clear()
          Clears and disposes all assets and the preloading queue.
<T> boolean
containsAsset(T asset)
           
 void dispose()
          Disposes all assets in the manager and stops all asynchronous loading.
 void finishLoading()
          blocks until all assets are loaded.
<T> T
get(java.lang.String fileName)
           
<T> T
get(java.lang.String fileName, java.lang.Class<T> type)
           
<T> java.lang.String
getAssetFileName(T asset)
           
 Array<java.lang.String> getAssetNames()
           
 java.lang.Class getAssetType(java.lang.String fileName)
           
 Array<java.lang.String> getDependencies(java.lang.String fileName)
           
 java.lang.String getDiagnostics()
           
 int getLoadedAssets()
           
 Logger getLogger()
           
 float getProgress()
           
 int getQueuedAssets()
           
 int getReferenceCount(java.lang.String fileName)
          Returns the reference count of an asset.
 boolean isLoaded(java.lang.String fileName)
           
 boolean isLoaded(java.lang.String fileName, java.lang.Class type)
           
 void load(AssetDescriptor desc)
          Adds the given asset to the loading queue of the AssetManager.
<T> void
load(java.lang.String fileName, java.lang.Class<T> type)
          Adds the given asset to the loading queue of the AssetManager.
<T> void
load(java.lang.String fileName, java.lang.Class<T> type, AssetLoaderParameters<T> parameter)
          Adds the given asset to the loading queue of the AssetManager.
 void setErrorListener(AssetErrorListener listener)
          Sets an AssetErrorListener to be invoked in case loading an asset failed.
<T,P extends AssetLoaderParameters<T>>
void
setLoader(java.lang.Class<T> type, AssetLoader<T,P> loader)
          Sets a new AssetLoader for the given type.
 void setReferenceCount(java.lang.String fileName, int refCount)
          Sets the reference count of an asset.
 void unload(java.lang.String fileName)
          Removes the asset and all its dependencies if they are not used by other assets.
 boolean update()
          Updates the AssetManager, keeping it loading any assets in the preload queue.
 boolean update(int millis)
          Updates the AssetManager continuously for the specified number of milliseconds, yeilding the CPU to the loading thread between updates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AssetManager

public AssetManager()
Creates a new AssetManager with all default loaders.


AssetManager

public AssetManager(FileHandleResolver resolver)
Creates a new AssetManager with all default loaders.

Method Detail

get

public <T> T get(java.lang.String fileName)
Parameters:
fileName - the asset file name
Returns:
the asset

get

public <T> T get(java.lang.String fileName,
                 java.lang.Class<T> type)
Parameters:
fileName - the asset file name
type - the asset type
Returns:
the asset

unload

public void unload(java.lang.String fileName)
Removes the asset and all its dependencies if they are not used by other assets.

Parameters:
fileName - the file name

containsAsset

public <T> boolean containsAsset(T asset)
Parameters:
asset - the asset
Returns:
whether the asset is contained in this manager

getAssetFileName

public <T> java.lang.String getAssetFileName(T asset)
Parameters:
asset - the asset
Returns:
the filename of the asset or null

isLoaded

public boolean isLoaded(java.lang.String fileName)
Parameters:
fileName - the file name of the asset
Returns:
whether the asset is loaded

isLoaded

public boolean isLoaded(java.lang.String fileName,
                        java.lang.Class type)
Parameters:
fileName - the file name of the asset
Returns:
whether the asset is loaded

load

public <T> void load(java.lang.String fileName,
                     java.lang.Class<T> type)
Adds the given asset to the loading queue of the AssetManager.

Parameters:
fileName - the file name (interpretation depends on AssetLoader)
type - the type of the asset.

load

public <T> void load(java.lang.String fileName,
                     java.lang.Class<T> type,
                     AssetLoaderParameters<T> parameter)
Adds the given asset to the loading queue of the AssetManager.

Parameters:
fileName - the file name (interpretation depends on AssetLoader)
type - the type of the asset.
parameter - parameters for the AssetLoader.

load

public void load(AssetDescriptor desc)
Adds the given asset to the loading queue of the AssetManager.

Parameters:
desc - the AssetDescriptor

update

public boolean update()
Updates the AssetManager, keeping it loading any assets in the preload queue.

Returns:
true if all loading is finished.

update

public boolean update(int millis)
Updates the AssetManager continuously for the specified number of milliseconds, yeilding the CPU to the loading thread between updates. This may block for less time if all loading tasks are complete. This may block for more time if the portion of a single task that happens in the GL thread takes a long time.

Returns:
true if all loading is finished.

finishLoading

public void finishLoading()
blocks until all assets are loaded.


setLoader

public <T,P extends AssetLoaderParameters<T>> void setLoader(java.lang.Class<T> type,
                                                             AssetLoader<T,P> loader)
Sets a new AssetLoader for the given type.

Parameters:
type - the type of the asset
loader - the loader

getLoadedAssets

public int getLoadedAssets()
Returns:
the number of loaded assets

getQueuedAssets

public int getQueuedAssets()
Returns:
the number of currently queued assets

getProgress

public float getProgress()
Returns:
the progress in percent of completion.

setErrorListener

public void setErrorListener(AssetErrorListener listener)
Sets an AssetErrorListener to be invoked in case loading an asset failed.

Parameters:
listener - the listener or null

dispose

public void dispose()
Disposes all assets in the manager and stops all asynchronous loading.

Specified by:
dispose in interface Disposable

clear

public void clear()
Clears and disposes all assets and the preloading queue.


getLogger

public Logger getLogger()
Returns:
the Logger used by the AssetManager

getReferenceCount

public int getReferenceCount(java.lang.String fileName)
Returns the reference count of an asset.

Parameters:
fileName -

setReferenceCount

public void setReferenceCount(java.lang.String fileName,
                              int refCount)
Sets the reference count of an asset.

Parameters:
fileName -

getDiagnostics

public java.lang.String getDiagnostics()
Returns:
a string containg ref count and dependency information for all assets.

getAssetNames

public Array<java.lang.String> getAssetNames()
Returns:
the file names of all loaded assets.

getDependencies

public Array<java.lang.String> getDependencies(java.lang.String fileName)
Returns:
the dependencies of an asset or null if the asset has no dependencies.

getAssetType

public java.lang.Class getAssetType(java.lang.String fileName)
Returns:
the type of a loaded asset.

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)