Skip to content

Commit

Permalink
Added createTiledFromAssetDirectory() method to BitmapTextureAtlasTex…
Browse files Browse the repository at this point in the history
…tureRegionFactory

This method allows to load mutliple assets from a given directory to a
single ITiledTextureRegion.
  • Loading branch information
nazgee committed May 7, 2012
1 parent dcdeb80 commit ce7742b
Showing 1 changed file with 32 additions and 0 deletions.
@@ -1,13 +1,17 @@
package org.andengine.opengl.texture.atlas.bitmap;


import java.io.IOException;

import org.andengine.opengl.texture.atlas.bitmap.source.AssetBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.bitmap.source.IBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.bitmap.source.ResourceBitmapTextureAtlasSource;
import org.andengine.opengl.texture.atlas.buildable.BuildableTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.texture.region.TextureRegionFactory;
import org.andengine.opengl.texture.region.TiledTextureRegion;
import org.andengine.util.exception.AndEngineRuntimeException;

import android.content.Context;
import android.content.res.AssetManager;
Expand Down Expand Up @@ -147,6 +151,34 @@ public static TiledTextureRegion createTiledFromAsset(final BuildableBitmapTextu
return BitmapTextureAtlasTextureRegionFactory.createTiledFromSource(pBuildableBitmapTextureAtlas, bitmapTextureAtlasSource, pTileColumns, pTileRows);
}

/**
* Loads all files from a given assets directory (in alphabetical order) as
* consecutive tiles of ITiledTextureRegion which it returns
*
* @param pBuildableBitmapTextureAtlas
* @param pAssetManager
* @param pAssetsSubdirectory to load all files from "gfx/flowers" put "flowers" here (assuming, that you've used setAssetBasePath("gfx/") on this factory)
* @return
*/
public static ITiledTextureRegion createTiledFromAssetDirectory(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetsSubdirectory) {
ITextureRegion textures[];
String[] files;

try {
files = pAssetManager.list(getAssetBasePath() + pAssetsSubdirectory);
} catch (IOException ioex) {
throw new AndEngineRuntimeException("Listing assets directory failed! " + getAssetBasePath() + pAssetsSubdirectory + " does not exist?", ioex);
}
textures = new ITextureRegion[files.length];

for (int i = 0; i < files.length; i++) {
String file = pAssetsSubdirectory + "/" + files[i];
textures[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pAssetManager, file);
}

return new TiledTextureRegion(pBuildableBitmapTextureAtlas, textures);
}


public static ITextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID) {
return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID);
Expand Down

0 comments on commit ce7742b

Please sign in to comment.