Пример #1
0
        //Rendering
        public override void Draw(GameTime gameTime)
        {
            //Render the screen to our internal game-sized back buffer.
            GraphicsDevice.SetRenderTarget(backRender);
            if (FlxG.state != null)
            {
                FlxG.state.preProcess(FlxG.spriteBatch);
                FlxG.state.render(FlxG.spriteBatch);

                FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
                if (FlxG.flash.exists)
                {
                    FlxG.flash.render(FlxG.spriteBatch);
                }
                if (FlxG.fade.exists)
                {
                    FlxG.fade.render(FlxG.spriteBatch);
                }

                if (FlxG.mouse.cursor.visible)
                {
                    FlxG.mouse.cursor.render(FlxG.spriteBatch);
                }

                FlxG.spriteBatch.End();

                FlxG.state.postProcess(FlxG.spriteBatch);
            }
            //Render sound tray if necessary
            if (_soundTrayVisible || _paused)
            {
                FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
                //GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
                //GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
                //GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;
                if (_soundTrayVisible)
                {
                    FlxG.spriteBatch.Draw(FlxG.XnaSheet, _soundTrayRect,
                                          new Rectangle(1, 1, 1, 1), _console.color);
                    _soundCaption.render(FlxG.spriteBatch);
                    for (int i = 0; i < _soundTrayBars.Length; i++)
                    {
                        _soundTrayBars[i].render(FlxG.spriteBatch);
                    }
                }
                if (_paused)
                {
                    _pausePanel.render(FlxG.spriteBatch);
                }
                FlxG.spriteBatch.End();
            }
            GraphicsDevice.SetRenderTarget(null);

            //Copy the result to the screen, scaled to fit
            GraphicsDevice.Clear(FlxG.backColor);
            FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
            //GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
            //GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
            //GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;
            FlxG.spriteBatch.Draw(backRender,
                                  new Rectangle(targetLeft + _quakeOffset.X, _quakeOffset.Y, targetWidth, GraphicsDevice.Viewport.Height),
                                  Color.White);
            //Render console if necessary
            if (_console.visible)
            {
                _console.render(FlxG.spriteBatch);
            }
            FlxG.spriteBatch.End();
        }
Пример #2
0
        /// <summary>
        /// The Main Rendering part.
        /// Uses two different SpriteBatches,
        /// To Do: Have Bloom effect both spritebatches.
        /// </summary>
        /// <param name="gameTime">Game time.</param>
        public override void Draw(GameTime gameTime)
        {
            //Render the screen to our internal game-sized back buffer.
            GraphicsDevice.SetRenderTarget(backRender);

            if (FlxG.state != null)
            {
                FlxG.state.preProcess(FlxG.spriteBatch);

                FlxG.state.render(FlxG.spriteBatch);

                FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);

                if (FlxG.flash.exists)
                {
                    FlxG.flash.render(FlxG.spriteBatch);
                }

                if (FlxG.fade.exists)
                {
                    FlxG.fade.render(FlxG.spriteBatch);
                }

                if (FlxG.mouse.cursor.visible)
                {
                    FlxG.mouse.cursor.render(FlxG.spriteBatch);
                }

                FlxG.spriteBatch.End();

                FlxG.state.postProcess(FlxG.spriteBatch);
            }
            //Render sound tray if necessary
            if (_soundTrayVisible || _paused)
            {
                FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
                //GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
                //GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
                //GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;
                if (_soundTrayVisible)
                {
                    FlxG.spriteBatch.Draw(FlxG.XnaSheet, _soundTrayRect,
                                          new Rectangle(1, 1, 1, 1), _console.color);
                    _soundCaption.render(FlxG.spriteBatch);
                    for (int i = 0; i < _soundTrayBars.Length; i++)
                    {
                        _soundTrayBars[i].render(FlxG.spriteBatch);
                    }
                }
                if (_paused)
                {
                    _pausePanel.render(FlxG.spriteBatch);
                }
                FlxG.spriteBatch.End();
            }

            //FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
            //var new_pos = new Vector2(50,50);
            //FlxG.spriteBatch.Draw(lightmask, new_pos, Color.White);
            //FlxG.spriteBatch.Draw(lightmask, new Vector2(10,100), Color.White);
            //FlxG.spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            //Copy the result to the screen, scaled to fit
            GraphicsDevice.Clear(FlxG.backColor);

            FlxG.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise);
            //GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.Point;
            //GraphicsDevice.SamplerStates[0].MinFilter = TextureFilter.Point;
            //GraphicsDevice.SamplerStates[0].MipFilter = TextureFilter.Point;

            // This was the original spritebatch.Draw
            //FlxG.spriteBatch.Draw(backRender,
            //    new Rectangle(targetLeft + _quakeOffset.X, _quakeOffset.Y, targetWidth, GraphicsDevice.Viewport.Height),
            //    Color.White);

            // If there are no cameras in the array, render the normal spriteBatch.
            if (FlxG.cameras.Count == 0)
            {
                // This is the new SpriteBatch.Draw the draws with the FlxG.angle

                // Adjust a full screen

                /*
                 *      60 + targetLeft + _quakeOffset.X + FlxG.width,
                 *      40 + _quakeOffset.Y + FlxG.height,
                 */
                FlxG.spriteBatch.Draw(backRender,
                                      new Rectangle(
                                          FlxG.borderWidth + targetLeft + _quakeOffset.X + FlxG.width,
                                          FlxG.borderHeight + _quakeOffset.Y + FlxG.height,
                                          targetWidth,
                                          GraphicsDevice.Viewport.Height),
                                      null,
                                      _color,
                                      FlxG.angle,
                                      new Vector2(FlxG.width / FlxG.zoom, FlxG.height / FlxG.zoom),
                                      SpriteEffects.None,
                                      0f);
            }
            // if there are cameras in the FlxG.cameras array, render them here.
            else
            {
                /*
                 * foreach (Viewport vp in viewports)
                 * {
                 *  Rectangle r2 = new Rectangle(0,0,GraphicsDevice.Viewport.Width * 2,GraphicsDevice.Viewport.Height * 2);
                 *
                 *  FlxG.spriteBatch.GraphicsDevice.Viewport = vp;
                 *  FlxG.spriteBatch.Draw(backRender, r2, Color.White);
                 * }
                 */


                /*
                 * foreach (FlxCamera cam in FlxG.cameras)
                 * {
                 *  Rectangle r2 = new Rectangle(
                 *      (targetLeft + _quakeOffset.X + FlxG.width) + (int)cam.x * FlxG.zoom,
                 *      (_quakeOffset.Y + FlxG.height) + (int)cam.y * FlxG.zoom,
                 *      targetWidth,
                 *      GraphicsDevice.Viewport.Height);
                 *
                 *  FlxG.spriteBatch.Draw(backRender,
                 *  r2,
                 *  null,
                 *  cam.color,
                 *  cam.angle,
                 *  new Vector2(FlxG.width / FlxG.zoom, FlxG.height / FlxG.zoom),
                 *  SpriteEffects.None,
                 *  0f);
                 * }
                 */
            }

            // Add cameras here.

            /*
             * FlxG.spriteBatch.Draw(backRender,
             *  new Rectangle((targetLeft + _quakeOffset.X + FlxG.width)/2, (_quakeOffset.Y + FlxG.height)/2, (targetWidth)/2, (GraphicsDevice.Viewport.Height)/2),
             *  null,
             *  _color,
             *  FlxG.angle,
             *  new Vector2(FlxG.width / FlxG.zoom, FlxG.height / FlxG.zoom),
             *  SpriteEffects.None,
             *  0f);
             */



            //Render console if necessary
            if (_console.visible)
            {
                _console.render(FlxG.spriteBatch);
            }

            // Render hud if neccessary.
            if (hud.visible)
            {
                hud.render(FlxG.spriteBatch);
            }
            // Render transition if neccessary, and render on this layer above everything.
            if (FlxG.transition.exists)
            {
                FlxG.transition.render(FlxG.spriteBatch);
            }


            FlxG.spriteBatch.End();
        }