當前位置: 首頁>>代碼示例>>C#>>正文


C# RenderTarget2D.BeginDraw方法代碼示例

本文整理匯總了C#中Microsoft.Xna.Framework.Graphics.RenderTarget2D.BeginDraw方法的典型用法代碼示例。如果您正苦於以下問題:C# RenderTarget2D.BeginDraw方法的具體用法?C# RenderTarget2D.BeginDraw怎麽用?C# RenderTarget2D.BeginDraw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Xna.Framework.Graphics.RenderTarget2D的用法示例。


在下文中一共展示了RenderTarget2D.BeginDraw方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Draw

        public override void Draw(SpriteBatch spriteBatch, Rectangle? visibleRectangle = null, Color? backgroundColor = null)
        {
            if(!IsVisible)
                return;

            if (_renderTarget == null)
            {
                // create and render the entire map to a single render target.
                // this gives the best frame rate performance at the cost of memory.
                // ideally, we'd like to have a couple of different draw strategies for different situations.
                _renderTarget = new RenderTarget2D(_renderTargetSpriteBatch.GraphicsDevice, _map.WidthInPixels, _map.WidthInPixels);

                using (_renderTarget.BeginDraw(_renderTargetSpriteBatch.GraphicsDevice, backgroundColor ?? Color.Transparent))
                {
                    //var vr = visibleRectangle ?? new Rectangle(0, 0, _map.WidthInPixels, _map.HeightInPixels);
                    var vr = new Rectangle(0, 0, _map.WidthInPixels, _map.HeightInPixels);
                    var renderOrderFunction = GetRenderOrderFunction();
                    var tileLocationFunction = GetTileLocationFunction();
                    var firstCol = vr.Left < 0 ? 0 : (int) Math.Floor(vr.Left/(float) _map.TileWidth);
                    var firstRow = vr.Top < 0 ? 0 : (int) Math.Floor(vr.Top/(float) _map.TileHeight);

                    // +3 to cover any gaps
                    var columns = Math.Min(_map.Width, vr.Width/_map.TileWidth) + 3;
                    var rows = Math.Min(_map.Height, vr.Height/_map.TileHeight) + 3;

                    _renderTargetSpriteBatch.Begin(blendState: BlendState.AlphaBlend, samplerState: SamplerState.PointClamp);

                    foreach (var tile in renderOrderFunction(firstCol, firstRow, firstCol + columns, firstRow + rows))
                    {
                        var region = tile != null ? _map.GetTileRegion(tile.Id) : null;

                        if (region != null)
                        {
                            var point = tileLocationFunction(tile);
                            var destinationRectangle = new Rectangle(point.X, point.Y, region.Width, region.Height);
                            _renderTargetSpriteBatch.Draw(region, destinationRectangle, Color.White*Opacity);
                        }
                    }

                    _renderTargetSpriteBatch.End();
                }
            }

            spriteBatch.Draw(_renderTarget, Vector2.Zero, Color.White);
        }
開發者ID:Mikescher,項目名稱:MonoGame.Extended,代碼行數:45,代碼來源:TiledTileLayer.cs


注:本文中的Microsoft.Xna.Framework.Graphics.RenderTarget2D.BeginDraw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。