本文整理汇总了C#中ISpriteBatch.DrawTiledXY方法的典型用法代码示例。如果您正苦于以下问题:C# ISpriteBatch.DrawTiledXY方法的具体用法?C# ISpriteBatch.DrawTiledXY怎么用?C# ISpriteBatch.DrawTiledXY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISpriteBatch
的用法示例。
在下文中一共展示了ISpriteBatch.DrawTiledXY方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// Draws the <see cref="ControlBorder"/> to the specified region.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw with.</param>
/// <param name="region">Region to draw the <see cref="ControlBorder"/> to. These values represent
/// the absolute screen position.</param>
/// <param name="color">The <see cref="Color"/> to use to draw the <see cref="ControlBorder"/>.</param>
public void Draw(ISpriteBatch sb, Rectangle region, Color color)
{
if (!_canDraw)
return;
var _bg = GetSprite(ControlBorderSpriteType.Background);
var _t = GetSprite(ControlBorderSpriteType.Top);
var _tl = GetSprite(ControlBorderSpriteType.TopLeft);
var _tr = GetSprite(ControlBorderSpriteType.TopRight);
var _l = GetSprite(ControlBorderSpriteType.Left);
var _r = GetSprite(ControlBorderSpriteType.Right);
var _b = GetSprite(ControlBorderSpriteType.Bottom);
var _bl = GetSprite(ControlBorderSpriteType.BottomLeft);
var _br = GetSprite(ControlBorderSpriteType.BottomRight);
var bSrc = _b.Source;
var tSrc = _t.Source;
var tlSrc = _tl.Source;
var trSrc = _tr.Source;
var lSrc = _l.Source;
var rSrc = _r.Source;
var blSrc = _bl.Source;
var brSrc = _br.Source;
// Set some values we will be using extensively
var cX = region.X;
var cY = region.Y;
var cW = region.Width;
var cH = region.Height;
lock (_drawSync)
{
// Background (draw first to ensure it stays behind the border in case something goes wrong)
Rectangle r;
if (_bg != null)
{
r = new Rectangle(cX + lSrc.Width, cY + tSrc.Height, cW - lSrc.Width - rSrc.Width,
cH - tSrc.Height - bSrc.Height);
switch (GetDrawStyle(ControlBorderSpriteType.Background))
{
case ControlBorderDrawStyle.Stretch:
_bg.Draw(sb, r, color);
break;
case ControlBorderDrawStyle.Tile:
AssertSaneDrawTilingAmount(r.X, r.Right, _bg.Size.X, ControlBorderSpriteType.Background);
AssertSaneDrawTilingAmount(r.Y, r.Bottom, _bg.Size.Y, ControlBorderSpriteType.Background);
sb.DrawTiledXY(r.X, r.Right, r.Y, r.Bottom, _bg, color);
break;
}
}
// Top side
r = new Rectangle(cX + tlSrc.Width, cY, cW - tlSrc.Width - trSrc.Width, tSrc.Height);
switch (GetDrawStyle(ControlBorderSpriteType.Top))
{
case ControlBorderDrawStyle.Stretch:
_t.Draw(sb, r, color);
break;
case ControlBorderDrawStyle.Tile:
AssertSaneDrawTilingAmount(r.X, r.Right, _t.Size.X, ControlBorderSpriteType.Top);
sb.DrawTiledX(r.X, r.Right, r.Y, _t, color);
break;
}
// Left side
r = new Rectangle(cX, cY + tlSrc.Height, lSrc.Width, cH - tlSrc.Height - blSrc.Height);
switch (GetDrawStyle(ControlBorderSpriteType.Left))
{
case ControlBorderDrawStyle.Stretch:
_l.Draw(sb, r, color);
break;
case ControlBorderDrawStyle.Tile:
AssertSaneDrawTilingAmount(r.Y, r.Bottom, _l.Size.Y, ControlBorderSpriteType.Left);
sb.DrawTiledY(r.Y, r.Bottom, r.X, _l, color);
break;
}
// Right side
r = new Rectangle(cX + cW - rSrc.Width, cY + trSrc.Height, rSrc.Width, cH - trSrc.Height - brSrc.Height);
switch (GetDrawStyle(ControlBorderSpriteType.Right))
{
case ControlBorderDrawStyle.Stretch:
_r.Draw(sb, r, color);
break;
case ControlBorderDrawStyle.Tile:
AssertSaneDrawTilingAmount(r.Y, r.Bottom, _r.Size.Y, ControlBorderSpriteType.Right);
sb.DrawTiledY(r.Y, r.Bottom, r.X, _r, color);
break;
//.........这里部分代码省略.........
示例2: HandleDraw
/// <summary>
/// Handles drawing the <see cref="BackgroundImage"/>.
/// </summary>
/// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param>
protected override void HandleDraw(ISpriteBatch sb)
{
var spriteSize = SpriteSourceSize;
var pos = GetPosition(Map.Size, Camera, spriteSize);
var vl = VerticalLayout;
var hl = HorizontalLayout;
if (hl == BackgroundLayerLayout.Stretched && vl == BackgroundLayerLayout.Stretched)
{
// Stretch both directions
spriteSize.X = GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
spriteSize.Y = GetStretchedSize(Camera.Size.Y * Camera.Scale, Map.Size.Y, Depth);
var rect = new Rectangle((int)pos.X, (int)pos.Y, (int)spriteSize.X, (int)spriteSize.Y);
Sprite.Draw(sb, rect, Color);
}
else if (vl == BackgroundLayerLayout.Tiled &&
(hl == BackgroundLayerLayout.None || hl == BackgroundLayerLayout.Stretched))
{
// Stretch/none horizontal, tile vertical
int drawWidth;
if (hl == BackgroundLayerLayout.None)
drawWidth = (int)spriteSize.X;
else
drawWidth = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
sb.DrawTiledY((int)pos.Y, (int)Camera.Max.Y + 64, (int)pos.X, Sprite, Color.White, drawWidth);
}
else if (hl == BackgroundLayerLayout.Tiled &&
(vl == BackgroundLayerLayout.None || vl == BackgroundLayerLayout.Stretched))
{
// Tile horizontal, stretch/none vertical
int drawHeight;
if (vl == BackgroundLayerLayout.None)
drawHeight = (int)spriteSize.Y;
else
drawHeight = (int)GetStretchedSize(Camera.Size.X * Camera.Scale, Map.Size.X, Depth);
sb.DrawTiledX((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, Sprite, Color.White, drawHeight);
}
else if (hl == BackgroundLayerLayout.Tiled && vl == BackgroundLayerLayout.Tiled)
{
// Tile both directions
sb.DrawTiledXY((int)pos.X, (int)Camera.Max.X + 64, (int)pos.Y, (int)Camera.Max.Y + 64, Sprite, Color);
}
else if (hl == BackgroundLayerLayout.None && vl == BackgroundLayerLayout.None)
{
// None in both directions
Sprite.Draw(sb, pos);
}
else
{
// Unknown or unhandled permutation
const string errmsg =
"Unknown or unhandled BackgroundLayerLayout provided." +
" Changing layouts to BackgroundLayerLayout.None. HorizontalLayout: `{0}` VerticalLayout: `{1}`";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, HorizontalLayout, VerticalLayout);
HorizontalLayout = BackgroundLayerLayout.None;
VerticalLayout = BackgroundLayerLayout.None;
}
}