Sign in to follow this  
Xardov

Converting a line of code for use in a standard class(XNA)

Recommended Posts

Xardov    112
So basically, I followed [url="http://xna-uk.net/blogs/randomchaos/archive/2010/08/09/boundingbox-s-in-xna-4-0.aspx"]this[/url] tutorial and made a bounding box. Here is the [url="http://pastebin.com/bSMDfaNc"]code[/url]. However, as you can see, the bounding box in that paste is a DrawableGameComponent. I would like to convert the entire thing to a standard class, and I believe that I can do so easily. However, one line of code is giving me trouble, and it is this one.

mesh = Game.Content.Load<Model>(modelName);

As far as I know, Game.Content.Load is only available to GameComponents. Is there any equivalent line of code that does not require extending the DrawableGameComponent, and can be used in a blank class?

Share this post


Link to post
Share on other sites
bami    100
You don't need to extend from (Drawable)GameComponent, you just need access to the class that extends Game, from there you can access Content.

For example:

[CODE]
public whateverClass {
public whateverClass(Game g)
{
g.Content.Load<Texture2D>("whatever");
}
}

public MyGame : Game {

public MyGame() : base()
{
new whateverClass(this);
}

}
[/CODE]

Share this post


Link to post
Share on other sites
Xardov    112
[color=#526569][font=Verdana, Arial, Helvetica, sans-serif][size=3][left]Thanks for your reply! I think I did something pretty close to what you told me to do, but I still got an error. I created an empty DrawableGameComponent called DrawHelper, then created a variable for it in my 3DObject class. Then I proceed to use mesh = drawHelper.Game.Content.Load<Model>(modelName), but then it points to that line and says "Object reference not set to an instance of an object.". And yes, I have added the DrawHelper component to the Game before adding the 3DObject class. What am I doing wrong?[/left][/size][/font][/color]

[color=#526569][font=Verdana, Arial, Helvetica, sans-serif][size=3][left]EDIT: Here is the code for the 3DObject class. [url="http://pastebin.com/379GnCh1"]http://pastebin.com/379GnCh1[/url][/left][/size][/font][/color]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this