Keeping track of unnamed objects

冷暖自知 提交于 2019-12-02 13:20:44

Using an object pool is a better approach.

The idea of an object pool is simple and fits perfectly for your needs in this case. The pool handles creating and storing the Bullet objects. All you have to do is to call the obtain method of the pool when you need a bullet (User shoots) and call the recycle method of the pool for this bullet when it's no longer needed in the game (Goes offscreen).

Here is a code example for a pool taken from AndEngine's source. You can use it to learn how it works and make your own pool class (Or use this one).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!