I have a small demo and I want to create a class that draws messages in screen like fps rate. I am reading a XNA book and they comment about GameComponents. I have created a class that inherits DrawableGameComponent
public class ScreenMessagesComponent : Microsoft.Xna.Framework.DrawableGameComponent
I override some methods like Initialize or LoadContent. But when I want to override draw I have a problem, I would like to pass some parameters to it.
Overrided method does not allow me to pass parameters.
public override void Draw(GameTime gameTime)
{
StringBuilder buffer = new StringBuilder();
buffer.AppendFormat("FPS: {0}\n", framesPerSecond); // Where get framesPerSecond from???
spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, Color.Yellow);
base.Draw(gameTime);
}
If I create a method with parameters, then I cannot override it and will not be automatically called:
public void Draw(SpriteBatch spriteBatch, int framesPerSecond)
{
StringBuilder buffer = new StringBuilder();
buffer.AppendFormat("FPS: {0}\n", framesPerSecond);
spriteBatch.DrawString(spriteFont, buffer.ToString(), fontPos, Color.Yellow);
base.Draw(gameTime);
}
So my questions are:
- Is there a mechanism to pass parameter to a drawableGameComponent? What is the best practice?
- In general is a good practice to use GameComponents?