Cutting down render time with sprite groups
Sprite groups are a great addition to any AndEngine game which deals with hundreds of visible sprites on the scene at any given time. The SpriteGroup
class allows us to eliminate a large amount of overhead by grouping many sprite rendering calls into a limited number of OpenGL calls. If a school bus were to pick up a single child, drop them off at school, then pick up the next child, repeating until all children were at school, the process would take a far greater time to complete. The same goes for drawing sprites with OpenGL.
Getting started…
Refer to the class named ApplyingSpriteGroups
in the code bundle. This recipe requires an image named marble.png
, which is 32 pixels in width by 32 pixels in height.
How to do it…
When creating a SpriteGroup
for use in our games, we can treat them as an Entity
layer which is specifically meant for Sprite
objects only. The following steps explain how to create and attach Sprite
objects to a SpriteGroup
.
Creating...