开发者

How to change DrawOrder without using DrawableGameComponent

开发者 https://www.devze.com 2023-02-18 06:10 出处:网络
Reading another SO question it seems that DrawableGameComponents 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

Reading another SO question it seems that DrawableGameComponents 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 DrawableGameComponents. 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?


GameComponents 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. GameComponents 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 GameComponents 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);
0

精彩评论

暂无评论...
验证码 换一张
取 消