[ad_1]
I’m making an attempt to know the right way to use the XNA XML content material importer to instantiate non-trivial objects which can be greater than a set of fundamental properties (e.g., a category that inherits from DrawreadyGameObject or GameObject and requires different issues to be handed into its constructor).
Is it attainable to move present exterior situations (e.g., an occasion of the present Game) to the constructor of an object that is being created utilizing the default XNA XML content material loader?
For instance, think about that I’ve the next class, inheriting from DrawreadyGamePart:
public class Character : DrawreadyGamePart
{
public string Name { get; set; }
public Character(Game recreation) : base(recreation) { }
public override void Update(GameTime gameTime) { }
public override void Draw(GameTime gameTime) { }
}
If I had a easy class that didn’t want different parameters in its constructor (i.e., the Game occasion), then I may merely use this XML:
<XnaContent>
<Asset Type="MyNamearea.Character">
<Name>John Doe</Name>
</Asset>
</XnaContent>
…after which create an occasion of Character utilizing this code:
var character = Content.Load<Character>("MyXmlAssetName");
But that will not work as a result of I must move the necessity to move the Game into the constructor.
What’s one of the simplest ways to deal with this example? Is there a strategy to move in issues like the present Game utilizing the default XNA XML content material loader? Do I would like to write down my very own XML loader? (If so, how?) Is there a greater object-oriented design that I ought to be utilizing for my courses?
Note: Although I used Game on this instance, I’m actually simply asking the right way to move any sort of present occasion to my constructors. (For instance, I’m utilizing the Farseer Physics Engine, and a few of my courses additionally want a reference to the Farseer World object too.)
Thanks upfront.
[ad_2]