Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added createTiledFromAssetDirectory() method to SVGBitmapTextureAtlasTextureRegionFactory #3

Open
wants to merge 2 commits into
base: GLES2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.andengine.extension.svg.opengl.texture.atlas.bitmap;

import java.io.IOException;

import org.andengine.extension.svg.adt.ISVGColorMapper;
import org.andengine.extension.svg.adt.SVG;
import org.andengine.extension.svg.opengl.texture.atlas.bitmap.source.SVGAssetBitmapTextureAtlasSource;
Expand All @@ -12,6 +14,7 @@
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 android.content.Context;

Expand Down Expand Up @@ -56,6 +59,10 @@ public static void setAssetBasePath(final String pAssetBasePath) {
}
}

public static String getAssetBasePath() {
return sAssetBasePath;
}

/**
* @param pScaleFactor must be > 0;
*/
Expand Down Expand Up @@ -176,6 +183,36 @@ public static ITiledTextureRegion createTiledFromAsset(final BuildableBitmapText
return BuildableTextureAtlasTextureRegionFactory.createTiledFromSource(pBuildableBitmapTextureAtlas, textureSource, pTileColumns, pTileRows);
}

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

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

int i = 0;
for (String file : files) {
file = pAssetsSubdirectory + "/" + file;
textures[i++] = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pContext, file, pWidth, pHeight);
}

return new TiledTextureRegion(pBuildableBitmapTextureAtlas, textures);
}

public static ITextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final int pRawResourceID, final int pWidth, final int pHeight) {
return SVGBitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pContext, pRawResourceID, pWidth, pHeight, null);
Expand Down