Jump to content
  • Advertisement
Sign in to follow this  
Xardov

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

This topic is 2320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So basically, I followed this tutorial and made a bounding box. Here is the code. 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
Advertisement
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:


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

public MyGame : Game {

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

}

Share this post


Link to post
Share on other sites
[color=#526569][font=Verdana, Arial, Helvetica, sans-serif]

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?

[/font]

[color=#526569][font=Verdana, Arial, Helvetica, sans-serif]

EDIT: Here is the code for the 3DObject class. http://pastebin.com/379GnCh1

[/font]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!