示例#1
0
        /// <summary>
        /// Create a new game
        /// </summary>
        /// <param name="intendedWidth">The intended width of the game</param>
        /// <param name="intendedHeight">The intended height of the game</param>
        /// <param name="title">The window title</param>
        /// <param name="fps">The number of updates to be called every second</param>
        /// <param name="fullscreen">Whether or not the game will start in fullscreen</param>
        /// <param name="vsync">Whether or not VSync is enabled</param>
        public Game(int intendedWidth, int intendedHeight, string title = "Created with Inferno", int fps = 30, bool fullscreen = false, bool vsync = true)
        {
            //Set my "Me" reference
            Instance = this;

            //Scaling
            VirtualWidth  = intendedWidth;
            VirtualHeight = intendedHeight;

            //Create Keys Array
            Keys = new List <Key>();

            //Configure states
            _currentState = null;

            //Create Graphics Device
            GraphicsDevice = new GraphicsDevice();

            //Create Audio Device
            AudioDevice = new AudioDevice();

            //Register events for focus pause
            OnDeactivated += (sender, e) =>
            {
                if (!FocusPause)
                {
                    return;
                }
                Paused = true;
                AudioDevice.PauseAll();
            };

            OnActivated += (sender, e) =>
            {
                if (!FocusPause)
                {
                    return;
                }
                Paused = false;
                AudioDevice.ResumeAll();
            };

            //Platform game
            PlatformGame = new PlatformGame(this);

            //Create GameWindow
            Window = new GameWindow(this, GraphicsDevice, title, intendedWidth, intendedHeight);

            //Fps and fullscreen
            FramesPerSecond   = fps;
            Window.Fullscreen = fullscreen;

            //Attach window to device
            GraphicsDevice.AttachWindow(Window);

            //Create Renderer
            Renderer = new Renderer(GraphicsDevice);

            //Create render target
            _baseRenderTarget = new RenderTarget(VirtualWidth, VirtualHeight);
        }