Reading another SO question it seems that DrawableGameComponent
s aren't the way forward. I took this upon myself to do a bit of research and using the Particle sample from the XNA Creators website, I decided to strip out the开发者_JAVA技巧 use of DrawableGameComponent
s. Everything compiled fine, except for the fact that I don't have DrawOrder
available and the example uses this for the particles.
How can I change the DrawOrder
as if I was using a DrawableGameComponent
?
GameComponent
s are a great tool, and can make your code much easier to use and reuse. I would disregard Andrew Russell's answer from the other SO question. It is highly biased. GameComponent
s are fine to use. They are similar to a Singleton. You wouldn't abstain from using the Singleton pattern because somebody expressed a negative opinion for it, would you?
Trying to duplicate this functionality that already exists in the framework is just silly. Andrew Russell's opinion was that GameComponent
s can make your code messier. I would argue that trying to write your own layered drawing system would make your code messier.
Bottom line: Use the functionality that already exists. Don't change your coding style because somebody insulted it. You don't have to use the latest and greatest when the older style still works.
I won't tell you which approach is better, but this is how you would do it without using GameComponents:
In the game's Draw method, you call the Draw methods of the particle systems in the order you want:
smokePlumeParticles.Draw(gameTime);
explosionSmokeParticles.Draw(gameTime);
projectileTrailParticles.Draw(gameTime);
explosionParticles.Draw(gameTime);
fireParticles.Draw(gameTime);
精彩评论