org.andengine.opengl.texture.region.TextureRegion Java Examples

The following examples show how to use org.andengine.opengl.texture.region.TextureRegion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceLoader.java    From sopa with Apache License 2.0 6 votes vote down vote up
Map<Character, TextureRegion> getTileTextures() {

        Map<Character, TextureRegion> regionMap = new HashMap<>();
        regionMap.put('s', getTexture("scenes/game/bordersStart.png"));

        regionMap.put('f', getTexture("scenes/game/bordersFinish.png"));
        regionMap.put('o', getTexture("scenes/game/o.png"));
        regionMap.put('a', getTexture("scenes/game/a.png"));
        regionMap.put('u', getTexture("scenes/game/u.png"));
        regionMap.put('c', getTexture("scenes/game/c.png"));
        regionMap.put('e', getTexture("scenes/game/e.png"));
        regionMap.put('g', getTexture("scenes/game/g.png"));
        regionMap.put('i', getTexture("scenes/game/i.png"));
        regionMap.put('S', getTexture("scenes/game/bordersStart_filled.png"));
        regionMap.put('F', getTexture("scenes/game/bordersFinish_filled.png"));
        regionMap.put('O', getTexture("scenes/game/o.png"));
        regionMap.put('A', getTexture("scenes/game/a_filled.png"));
        regionMap.put('U', getTexture("scenes/game/u_filled.png"));
        regionMap.put('C', getTexture("scenes/game/c_filled.png"));
        regionMap.put('E', getTexture("scenes/game/e_filled.png"));
        regionMap.put('G', getTexture("scenes/game/g_filled.png"));
        regionMap.put('I', getTexture("scenes/game/i_filled.png"));

        return regionMap;
    }
 
Example #2
Source File: ResourceLoader.java    From sopa with Apache License 2.0 6 votes vote down vote up
TextureRegion getTexture(final String path) {

        try {
            ITexture texture = new BitmapTexture(textureManager, new IInputStreamOpener() {

                        @Override
                        public InputStream open() throws IOException {

                            return assetManager.open(path);
                        }
                    }, TextureOptions.BILINEAR);

            return TextureRegionFactory.extractFromTexture(texture);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
 
Example #3
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
/**
 * Loads all files from a given assets directory (in alphabetical order) as consecutive tiles of an {@link TiledTextureRegion}.
 *
 * @param pBuildableBitmapTextureAtlas
 * @param pAssetManager
 * @param pAssetSubdirectory to load all files from "gfx/flowers" put "flowers" here (assuming, that you've used {@link BitmapTextureAtlasTextureRegionFactory#setAssetBasePath(String)} with "gfx/" before.)
 * @return
 */
public static TiledTextureRegion createTiledFromAssetDirectory(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetSubdirectory) {
	final String[] files;
	try {
		files = pAssetManager.list(BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetSubdirectory);
	} catch (final IOException e) {
		throw new AndEngineRuntimeException("Listing assets subdirectory: '" + BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetSubdirectory + "' failed. Does it exist?", e);
	}
	final int fileCount = files.length;
	final TextureRegion[] textures = new TextureRegion[fileCount];

	for (int i = 0; i < fileCount; i++) {
		final String assetPath = pAssetSubdirectory + "/" + files[i];
		textures[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pAssetManager, assetPath);
	}

	return new TiledTextureRegion(pBuildableBitmapTextureAtlas, textures);
}
 
Example #4
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 6 votes vote down vote up
/**
 * Loads all files from a given assets directory (in alphabetical order) as consecutive tiles of an {@link TiledTextureRegion}.
 *
 * @param pBuildableBitmapTextureAtlas
 * @param pAssetManager
 * @param pAssetSubdirectory to load all files from "gfx/flowers" put "flowers" here (assuming, that you've used {@link BitmapTextureAtlasTextureRegionFactory#setAssetBasePath(String)} with "gfx/" before.)
 * @return
 */
public static TiledTextureRegion createTiledFromAssetDirectory(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetSubdirectory) {
	final String[] files;
	try {
		files = pAssetManager.list(BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetSubdirectory);
	} catch (final IOException e) {
		throw new AndEngineRuntimeException("Listing assets subdirectory: '" + BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetSubdirectory + "' failed. Does it exist?", e);
	}
	final int fileCount = files.length;
	final TextureRegion[] textures = new TextureRegion[fileCount];

	for (int i = 0; i < fileCount; i++) {
		final String assetPath = pAssetSubdirectory + "/" + files[i];
		textures[i] = BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pAssetManager, assetPath);
	}

	return new TiledTextureRegion(pBuildableBitmapTextureAtlas, textures);
}
 
Example #5
Source File: GameFieldView.java    From sopa with Apache License 2.0 5 votes vote down vote up
GameFieldView(float pX, float pY, float spacePerTile, GameService gameService,
    Map<Character, TextureRegion> regionMap, VertexBufferObjectManager vbom, ITextureRegion tilesBorderRegion) {

    super(pX, pY);
    this.gameService = gameService;
    this.spacePerTile = spacePerTile;
    this.tileRegionMap = regionMap;
    this.vbom = vbom;
    this.tilesBorderRegion = tilesBorderRegion;
}
 
Example #6
Source File: ResourcesManager.java    From sopa with Apache License 2.0 5 votes vote down vote up
private void unloadGameSceneTextures() {

        for (TextureRegion textureRegion : regionTileMap.values()) {
            textureRegion.getTexture().unload();
        }

        restartRegion.getTexture().unload();
        tilesBorderRegion.getTexture().unload();
        scoreFont.getTexture().unload();
        scoreFont = null;
        minMovesFont.unload();
        minMovesFont = null;
        levelFont.unload();
        levelFont = null;
    }
 
Example #7
Source File: ResourcesManager.java    From sopa with Apache License 2.0 5 votes vote down vote up
private void loadGameSceneGraphics() {

        prepareTextures();
        regionTileMap = this.resourceLoader.getTileTextures();

        for (TextureRegion textureRegion : regionTileMap.values()) {
            textureRegion.getTexture().load();
        }

        tilesBorderRegion.getTexture().load();
        restartRegion.getTexture().load();
    }
 
Example #8
Source File: BuildableTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public static <T extends ITextureAtlasSource, A extends ITextureAtlas<T>> TextureRegion createFromSource(final BuildableTextureAtlas<T, A> pBuildableTextureAtlas, final T pTextureAtlasSource, final boolean pRotated) {
	final TextureRegion textureRegion = new TextureRegion(pBuildableTextureAtlas, 0, 0, pTextureAtlasSource.getTextureWidth(), pTextureAtlasSource.getTextureHeight(), pRotated);
	pBuildableTextureAtlas.addTextureAtlasSource(pTextureAtlasSource, new Callback<T>() {
		@Override
		public void onCallback(final T pCallbackValue) {
			textureRegion.setTexturePosition(pCallbackValue.getTextureX(), pCallbackValue.getTextureY());
		}
	});
	return textureRegion;
}
 
Example #9
Source File: NineSliceSprite.java    From tilt-game-android with MIT License 5 votes vote down vote up
public NineSliceSprite(final float pX, final float pY, final float pWidth, final float pHeight, final ITextureRegion pTextureRegion, final float pInsetLeft, final float pInsetTop, final float pInsetRight, final float pInsetBottom, final VertexBufferObjectManager pVertexBufferObjectManager, final ShaderProgram pShaderProgram) {
	super(pX, pY, pWidth, pHeight);

	this.mTextureRegion = pTextureRegion;
	this.mInsetLeft = pInsetLeft;
	this.mInsetTop = pInsetTop;
	this.mInsetRight = pInsetRight;
	this.mInsetBottom = pInsetBottom;

	final ITexture texture = pTextureRegion.getTexture();
	this.mSpriteBatch = new SpriteBatch(texture, NINESLICESPRITE_CHILD_COUNT, pVertexBufferObjectManager, pShaderProgram);

	this.mTopLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mTopCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mTopRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mCenterLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mCenterRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mBottomLeftTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mBottomCenterTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);
	this.mBottomRightTextureRegion = new TextureRegion(texture, 0, 0, 0, 0);

	this.updateTextureRegions();
	this.updateVertices();

	this.attachChild(this.mSpriteBatch);
}
 
Example #10
Source File: BuildableTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 5 votes vote down vote up
public static <T extends ITextureAtlasSource, A extends ITextureAtlas<T>> TextureRegion createFromSource(final BuildableTextureAtlas<T, A> pBuildableTextureAtlas, final T pTextureAtlasSource, final boolean pRotated) {
	final TextureRegion textureRegion = new TextureRegion(pBuildableTextureAtlas, 0, 0, pTextureAtlasSource.getTextureWidth(), pTextureAtlasSource.getTextureHeight(), pRotated);
	pBuildableTextureAtlas.addTextureAtlasSource(pTextureAtlasSource, new Callback<T>() {
		@Override
		public void onCallback(final T pCallbackValue) {
			textureRegion.setTexturePosition(pCallbackValue.getTextureX(), pCallbackValue.getTextureY());
		}
	});
	return textureRegion;
}
 
Example #11
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Resources pResources, final int pDrawableResourceID, final boolean pRotated) {
	final IBitmapTextureAtlasSource bitmapTextureAtlasSource = ResourceBitmapTextureAtlasSource.create(pResources, pDrawableResourceID);
	return BitmapTextureAtlasTextureRegionFactory.createFromSource(pBuildableBitmapTextureAtlas, bitmapTextureAtlasSource, pRotated);
}
 
Example #12
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final String pAssetPath) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pContext.getAssets(), pAssetPath);
}
 
Example #13
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetPath) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pAssetManager, pAssetPath, false);
}
 
Example #14
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final String pAssetPath, final boolean pRotated) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pContext.getAssets(), pAssetPath, pRotated);
}
 
Example #15
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetPath, final boolean pRotated) {
	final IBitmapTextureAtlasSource bitmapTextureAtlasSource = AssetBitmapTextureAtlasSource.create(pAssetManager, BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetPath);
	return BitmapTextureAtlasTextureRegionFactory.createFromSource(pBuildableBitmapTextureAtlas, bitmapTextureAtlasSource, pRotated);
}
 
Example #16
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID);
}
 
Example #17
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Resources pResources, final int pDrawableResourceID) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pResources, pDrawableResourceID, false);
}
 
Example #18
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID, final boolean pRotated) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID, pRotated);
}
 
Example #19
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromResource(final BitmapTextureAtlas pBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID, final int pTextureX, final int pTextureY) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID, pTextureX, pTextureY);
}
 
Example #20
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromSource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource) {
	return BitmapTextureAtlasTextureRegionFactory.createFromSource(pBuildableBitmapTextureAtlas, pBitmapTextureAtlasSource, false);
}
 
Example #21
Source File: BitmapTextureAtlasTextureRegionFactory.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static TextureRegion createFromSource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final boolean pRotated) {
	return BuildableTextureAtlasTextureRegionFactory.createFromSource(pBuildableBitmapTextureAtlas, pBitmapTextureAtlasSource, pRotated);
}
 
Example #22
Source File: GameFieldView.java    From sopa with Apache License 2.0 4 votes vote down vote up
void addTiles(boolean finished) {

        int tileIndex;

        if (finished) {
            tileIndex = 1;
        } else {
            tileIndex = 0;
        }

        detachChildren();

        if (active) {
            oneModifierFinished(true);
        }

        Tile[][] field = gameService.getLevel().getField();
        int width = field.length;
        int heigth = field[0].length;
        tileSprites = new TileSprite[width][heigth];

        int tilePositionY = 0;

        for (int y = 0; y < heigth; y++) {
            int tilePositionX = 0;

            for (int x = 0; x < width; x++) {
                if (field[x][y].getShortcut() != 'n') {
                    TextureRegion pTextureRegion = tileRegionMap.get(field[x][y].getShortcut());
                    TextureRegion pTextureRegionFilled = tileRegionMap.get(Character.toUpperCase(
                                field[x][y].getShortcut()));
                    List<ITextureRegion> textureRegions = Arrays.<ITextureRegion>asList(pTextureRegion,
                            pTextureRegionFilled);

                    switch (field[x][y].getTileType()) {
                        case PUZZLE:

                            TileSprite tileSprite = new TileSprite(tilePositionX, tilePositionY, spacePerTile,
                                    spacePerTile, textureRegions, vbom);
                            tileSprite.setITextureRegionIndex(tileIndex);
                            attachChild(tileSprite);
                            tileSprites[x][y] = tileSprite;
                            break;

                        case FINISH:

                            TileSprite finish = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions,
                                    field);
                            finish.setITextureRegionIndex(tileIndex);
                            break;

                        case START:

                            TileSprite start = createFinishAnsStart(x, y, tilePositionX, tilePositionY, textureRegions,
                                    field);
                            start.setITextureRegionIndex(tileIndex);
                            break;

                        default:
                            break;
                    }
                }

                tilePositionX += spacePerTile;
            }

            tilePositionY += spacePerTile;
        }

        attachChild(new Sprite(spacePerTile, spacePerTile, spacePerTile * (width - 2), spacePerTile * (width - 2),
                tilesBorderRegion, vbom));
    }
 
Example #23
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromResource(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBuildableBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID);
}
 
Example #24
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromAsset(final BitmapTextureAtlas pBitmapTextureAtlas, final Context pContext, final String pAssetPath, final int pTextureX, final int pTextureY) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBitmapTextureAtlas, pContext.getAssets(), pAssetPath, pTextureX, pTextureY);
}
 
Example #25
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromAsset(final BitmapTextureAtlas pBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetPath, final int pTextureX, final int pTextureY) {
	final IBitmapTextureAtlasSource bitmapTextureAtlasSource = AssetBitmapTextureAtlasSource.create(pAssetManager, BitmapTextureAtlasTextureRegionFactory.sAssetBasePath + pAssetPath);
	return BitmapTextureAtlasTextureRegionFactory.createFromSource(pBitmapTextureAtlas, bitmapTextureAtlasSource, pTextureX, pTextureY);
}
 
Example #26
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromResource(final BitmapTextureAtlas pBitmapTextureAtlas, final Context pContext, final int pDrawableResourceID, final int pTextureX, final int pTextureY) {
	return BitmapTextureAtlasTextureRegionFactory.createFromResource(pBitmapTextureAtlas, pContext.getResources(), pDrawableResourceID, pTextureX, pTextureY);
}
 
Example #27
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromResource(final BitmapTextureAtlas pBitmapTextureAtlas, final Resources pResources, final int pDrawableResourceID, final int pTextureX, final int pTextureY) {
	final IBitmapTextureAtlasSource bitmapTextureAtlasSource = ResourceBitmapTextureAtlasSource.create(pResources, pDrawableResourceID);
	return BitmapTextureAtlasTextureRegionFactory.createFromSource(pBitmapTextureAtlas, bitmapTextureAtlasSource, pTextureX, pTextureY);
}
 
Example #28
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromSource(final BitmapTextureAtlas pBitmapTextureAtlas, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final int pTextureX, final int pTextureY) {
	return TextureRegionFactory.createFromSource(pBitmapTextureAtlas, pBitmapTextureAtlasSource, pTextureX, pTextureY);
}
 
Example #29
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final Context pContext, final String pAssetPath) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pContext.getAssets(), pAssetPath);
}
 
Example #30
Source File: BitmapTextureAtlasTextureRegionFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static TextureRegion createFromAsset(final BuildableBitmapTextureAtlas pBuildableBitmapTextureAtlas, final AssetManager pAssetManager, final String pAssetPath) {
	return BitmapTextureAtlasTextureRegionFactory.createFromAsset(pBuildableBitmapTextureAtlas, pAssetManager, pAssetPath, false);
}