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


C# SpriteBatch.FlushIfNeeded方法代码示例

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


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

示例1: DrawInto


//.........这里部分代码省略.........

                if (flippedVert)
                {
                    origin.Y *= -1;
                    flipAdjustment.Y = LineSpacing - size.Y;
                }
            }

            // TODO: This looks excessive... i suspect we could do most
            // of this with simple vector math and avoid this much matrix work.

            Matrix transformation, temp;
            Matrix.CreateTranslation(-origin.X, -origin.Y, 0f, out transformation);
            Matrix.CreateScale((flippedHorz ? -scale.X : scale.X), (flippedVert ? -scale.Y : scale.Y), 1f, out temp);
            Matrix.Multiply(ref transformation, ref temp, out transformation);
            Matrix.CreateTranslation(flipAdjustment.X, flipAdjustment.Y, 0, out temp);
            Matrix.Multiply(ref temp, ref transformation, out transformation);
            Matrix.CreateRotationZ(rotation, out temp);
            Matrix.Multiply(ref transformation, ref temp, out transformation);
            Matrix.CreateTranslation(position.X, position.Y, 0f, out temp);
            Matrix.Multiply(ref transformation, ref temp, out transformation);

            // Get the default glyph here once.
            Glyph? defaultGlyph = null;
            if (DefaultCharacter.HasValue)
                defaultGlyph = _glyphs[DefaultCharacter.Value];

            var currentGlyph = Glyph.Empty;
            var offset = Vector2.Zero;
            var hasCurrentGlyph = false;
            var firstGlyphOfLine = true;

			for (var i = 0; i < text.Length; ++i)
            {
                var c = text[i];
                if (c == '\r')
                {
                    hasCurrentGlyph = false;
                    continue;
                }

                if (c == '\n')
                {
                    offset.X = 0;
                    offset.Y += LineSpacing;
                    hasCurrentGlyph = false;
                    firstGlyphOfLine = true;
                    continue;
                }

                if (hasCurrentGlyph) {
                    offset.X += Spacing + currentGlyph.Width + currentGlyph.RightSideBearing;
                }

                hasCurrentGlyph = _glyphs.TryGetValue(c, out currentGlyph);
                if (!hasCurrentGlyph)
                {
                    if (!defaultGlyph.HasValue)
                        throw new ArgumentException(Errors.TextContainsUnresolvableCharacters, "text");

                    currentGlyph = defaultGlyph.Value;
                    hasCurrentGlyph = true;
                }

                if (hasCurrentGlyph) {
                    // The first character on a line might have a negative left side bearing.
                    // In this scenario, SpriteBatch/SpriteFont normally offset the text to the right,
                    //  so that text does not hang off the left side of its rectangle.
                    if (firstGlyphOfLine) {
                        offset.X = Math.Max(offset.X, 0);
                        firstGlyphOfLine = false;
                    } else {
                        offset.X += currentGlyph.LeftSideBearing;
                    }
                }

                var p = offset;

				if (flippedHorz)
                    p.X += currentGlyph.BoundsInTexture.Width;
                p.X += currentGlyph.Cropping.X;

				if (flippedVert)
                    p.Y += currentGlyph.BoundsInTexture.Height - LineSpacing;
                p.Y += currentGlyph.Cropping.Y;

				Vector2.Transform(ref p, ref transformation, out p);

                var destRect = new Vector4( p.X, p.Y, 
                                            currentGlyph.BoundsInTexture.Width * scale.X,
                                            currentGlyph.BoundsInTexture.Height * scale.Y);

				spriteBatch.DrawInternal(
                    _texture, destRect, currentGlyph.BoundsInTexture,
					color, rotation, Vector2.Zero, effect, depth, false);
			}

			// We need to flush if we're using Immediate sort mode.
			spriteBatch.FlushIfNeeded();
		}
开发者ID:hellewegenRebers,项目名称:MasterBlaster,代码行数:101,代码来源:SpriteFont.cs


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