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

GraphicsDevice.VertexDelcaratio

This topic is 3739 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
GraphicsDevice isn't a static class, it's a member of the Game class. Therefore, if you wish to access it outside of the Game class, you need to pass it as a parameter somehow, either in the constructor or through whichever method you need it. For example:


class Game
{
void Draw()
{
OtherClass c = new OtherClass();
c.DoSomething(GraphicsDevice);
}
}

class OtherClass
{
public void DoSomething(GraphicsDevice device)
{
device.VertexDeclaration = whatever;
}
}

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!