How to handle many updating objects efficiently in C#?

后端 未结 6 1189
感情败类
感情败类 2021-01-05 00:34

I\'m developing a 2D overhead shooter game using C# and XNA. I have a class that I\'ll call \"bullet\" and need to update many of these instances every fraction of a second.

6条回答
  •  感动是毒
    2021-01-05 01:16

    You may find the flyweight design pattern useful. There need be only one bullet object, but multiple flyweights may specify different positions and velocities for it. The flyweights can be stored in a preallocated array (say, 100) and flagged as active or not.

    That should eliminate garbage-collection completely, and may reduce the space necessary for tracking each bullet's malleable properties.

提交回复
热议问题