Small problem code in XNA

Started by
1 comment, last by Little British Boy 15 years, 9 months ago
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
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
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Thanks for the info Mate!



LBB

This topic is closed to new replies.

Advertisement