Jump to content
  • Advertisement
Sign in to follow this  
Little British Boy

Small problem code in XNA

This topic is 3740 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

Good Day Mates, The only problem I seem to still have is that my program is in 2 seperate files, The first program loads, sets the GraphicsDeviceManger and the like, but the second program with the draw code, doesn't seem to recognize GraphicsDevice.VertexDelcaration, etc... how do I pass this data to this other program or how should I go about this? The error I'm getting is Error 1 An object reference is required for the nonstatic field, method, or property 'Microsoft.Xna.Framework.Graphics.GraphicsDevice.VertexDeclaration.get' C:\BACKUP\SA\SimpleAnimationSample\SimpleAnimation\Carrier.cs 159 25 RotorheaD Thanks again Mates, LBB

Share this post


Link to post
Share on other sites
Advertisement

You'll somehow have to pass the GraphicsDevice object created in your main class to the other class in Carrier.cs. With your current code you're referencing the GraphicsDevice class, instead of your GraphicsDevice object. Though it is possible for a class to contain methods and/or properties (so-called static members), you typically -and certainly in the case- will want to work with objects.

I was writing a little example, but I think that'll only be confusing. I'd advice you to brush up on object oriented programming. Then you can get to work with the options of passing the GraphicsDevice to your Carrier, like:

- Passing in the device object as a parameter to your Carrier's Draw function
- Making the device object a member variable of your Carrier object
- Making the Carrier inherit from GameComponent, so you'll have access to the device through the Game object

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!