GraphicsDevice.VertexDelcaratio

Started by
2 comments, last by Little British Boy 15 years, 10 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
Can you post the relevant code?
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;    }}
Mike Popoloski | Journal | SlimDX
Thanks Mate think I got it going now, Thanks for your help!



LBB

This topic is closed to new replies.

Advertisement