本文整理汇总了Java中org.andengine.opengl.texture.region.TextureRegion类的典型用法代码示例。如果您正苦于以下问题:Java TextureRegion类的具体用法?Java TextureRegion怎么用?Java TextureRegion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextureRegion类属于org.andengine.opengl.texture.region包,在下文中一共展示了TextureRegion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextureFromAsset
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
private TextureRegion getTextureFromAsset(final String path) {
try {
texture = new BitmapTexture(engine.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
return context.getAssets().open("gfx/" + path); // path of the image
}
}, TextureOptions.BILINEAR);
texture.load();
return TextureRegionFactory.extractFromTexture(texture);
} catch (IOException e) {
e.printStackTrace();
Log.e(ASSETS_ERROR_TAG, e.toString());
}
return null;
}
示例2: createTiledFromAssetDirectory
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
/**
* 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);
}
示例3: populateScene
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
@Override
public void populateScene() {
AbstractGameActivity activity = getActivity();
if (activity == null) {
return;
}
ResourcesManager resourcesManager = activity.getResourcesManager();
try {
resourcesManager.uploadTexture("gfx/splash.jpg");
} catch (IOException e) {
return;
}
TextureRegion splashRegion = TextureRegionFactory.extractFromTexture(
resourcesManager.getTexture("gfx/splash.jpg"));
mSplash = new Sprite(0, 0, splashRegion, resourcesManager.getVertexBufferObjectManager()) {
@Override
protected void preDraw(GLState pGLState, Camera pCamera) {
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
};
mSplash.setPosition(activity.getCameraWidth() / 2, activity.getCameraHeight() / 2);
attachChild(mSplash);
}
示例4: createBackground
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
private void createBackground() {
Logger.log(TAG, "creating menu background");
AbstractGameActivity activity = getActivity();
if (activity == null) {
return;
}
ResourcesManager manager = activity.getResourcesManager();
TextureRegion region = TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/menu_background.jpg"));
attachChild(new Sprite(activity.getCameraWidth() / 2, activity.getCameraHeight() / 2,
region, manager.getVertexBufferObjectManager()) {
@Override
protected void preDraw(GLState pGLState, Camera pCamera) {
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
});
}
示例5: createTiledFromAssetDirectory
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
/**
* 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 org.andengine.opengl.texture.atlas.bitmap.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);
}
示例6: getTextureRegionFromGlobalTileID
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
public ITextureRegion getTextureRegionFromGlobalTileID(final int pGlobalTileID) {
final int localTileID = pGlobalTileID - this.mFirstGlobalTileID;
final int tileColumn = localTileID % this.mTilesHorizontal;
final int tileRow = localTileID / this.mTilesHorizontal;
final int texturePositionX = this.mMargin + (this.mSpacing + this.mTileWidth) * tileColumn;
final int texturePositionY = this.mMargin + (this.mSpacing + this.mTileHeight) * tileRow;
return new TextureRegion(this.mTexture, texturePositionX, texturePositionY, this.mTileWidth, this.mTileHeight);
}
示例7: setSpotlight
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
public void setSpotlight(String texture) {
try {
final AssetBitmapTexture spotlight_texture = new AssetBitmapTexture(PhoeniciaContext.textureManager, PhoeniciaContext.assetManager, texture);
spotlight_texture.load();
TextureRegion spotlight_region = TextureRegionFactory.extractFromTexture(spotlight_texture);
this.clearSpotlight();
this.spotlight = new Sprite(this.getWidth()/2, this.getHeight()/2, spotlight_region, PhoeniciaContext.vboManager);
this.spotlight.setZIndex(this.guideSprite.getZIndex()-1);
this.attachChild(this.spotlight);
this.sortChildren();
} catch (IOException e) {
Debug.e("Failed to load spotlight texture: "+texture);
}
}
示例8: NineSliceSprite
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
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);
}
示例9: createFromSource
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
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;
}
示例10: populateScene
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
@Override
public void populateScene() {
AbstractGameActivity activity = getActivity();
if (activity == null) {
return;
}
ResourcesManager manager = activity.getResourcesManager();
TextureRegion backgroundRegion = TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/grass.jpg"));
ParallaxBackground background = new AutoParallaxBackground(0, 0, 0, 5);
background.attachParallaxEntity(new ParallaxBackground.ParallaxEntity(0, new Sprite(
0, activity.getCameraHeight() / 2,
backgroundRegion, manager.getVertexBufferObjectManager())));
setBackground(background);
setBackgroundEnabled(true);
/* BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(
activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
TiledTextureRegion mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(
mBitmapTextureAtlas, activity.getApplicationContext(), "gfx/hero.png", 0, 0, 4, 2);
AnimatedSprite player = new AnimatedSprite(100, 100, mPlayerTextureRegion, manager.getVertexBufferObjectManager());
player.animate(new long[]{100, 100, 100}, 5, 7, true);*/
TextureRegion playerRegion = TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/player.png"));
mPlayerSprite = new Sprite(activity.getCameraWidth() / 2, activity.getCameraHeight() / 2,
playerRegion, manager.getVertexBufferObjectManager());
mPlayerSprite.setScale(3);
attachChild(mPlayerSprite);
Random random = new SecureRandom();
for (int i = 0; i < 5; i++) {
TextureRegion bombRegion = TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/bomb.png"));
int width = random.nextInt(activity.getCameraWidth());
int height = random.nextInt(activity.getCameraHeight());
//noinspection ObjectAllocationInLoop
Sprite sprite = new Sprite(width, height, bombRegion, manager.getVertexBufferObjectManager());
mBombsSprite.add(sprite);
attachChild(sprite);
}
}
示例11: createMenuChildScene
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
private void createMenuChildScene() {
Logger.log(TAG, "creating menu items");
AbstractGameActivity activity = getActivity();
if (activity == null) {
return;
}
ResourcesManager manager = activity.getResourcesManager();
mMenuScene = new MenuScene(activity.getEngine().getCamera());
mMenuScene.setPosition(activity.getCameraWidth() / 2, activity.getCameraHeight() / 2);
TextureRegion[] levelRegionS = {
TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/level1.png")),
TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/level2.png")),
TextureRegionFactory.extractFromTexture(manager.getTexture("gfx/level3.png")),
};
IMenuItem[] menuItems = {
new SpriteMenuItem(mLevels[0], levelRegionS[0], manager.getVertexBufferObjectManager()),
new SpriteMenuItem(mLevels[1], levelRegionS[1], manager.getVertexBufferObjectManager()),
new SpriteMenuItem(mLevels[2], levelRegionS[2], manager.getVertexBufferObjectManager()),
};
for (IMenuItem menuItem : menuItems) {
mMenuScene.addMenuItem(menuItem);
}
int width = activity.getCameraWidth() / 2;
int height = activity.getCameraHeight() / 2;
menuItems[0].setPosition(-width + 100, height - 100);
menuItems[1].setPosition(-width + 300, height - 100);
menuItems[2].setPosition(-width + 500, height - 100);
mMenuScene.buildAnimations();
mMenuScene.setBackgroundEnabled(false);
mMenuScene.setOnMenuItemClickListener(this);
setChildScene(mMenuScene);
}
示例12: generateEnemyShuriken
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
/**
* Generate a shuriken sent by an enemy.
* @param enemySprite
* @return
*/
public Entity generateEnemyShuriken(Sprite enemySprite) {
float rotationDegre = enemySprite.getRotation();
//Handle the fact the enemy sprites are oriented facing south.
rotationDegre = (rotationDegre + 180)%360;
double rotationRad = rotationDegre * Math.PI / 180d;
float startX = (float) Math.sin(rotationRad);
float startY = (float) Math.cos(rotationRad) * -1;
TextureRegion shurikenProjectileTexture = spriteLoader.getProjShurikenTextureRegion();
Couple<Float> enemyCenter = SpriteUtil.getCenter(enemySprite);
final Sprite sShurikenProjectile = new Sprite(enemyCenter.getX() - shurikenProjectileTexture.getWidth() / 2f,
enemyCenter.getY() - shurikenProjectileTexture.getHeight() / 2f,
shurikenProjectileTexture, this.vertextBufferObjectManager);
sShurikenProjectile.setZIndex(13);
sShurikenProjectile.setRotation(rotationDegre);
Entity shurikenProjectile = this.em.createEntity();
SpriteComponent scShurikenProj = new SpriteComponent(sShurikenProjectile, true);
scShurikenProj.defineRectangularHitboxDiff(15, 5, 15, 20);
this.em.addComponentToEntity(scShurikenProj, shurikenProjectile);
this.em.addComponentToEntity(new SelfRotationComponent(15), shurikenProjectile);
this.em.addComponentToEntity(new MoveTowardsComponent(10, startX, startY), shurikenProjectile);
this.em.addComponentToEntity(new AttackComponent(1, 2), shurikenProjectile);
gameArea.attachChild(sShurikenProjectile);
scShurikenProj.setAttached(true);
return shurikenProjectile;
}
示例13: LevelIntroHUD
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
/**
* Display level transition text pages, images and sound.
* @param game Reference to the PhoeniciaGame this HUD is running in
* @param level The level to display introduction pages for
*/
public LevelIntroHUD(final PhoeniciaGame game, final Level level) {
super(game);
this.setBackgroundEnabled(false);
this.game = game;
this.level = level;
this.current_page = 0;
this.setOnSceneTouchListener(this);
Debug.d("New level guide: "+game.locale.tour.guide.name);
this.guideSprite = new Sprite(-112, 160, game.personTiles.get(game.locale.tour.guide), PhoeniciaContext.vboManager);
this.attachChild(guideSprite);
final float messageBoxWidth = this.getWidth()-this.guideSprite.getWidth()-32;
final float messageBoxHeight = 256;
String texture = "textures/tour/tour-focus-none.png";
try {
final AssetBitmapTexture spotlight_texture = new AssetBitmapTexture(PhoeniciaContext.textureManager, PhoeniciaContext.assetManager, texture);
spotlight_texture.load();
TextureRegion spotlight_region = TextureRegionFactory.extractFromTexture(spotlight_texture);
Sprite backdrop = new Sprite(this.getWidth()/2, this.getHeight()/2, spotlight_region, PhoeniciaContext.vboManager);
backdrop.setZIndex(guideSprite.getZIndex()-1);
this.attachChild(backdrop);
this.sortChildren();
} catch (IOException e) {
Debug.e("Failed to load spotlight texture: "+texture);
}
Debug.d("New Level into guide sprite width: "+this.guideSprite.getWidth());
this.messageBox = new BorderRectangle((messageBoxWidth/2)+this.guideSprite.getWidth(), this.guideSprite.getY(), messageBoxWidth, messageBoxHeight, PhoeniciaContext.vboManager);
this.messageBox.setColor(Color.WHITE);
this.attachChild(messageBox);
this.registerTouchArea(messageBox);
ITextureRegion nextRegion = GameUI.getInstance().getNextIcon();
this.nextButton = new ButtonSprite(messageBox.getWidth() - 48, 50, nextRegion, PhoeniciaContext.vboManager);
this.nextButton.setOnClickListener(new ButtonSprite.OnClickListener() {
@Override
public void onClick(ButtonSprite buttonSprite, float v, float v1) {
if (current_page+1 < level.intro.size()) {
nextButton.setVisible(false);
showPage(current_page + 1);
} else {
finish();
}
}
});
this.nextButton.setVisible(false);
this.registerTouchArea(this.nextButton);
this.messageBox.attachChild(this.nextButton);
Debug.d("Finished instantiating LevelIntroHUD");
this.clickDetector = new ClickDetector(this);
}
示例14: MiniGameHUD
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
public MiniGameHUD(final PhoeniciaGame phoeniciaGam, final Level level, final GameTile tile) {
super(phoeniciaGam);
this.setBackgroundEnabled(false);
this.setOnAreaTouchTraversalFrontToBack();
try {
final AssetBitmapTexture spotlight_texture = new AssetBitmapTexture(PhoeniciaContext.textureManager, PhoeniciaContext.assetManager, SPOTLIGHT_NONE);
spotlight_texture.load();
TextureRegion spotlight_region = TextureRegionFactory.extractFromTexture(spotlight_texture);
Sprite spotlight = new Sprite(this.getWidth()/2, this.getHeight()/2, spotlight_region, PhoeniciaContext.vboManager);
this.attachChild(spotlight);
AssetBitmapTexture hud_texture = new AssetBitmapTexture(PhoeniciaContext.textureManager, PhoeniciaContext.assetManager, tile.game.background_texture);
hud_texture.load();
ITextureRegion background_region = TextureRegionFactory.extractFromTexture(hud_texture, 0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT);
ITextureRegion foreground_region = TextureRegionFactory.extractFromTexture(hud_texture, 0, BACKGROUND_HEIGHT, FOREGROUND_WIDTH, FOREGROUND_HEIGHT);
final float background_y = (GameActivity.CAMERA_HEIGHT/2) + (hud_texture.getHeight()/2) - (background_region.getHeight()/2);
final float foreground_y = (GameActivity.CAMERA_HEIGHT/2) - (hud_texture.getHeight()/2) + (foreground_region.getHeight()/2);
background_sprite = new Sprite(GameActivity.CAMERA_WIDTH / 2, background_y, BACKGROUND_WIDTH, BACKGROUND_HEIGHT, background_region, PhoeniciaContext.vboManager);
foreground_sprite = new Sprite(GameActivity.CAMERA_WIDTH / 2, foreground_y, FOREGROUND_WIDTH, FOREGROUND_HEIGHT, foreground_region, PhoeniciaContext.vboManager);
this.attachChild(background_sprite);
this.attachChild(foreground_sprite);
final ITextureRegion person_texture = phoeniciaGam.personTiles.get(tile.game.host);
final float host_x = (GameActivity.CAMERA_WIDTH/2) - (WINDOW_HEIGHT/2) + (person_texture.getWidth()/4);
final float host_y = (GameActivity.CAMERA_HEIGHT/2) - (WINDOW_HEIGHT/2) + (person_texture.getHeight()*2/3);
host_sprite = new Sprite(host_x, host_y, person_texture, PhoeniciaContext.vboManager);
this.attachChild(host_sprite);
content = new Entity(GameActivity.CAMERA_WIDTH / 2, GameActivity.CAMERA_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT);
this.attachChild(content);
spotlight.setZIndex(background_sprite.getZIndex()-1);
host_sprite.setZIndex(background_sprite.getZIndex() + 1);
foreground_sprite.setZIndex(background_sprite.getZIndex() + 2);
content.setZIndex(background_sprite.getZIndex() + 3);
this.sortChildren();
} catch (IOException e) {
// TODO: gracefully handle missing background
}
}
示例15: getMmenuOptionsBtnTextureRegion
import org.andengine.opengl.texture.region.TextureRegion; //导入依赖的package包/类
public TextureRegion getMmenuOptionsBtnTextureRegion() {
return mMmenuOptionsBtnTextureRegion;
}