Game Development Reference
In-Depth Information
// Initialize controller and renderer
worldController = new WorldController();
worldRenderer = new WorldRenderer(worldController);
}
@Override
public void resume () {
Assets.instance.init(new AssetManager());
paused = false;
}
@Override
public void dispose () {
worldRenderer.dispose();
Assets.instance.dispose();
}
In create() , we instantiate a new AssetManager object and pass it to the init()
method of our Assets class. Note that we initialized AssetManager before
WorldController is created so that our assets are loaded and ready to be accessed.
Remember, an instance of our class does already exist and can be directly accessed
through the instance variable. In resume() , we actually do the exact same that we
did in create() ; as for Android, the context loss requires all assets to be reloaded
when resumed. Finally in dispose() , we call the dispose() method of our Assets
class, which in turn delegates this request to its internally stored instance of the
asset manager.
The final change will be to replace our test sprites with the ones from the texture
atlas. Add the following two imports to WorldController :
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.utils.Array;
After this, apply the modifications shown in the following code:
private void initTestObjects () {
// Create new array for 5 sprites
testSprites = new Sprite[5];
// Create a list of texture regions
Array<TextureRegion> regions = new Array<TextureRegion>();
regions.add(Assets.instance.bunny.head);
regions.add(Assets.instance.feather.feather);
regions.add(Assets.instance.goldCoin.goldCoin);
// Create new sprites using a random texture region
 
Search WWH ::




Custom Search