Back to project page BlockBreaker.
The source code is released under:
GNU General Public License
If you think the Android project BlockBreaker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package de.hotware.blockbreaker.android.view; /*from www . j a v a2s . c o m*/ import org.andengine.entity.scene.Scene; import org.andengine.opengl.texture.region.TiledTextureRegion; import org.andengine.opengl.vbo.VertexBufferObjectManager; import org.andengine.util.adt.pool.GenericPool; import de.hotware.blockbreaker.android.view.listeners.IBlockSpriteTouchListener; import de.hotware.blockbreaker.model.Block; public class BlockSpritePool extends GenericPool<BlockSprite> { private Scene mScene; private TiledTextureRegion mTiledTextureRegion; private VertexBufferObjectManager mVertexBufferObjectManager; public BlockSpritePool(Scene pScene, TiledTextureRegion pTiledTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager) { this.mScene = pScene; this.mTiledTextureRegion = pTiledTextureRegion; this.mVertexBufferObjectManager = pVertexBufferObjectManager; } @Override protected BlockSprite onAllocatePoolItem() { BlockSprite bs = new BlockSprite(UIConstants.BASE_SPRITE_WIDTH, UIConstants.BASE_SPRITE_HEIGHT, this.mTiledTextureRegion.deepCopy(), this.mVertexBufferObjectManager); this.mScene.attachChild(bs); return bs; } @Override protected void onHandleRecycleItem(final BlockSprite pBlockSprite) { pBlockSprite.setIgnoreUpdate(true); pBlockSprite.setVisible(false); this.mScene.unregisterTouchArea(pBlockSprite); } @Override protected void onHandleObtainItem(final BlockSprite pBlockSprite) { pBlockSprite.reset(); } public BlockSprite obtainBlockSprite(final int pX, int pY, final Block pBlock, final IBlockSpriteTouchListener pBlockSpriteTouchListener) { BlockSprite bs = this.obtainPoolItem(); bs.setIgnoreUpdate(false); bs.setVisible(true); bs.setPosition(pX, pY); bs.setBlock(pBlock); bs.setBlockSpriteTouchListener(pBlockSpriteTouchListener); return bs; } }