Permalink
Browse files

Merge pull request #99 from nazgee/for-nicolas-directorytiles

Added createTiledFromAssetDirectory() method to BitmapTextureAtlasTextureRegionFactory.
  • Loading branch information...
2 parents d0856cb + ce7742b commit e799e9e33bb5049a9adf644c4ba3c215ec4a77f1 @nicolasgramlich committed May 14, 2012
@@ -45,6 +45,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}
+ public static String getAssetBasePath() {
+ return MusicFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
MusicFactory.setAssetBasePath("");
}
@@ -44,6 +44,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}
+ public static String getAssetBasePath() {
+ return SoundFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
SoundFactory.setAssetBasePath("");
}
@@ -50,6 +50,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}
+ public static String getAssetBasePath() {
+ return FontFactory.sAssetBasePath;
+ }
+
public static void onCreate() {
FontFactory.setAssetBasePath("");
}
@@ -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;
@@ -51,6 +55,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}
+ public static String getAssetBasePath() {
+ return BitmapTextureAtlasTextureRegionFactory.sAssetBasePath;
+ }
+
public static void reset() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("");
}
@@ -143,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);
@@ -76,6 +76,10 @@ public void setAssetBasePath(final String pAssetBasePath) {
}
}
+ public String getAssetBasePath() {
+ return mAssetBasePath;
+ }
+
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

0 comments on commit e799e9e

Please sign in to comment.