我想至少使用9個圖像&他們將通過池使用。但是我只能使用一個紋理池類&不能使用其他的其他。在一個通用池中使用不同的精靈紋理AndEngine
我的代碼:我愛:
public class BubblePool extends GenericPool<Bubble> {
public static BubblePool instance;
private PixelPerfectTiledTextureRegion aITiledTextureRegion;
public BubblePool(PixelPerfectTiledTextureRegion aTextureRegion) {
if (aTextureRegion == null) {
throw new IllegalArgumentException(
"The Texture Region must not be null");
}
this.aITiledTextureRegion = aTextureRegion.deepCopy();
instance = this;
}
public static BubblePool sharedBubblePool() {
// if (instance == null) {
// instance = new BubblePool();
// }
return instance;
}
protected void onHandleRecycleItem(final Bubble b) {
b.clearEntityModifiers();
b.clearUpdateHandlers();
b.setVisible(false);
b.detachSelf();
Log.v("****Bubble*****", " Recycled ");
}
@Override
protected synchronized void onHandleObtainItem(final Bubble b) {
b.reset();
// b.animate(new long[] { 110, 110, 110 }, 0, 2, true);
// e.init();// starting modifiers
b.setVisible(true);
b.setIgnoreUpdate(false);
}
@Override
protected Bubble onAllocatePoolItem() {
return new Bubble(0, 0, aITiledTextureRegion,
ResourcesManager.getInstance().vbom);
}
}
我最初&循環創建30個相同的精靈在場景更快的使用。
public void initiateBubble(
final PixelPerfectTiledTextureRegion aITiledTextureRegion) {
bubbleList = new LinkedList<Bubble>();
bubblePoolObj = new BubblePool(aITiledTextureRegion);
ArrayList<Bubble> bubbles = new ArrayList<Bubble>();
for (int i = 0; i < 30; i++) {
Bubble ee = bubblePoolObj.obtainPoolItem();
bubbles.add(ee);
}
for (Bubble easyEnemy : bubbles) {
bubblePoolObj.recyclePoolItem(easyEnemy);
}
bubbles.clear();
}
然後我打電話像
Bubble aBubble = bubblePoolObj.obtainPoolItem();
if (!aBubble.hasParent()) {
// attachChild(aEasyEnemy);
// add first layer
getChildByIndex(FIRST_LAYER).attachChild(aBubble);
}
池對象我如何只通過一個單一的池中使用不同的紋理&再利用?
希望你明白我的問題。