Creating sprite pools
The GenericPool
classes are an incredibly important part of AndEngine game design considering mobile platforms are relatively limited when it comes to hardware resources. In Android game development, the key to a smooth gameplay experience throughout a lengthy session is to create the least amount of objects as possible. This does not necessarily mean we should limit ourselves to four or five objects on the screen, it means we should consider the option of recycling objects which have already been created. This is where object pools come into play.
Getting started…
Refer to the class named SpritePool
in the code bundle.
How to do it…
The GenericPool
classes make use of a few useful methods, which make recycling objects for later use very easy. We will cover the main methods to be used here.
Constructing the SpritePool
class:
public SpritePool(ITextureRegion pTextureRegion, VertexBufferObjectManager pVertexBufferObjectManager){ this.mTextureRegion = pTextureRegion; this...