Keeping track of unnamed objects

后端 未结 1 1070
太阳男子
太阳男子 2021-01-25 21:24

I want to make a top-down 2d shooting game using libgdx. There will be a lot of bullet objects that I want to keep track of and dispose when they go off the screen. I was thinki

相关标签:
1条回答
  • 2021-01-25 21:36

    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).

    0 讨论(0)
提交回复
热议问题