org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory Java Examples

The following examples show how to use org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory. 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: RepeatingSpriteBackground.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
private Sprite loadSprite(final float pCameraWidth, final float pCameraHeight, final TextureManager pTextureManager, final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final VertexBufferObjectManager pVertexBufferObjectManager) throws IllegalArgumentException {
	this.mBitmapTextureAtlas = new BitmapTextureAtlas(pTextureManager, pBitmapTextureAtlasSource.getTextureWidth(), pBitmapTextureAtlasSource.getTextureHeight(), BitmapTextureFormat.RGBA_8888, TextureOptions.REPEATING_NEAREST);
	final ITextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(this.mBitmapTextureAtlas, pBitmapTextureAtlasSource, 0, 0);

	final int width = Math.round(pCameraWidth / this.mScale);
	final int height = Math.round(pCameraHeight / this.mScale);

	textureRegion.setTextureWidth(width);
	textureRegion.setTextureHeight(height);

	this.mBitmapTextureAtlas.load();

	final Sprite sprite = new Sprite(0, 0, width, height, textureRegion, pVertexBufferObjectManager);
	sprite.setScaleCenter(0, 0);
	sprite.setScale(this.mScale);
	return sprite;
}
 
Example #2
Source File: PipePair.java    From OpenFlappyBird with Do What The F*ck You Want To Public License 6 votes vote down vote up
public static void onCreateResources(SimpleBaseGameActivity activity){

		// upper pipe		
		BitmapTextureAtlas upperPipeTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 130, 60, TextureOptions.BILINEAR);
		mUpperPipeTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(upperPipeTextureAtlas, activity, "pipeupper.png", 0, 0);
		upperPipeTextureAtlas.load();

		// upper pipe section	
		BitmapTextureAtlas upperPipeSectionTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 120, 1, TextureOptions.BILINEAR);
		mUpperPipeSectionTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(upperPipeSectionTextureAtlas, activity, "pipesectionupper.png", 0, 0);
		upperPipeSectionTextureAtlas.load();


		// lower pipe		
		BitmapTextureAtlas lowerPipeTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 130, 60, TextureOptions.BILINEAR);
		mLowerPipeTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(lowerPipeTextureAtlas, activity, "pipelower.png", 0, 0);
		lowerPipeTextureAtlas.load();

		// lower pipe section	
		BitmapTextureAtlas lowerPipeSectionTextureAtlas = new BitmapTextureAtlas(activity.getTextureManager(), 120, 1, TextureOptions.BILINEAR);
		mLowerPipeSectionTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(lowerPipeSectionTextureAtlas, activity, "pipesectionlower.png", 0, 0);
		lowerPipeSectionTextureAtlas.load();
	}
 
Example #3
Source File: WorldController.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void createBackground(final Bitmap background, @Nullable final String backgroundUrl) {
    if (background == null) return;

    BitmapTextureAtlas bitmapTextureAtlas = new BitmapTextureAtlas(_engine.getTextureManager(), _width, _height, TextureOptions.BILINEAR);
    IBitmapTextureAtlasSource baseTextureSource = new EmptyBitmapTextureAtlasSource(_width, _height);

    final IBitmapTextureAtlasSource bitmapTextureAtlasSource = new BaseBitmapTextureAtlasSourceDecorator(baseTextureSource) {
        @Override
        protected void onDecorateBitmap(Canvas pCanvas) throws Exception {
            if (backgroundUrl != null) {
                Bitmap template = BitmapFactory.decodeStream(GoogleFlipGameApplication.sContext.getAssets().open(backgroundUrl));
                pCanvas.drawBitmap(template, 0, 0, mPaint);
            }

            pCanvas.drawColor(_backgroundColor);
            pCanvas.drawBitmap(background, 0, 0, mPaint);
        }

        @Override
        public BaseBitmapTextureAtlasSourceDecorator deepCopy() {
            throw new IModifier.DeepCopyNotSupportedException();
        }
    };

    ITextureRegion mDecoratedBalloonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(bitmapTextureAtlas, bitmapTextureAtlasSource,
            0, 0);
    bitmapTextureAtlas.load();

    Sprite sprite = new Sprite(0, 0, mDecoratedBalloonTextureRegion, _engine.getVertexBufferObjectManager());
    sprite.setOffsetCenter(0, 0);
    sprite.setWidth(_width);
    sprite.setHeight(_height);
    _background = new SpriteBackground(sprite);
    _engine.getScene().setBackground(_background);
}
 
Example #4
Source File: AndEngineActivity.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreateResources() throws IOException {
    mTexture = new AssetBitmapTexture(getTextureManager(), getAssets(), "player.png");
    mTextureRegion = TextureRegionFactory.extractFromTexture(mTexture);
    mTexture.load();

    mBitmapTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 100, 100, TextureOptions.BILINEAR);
    mTiledTextureRegion = BitmapTextureAtlasTextureRegionFactory
            .createTiledFromAsset(mBitmapTextureAtlas, getAssets(), "npc-oldman1.png", 0, 0, 4, 1);

    mBitmapTextureAtlas.load();
}
 
Example #5
Source File: Engine.java    From tilt-game-android with MIT License 4 votes vote down vote up
public Engine(final EngineOptions pEngineOptions) {
	/* Initialize Factory and Manager classes. */
	BitmapTextureAtlasTextureRegionFactory.reset();
	SoundFactory.onCreate();
	MusicFactory.onCreate();
	FontFactory.onCreate();
	this.mVertexBufferObjectManager.onCreate();
	this.mTextureManager.onCreate();
	this.mFontManager.onCreate();
	this.mShaderProgramManager.onCreate();

	/* Apply EngineOptions. */
	this.mEngineOptions = pEngineOptions;
	if (this.mEngineOptions.hasEngineLock()) {
		this.mEngineLock = pEngineOptions.getEngineLock();
	} else {
		this.mEngineLock = new EngineLock(false);
	}
	this.mCamera = pEngineOptions.getCamera();

	/* Touch. */
	if (this.mEngineOptions.getTouchOptions().needsMultiTouch()) {
		this.setTouchController(new MultiTouchController());
	} else {
		this.setTouchController(new SingleTouchController());
	}

	/* Audio. */
	if (this.mEngineOptions.getAudioOptions().needsSound()) {
		this.mSoundManager = new SoundManager(this.mEngineOptions.getAudioOptions().getSoundOptions().getMaxSimultaneousStreams());
	} else {
		this.mSoundManager = null;
	}
	if (this.mEngineOptions.getAudioOptions().needsMusic()) {
		this.mMusicManager = new MusicManager();
	} else {
		this.mMusicManager = null;
	}

	/* Start the UpdateThread. */
	if (this.mEngineOptions.hasUpdateThread()) {
		this.mUpdateThread = this.mEngineOptions.getUpdateThread();
	} else {
		this.mUpdateThread = new UpdateThread();
	}
	this.mUpdateThread.setEngine(this);
}
 
Example #6
Source File: Engine.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public Engine(final EngineOptions pEngineOptions) {
	/* Initialize Factory and Manager classes. */
	BitmapTextureAtlasTextureRegionFactory.reset();
	SoundFactory.onCreate();
	MusicFactory.onCreate();
	FontFactory.onCreate();
	this.mVertexBufferObjectManager.onCreate();
	this.mTextureManager.onCreate();
	this.mFontManager.onCreate();
	this.mShaderProgramManager.onCreate();

	/* Apply EngineOptions. */
	this.mEngineOptions = pEngineOptions;
	if(this.mEngineOptions.hasEngineLock()) {
		this.mEngineLock = pEngineOptions.getEngineLock();
	} else {
		this.mEngineLock = new EngineLock(false);
	}
	this.mCamera = pEngineOptions.getCamera();

	/* Touch. */
	if(this.mEngineOptions.getTouchOptions().needsMultiTouch()) {
		this.setTouchController(new MultiTouchController());
	} else {
		this.setTouchController(new SingleTouchController());
	}

	/* Audio. */
	if(this.mEngineOptions.getAudioOptions().needsSound()) {
		this.mSoundManager = new SoundManager(this.mEngineOptions.getAudioOptions().getSoundOptions().getMaxSimultaneousStreams());
	} else {
		this.mSoundManager = null;
	}
	if(this.mEngineOptions.getAudioOptions().needsMusic()) {
		this.mMusicManager = new MusicManager();
	} else {
		this.mMusicManager = null;
	}

	/* Start the UpdateThread. */
	if(this.mEngineOptions.hasUpdateThread()) {
		this.mUpdateThread = this.mEngineOptions.getUpdateThread();
	} else {
		this.mUpdateThread = new UpdateThread();
	}
	this.mUpdateThread.setEngine(this);
}