XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Trying to encapsulate graphics device, Code compiles but the device isn't working

Last post 7/6/2008 11:09 PM by TyTheProgrammer89. 1 replies.
  • 7/6/2008 10:01 PM

    Trying to encapsulate graphics device, Code compiles but the device isn't working

    The title pretty much says it all, what I'm trying to do is encapsulate the graphics device in its own class for a game engine I'm trying to make. It currently compiles with no errors or warnings but the BeginRender function isn't refreshing the screen to Blue. It's just the default gray window color.

    The only thing I can think of is that the Graphics Device no longer belongs to the window itself, hence the window isn't refreshing.

     Thanks for all the help!

    using System; 
    using System.Collections.Generic; 
    using Microsoft.Xna.Framework; 
    using Microsoft.Xna.Framework.Audio; 
    using Microsoft.Xna.Framework.Content; 
    using Microsoft.Xna.Framework.GamerServices; 
    using Microsoft.Xna.Framework.Graphics; 
    using Microsoft.Xna.Framework.Input; 
    using Microsoft.Xna.Framework.Net; 
    using Microsoft.Xna.Framework.Storage; 
     
    namespace CameraControlTest 
     
        public class Game1 : Microsoft.Xna.Framework.Game 
        { 
            public static CGraphics Graphics() 
            { 
                return CGraphics.Get; 
            } 
     
            SpriteBatch spriteBatch; 
     
            float winWidth; 
            float winHeight; 
     
            CCamera m_Camera; 
     
            public Game1() 
            { 
                Content.RootDirectory = "Content"
            } 
     
            protected override void Initialize() 
            { 
                Graphics().Initialize(this, 800, 600, true);      
                m_Camera = new CCamera(); 
     
                m_Camera.Initialize(winWidth, winHeight); 
     
                base.Initialize(); 
            } 
     
            protected override void LoadContent() 
            { 
                // Create a new SpriteBatch, which can be used to draw textures. 
                spriteBatch = new SpriteBatch(Graphics().Device()); 
            } 
     
            protected override void UnloadContent() 
            { 
     
            } 
     
            protected override void Update(GameTime gameTime) 
            { 
                // Allows the game to exit 
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
                    this.Exit(); 
     
                m_Camera.Update(); 
                base.Update(gameTime); 
            } 
     
            protected override void Draw(GameTime gameTime) 
            { 
                Graphics().BeginRender(); 
     
                Graphics().EndRender(); 
     
                base.Draw(gameTime); 
            } 
        } 
    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using Microsoft.Xna.Framework; 
    using Microsoft.Xna.Framework.Content; 
    using Microsoft.Xna.Framework.GamerServices; 
    using Microsoft.Xna.Framework.Graphics; 
     
     
     
     
    namespace CameraControlTest 
     
        public sealed class CGraphics 
        { 
     
            public static CGraphics Get 
            { 
                get 
                { 
                    if (m_instance == null
                    { 
                        m_instance = new CGraphics(); 
                    } 
                    return m_instance; 
                } 
            } 
     
            public GraphicsDevice Device() 
            { 
                return m_graphics.GraphicsDevice; 
            } 
     
            public void Initialize(Game newGame, int iWidth, int iHeight, bool bFullscreen) 
            { 
                m_graphics = new GraphicsDeviceManager(newGame); 
                m_graphics.PreferredBackBufferWidth = iWidth; 
                m_graphics.PreferredBackBufferHeight = iHeight; 
                m_graphics.ApplyChanges(); 
     
                //m_device.Viewport.Height = iHeight; 
                //m_device.Viewport.Width = iWidth; 
     
                m_initialized = true
            } 
     
            public void BeginRender() 
            { 
                if ( m_initialized == true ) 
                { 
                    m_graphics.GraphicsDevice.Clear(Color.Blue); 
                } 
            } 
     
            public void EndRender() 
            { 
                if ( m_initialized == true ) 
                { 
     
                } 
            } 
     
            private CGraphics() 
            { 
                m_graphics = null
                m_initialized = false
            } 
     
            private GraphicsDeviceManager m_graphics; 
            private bool m_initialized; 
     
            private static CGraphics m_instance = null
        } 
  • 7/6/2008 11:09 PM In reply to

    Re: Trying to encapsulate graphics device, Code compiles but the device isn't working

    Nevermind I fixed the problem... Pretty stupid error actually. I had to move the Graphics Initialize function into the Game1 Constructor.
Page 1 of 1 (2 items) Previous Next