当前位置: 首页>>代码示例>>C#>>正文


C# ISpriteBatch.Begin方法代码示例

本文整理汇总了C#中ISpriteBatch.Begin方法的典型用法代码示例。如果您正苦于以下问题:C# ISpriteBatch.Begin方法的具体用法?C# ISpriteBatch.Begin怎么用?C# ISpriteBatch.Begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISpriteBatch的用法示例。


在下文中一共展示了ISpriteBatch.Begin方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Begin

        public void Begin(ISpriteBatch batch)
        {
            device.SetRenderTarget(target);
            device.Clear(screenConstants.BackgroundColor);

            batch.Begin();
        }
开发者ID:Nexus87,项目名称:PokeClone,代码行数:7,代码来源:Screen.cs

示例2: HandleDrawBuffer

        /// <summary>
        /// When overridden in the derived class, handles drawing to the buffer.
        /// </summary>
        /// <param name="rt">The <see cref="RenderTarget"/> to draw to.</param>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw to the <paramref name="rt"/>. The derived class
        /// is required to handle making Begin()/End() calls on it.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param>
        /// <returns>True if the drawing was successful; false if there were any errors while drawing.</returns>
        protected override bool HandleDrawBuffer(RenderTarget rt, ISpriteBatch sb, ICamera2D camera)
        {
            // Draw the lights
            sb.Begin(BlendMode.Add, camera);

            foreach (var light in this)
            {
                if (camera.InView(light))
                    light.Draw(sb);
            }

            sb.End();

            return true;
        }
开发者ID:Vizzini,项目名称:netgore,代码行数:23,代码来源:LightManager.cs

示例3: Render

        public void Render(ISpriteBatch spriteBatch, V2 cameraPosition)
        {
            spriteBatch.Begin();

            for (int i = 0; i < positionedWorldCells.Length; i++)
            {
                if (positionedWorldCells[i] == null)
                    continue;

                for (int j = 0; j < positionedWorldCells[i].Count; j++)
                {
                    var cell = positionedWorldCells[i][j];

                    if (cell.Tile == null)
                        continue;

                    spriteBatch.Draw(cell.Tile.Texture,
                        new Rect(0, 0, TileWidth, TileHeight),
                        new Rect((int)cell.Position.X, (int)cell.Position.Y, TileWidth, TileHeight),
                        0f,
                        baseDepth - ((i * 100) + j) * HeightRowDepthMod);

                    spriteBatch.DrawString(SysCore.SystemFont, cell.Position.X + ", " + cell.Position.Y, new V2(cell.Position.X, cell.Position.Y), new V4(255), 0f, 1f, 1f);

                }
            }

            spriteBatch.End();
        }
开发者ID:7Kronos,项目名称:linda,代码行数:29,代码来源:TileRenderer.cs

示例4: HandleDrawBuffer

        /// <summary>
        /// When overridden in the derived class, handles drawing to the buffer.
        /// </summary>
        /// <param name="rt">The <see cref="RenderTarget"/> to draw to.</param>
        /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw to the <paramref name="rt"/>. The derived class
        /// is required to handle making Begin()/End() calls on it.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param>
        /// <returns>
        /// True if the drawing was successful; false if there were any errors while drawing.
        /// </returns>
        protected override bool HandleDrawBuffer(RenderTarget rt, ISpriteBatch sb, ICamera2D camera)
        {
            sb.Begin(BlendMode.Add, camera);

            try
            {
                // Sort through the effects, grabbing those in view, then ordering by their drawing priority
                foreach (var effect in this.Where(camera.InView).OrderBy(x => x.DrawPriority))
                {
                    try
                    {
                        // Draw the effect
                        effect.Draw(sb);
                    }
                    catch (Exception ex)
                    {
                        // A single effect failed
                        const string errmsg =
                            "Error while drawing IRefractionEffect `{0}` for RefractionManager `{1}`. Exception: {2}";
                        if (log.IsErrorEnabled)
                            log.ErrorFormat(errmsg, effect, this, ex);
                        Debug.Fail(string.Format(errmsg, effect, this, ex));
                    }
                }
            }
            catch (Exception ex)
            {
                // Failed somewhere other than effect.Draw(), causing the whole drawing to fail
                const string errmsg = "Error while drawing IRefractionEffects for RefractionManager `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, this, ex);
                Debug.Fail(string.Format(errmsg, this, ex));
                return false;
            }
            finally
            {
                sb.End();
            }

            return true;
        }
开发者ID:Furt,项目名称:netgore,代码行数:51,代码来源:RefractionManager.cs

示例5: DoRender

        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            spriteBatch.Begin();

            Vector2 textSize = content.SpriteFont.MeasureString(m_text);
            Vector2 origin = Vector2.Zero;

            if (Alignment == Alignment.Centered) {
                origin = textSize / 2;
            }
            else if (Alignment == Alignment.TopRight) {
                origin = new Vector2(textSize.X, 0);
            }

            spriteBatch.DrawString(
                content.SpriteFont,
                m_text,
                combinedTransform.Translation,
                Color,
                Rotation,
                origin,
                combinedTransform.Scale.X,
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:36,代码来源:TextNode.cs

示例6: Draw

        public void Draw(ISpriteBatch spriteBatch)
        {
            Rect clippingRect = this.absoluteClippingRect;
            if (spriteBatch.TryIntersectViewport(ref clippingRect))
            {
                spriteBatch.Begin(clippingRect);

                foreach (ISpriteJob spriteJob in this.jobs)
                {
                    spriteJob.Draw(spriteBatch, this.absoluteOffset);
                }
            }
        }
开发者ID:redbadger,项目名称:XPF,代码行数:13,代码来源:DrawingContext.cs

示例7: DoRender

        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            bool positionMirrored =
                SecondaryViewOption == SecondaryViewOption.PositionMirrored
                && view == HolofunkView.Secondary;

            Vector2 p0 = m_p0 + parentTransform.Translation;
            Vector2 p1 = m_p1 + parentTransform.Translation;

            if (positionMirrored) {
                p0 = new Vector2(spriteBatch.Viewport.X - p0.X, p0.Y);
                p1 = new Vector2(spriteBatch.Viewport.X - p1.X, p1.Y);
            }

            Vector2 diff = Vector2.Subtract(p1, p0);
            float angleRadians = (float)Math.Atan2(diff.Y, diff.X);
            float length = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y) / 2;

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                content.TinyDot,
                p0,
                null,
                Color,
                angleRadians,
                new Vector2(0f, 1f), // we pivot around the center of the left edge of the 2x2 square
                new Vector2(length, LocalTransform.Scale.Y),
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:41,代码来源:LineNode.cs

示例8: DrawQuarterCircle

        // Draw one of the squares at a grid coordinate.
        void DrawQuarterCircle(ISpriteBatch spriteBatch, TextureContent content, Rectangle rect, Vector2 gridOrigin, int beat, Color color, float filledness, int depth)
        {
            // we prefer beats to start at upper left, but left to this logic, they start at lower left

            // position of this measure
            Vector2 position = gridOrigin + new Vector2(((beat / 4) % 4) * rect.Width, (beat / 16) * rect.Height);

            Vector2 offset;
            switch (beat % 4)
            {
                case 0: offset = new Vector2(1, 1); break;
                case 1: offset = new Vector2(0, 1); break;
                case 2: offset = new Vector2(0, 0); break;
                case 3: offset = new Vector2(1, 0); break;
                default: offset = Vector2.Zero; break; // NOTREACHED
            }
            position += offset * new Vector2(rect.Width, rect.Height);

            Rectangle destRect = new Rectangle(
                rect.Left + (int)position.X,
                rect.Top + (int)position.Y,
                rect.Width,
                rect.Height);

            Spam.Graphics.WriteLine(new string(' ', depth * 4 + 4) + Label + ": beat " + beat + ", filledness " + filledness + ", destRect " + destRect.ToString());

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            Vector2 origin = new Vector2(0);

            // always draw a hollow quarter circle
            spriteBatch.Draw(
                content.QuarterHollowCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            // now maybe draw a filled circle
            Vector4 v = color.ToVector4();
            v *= filledness;
            color = new Color(v);

            spriteBatch.Draw(
                content.QuarterFilledCircle,
                destRect,
                null,
                color,
                (float)((beat % 4 + 2) * Math.PI / 2),
                origin,
                SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically,
                0);

            spriteBatch.End();
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:60,代码来源:BeatNode.cs

示例9: DoRender

        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            // no texture = no-op
            if (m_texture == null) {
                return;
            }

            int left = -(int)((float)m_texture.Width * m_origin.X);
            int top = -(int)((float)m_texture.Height * m_origin.Y);
            Rectangle rect = new Rectangle(left, top, m_texture.Width, m_texture.Height);

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            Rectangle transformedRect = rect * combinedTransform;

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + "; start rect " + rect.FormatToString() + "; transformedRect " + transformedRect.FormatToString());

            Texture2D texture = m_texture;
            SpriteEffects effects = SpriteEffects.None;

            if (view == HolofunkView.Secondary) {
                if ((SecondaryViewOption & SecondaryViewOption.TextureMirrored) != 0) {
                    effects = SpriteEffects.FlipHorizontally;
                }

                if ((SecondaryViewOption & SecondaryViewOption.PositionMirrored) != 0) {
                    // need to flip transformedRect around center of viewport
                    int newLeft = (int)spriteBatch.Viewport.X - transformedRect.Right;

                    transformedRect = new Rectangle(newLeft, transformedRect.Y, transformedRect.Width, transformedRect.Height);
                }

                if ((SecondaryViewOption & SecondaryViewOption.SecondTexture) != 0) {
                    HoloDebug.Assert(m_secondaryTexture != null);
                    texture = m_secondaryTexture;
                }
            }

            Color color = m_color;
            if (view == HolofunkView.Secondary && m_secondaryColor.HasValue) {
                color = m_secondaryColor.Value;
            }

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                texture,
                transformedRect,
                null,
                color,
                0,
                m_origin,
                effects,
                0);

            spriteBatch.End();
        }
开发者ID:RobJellinghaus,项目名称:Holofunk,代码行数:65,代码来源:SpriteNode.cs


注:本文中的ISpriteBatch.Begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。