Skip to content

Commit

Permalink
Merge pull request nicolasgramlich#99 from nazgee/for-nicolas-directo…
Browse files Browse the repository at this point in the history
…rytiles

Added createTiledFromAssetDirectory() method to BitmapTextureAtlasTextureRegionFactory.
  • Loading branch information
nicolasgramlich committed May 14, 2012
2 parents d0856cb + ce7742b commit e799e9e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/org/andengine/audio/music/MusicFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}

public static String getAssetBasePath() {
return MusicFactory.sAssetBasePath;
}

public static void onCreate() {
MusicFactory.setAssetBasePath("");
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/andengine/audio/sound/SoundFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}

public static String getAssetBasePath() {
return SoundFactory.sAssetBasePath;
}

public static void onCreate() {
SoundFactory.setAssetBasePath("");
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/andengine/opengl/font/FontFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}

public static String getAssetBasePath() {
return FontFactory.sAssetBasePath;
}

public static void onCreate() {
FontFactory.setAssetBasePath("");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 @@ -51,6 +55,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}

public static String getAssetBasePath() {
return BitmapTextureAtlasTextureRegionFactory.sAssetBasePath;
}

public static void reset() {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("");
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/org/andengine/util/level/LevelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void setAssetBasePath(final String pAssetBasePath) {
}
}

public String getAssetBasePath() {
return mAssetBasePath;
}

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
Expand Down

0 comments on commit e799e9e

Please sign in to comment.