本文整理汇总了C#中ISpriteBatch.Draw方法的典型用法代码示例。如果您正苦于以下问题:C# ISpriteBatch.Draw方法的具体用法?C# ISpriteBatch.Draw怎么用?C# ISpriteBatch.Draw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISpriteBatch
的用法示例。
在下文中一共展示了ISpriteBatch.Draw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
/// <summary>
/// Draws a rectangle.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="dest">Destination rectangle.</param>
/// <param name="color">Color of the rectangle.</param>
public static void Draw(ISpriteBatch sb, Rectangle dest, Color color)
{
var fDest = new FloatRect(dest.Left, dest.Top, dest.Width, dest.Height);
using (var s = Shape.Rectangle(fDest, color))
{
sb.Draw(s);
}
}
示例2: Draw
/// <summary>
/// Draws a rectangle.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="position">Top-left corner position.</param>
/// <param name="size">The size of the rectangle.</param>
/// <param name="color">Color of the rectangle.</param>
public static void Draw(ISpriteBatch sb, Vector2 position, Vector2 size, Color color)
{
var drawRect = _drawRectBorder;
drawRect.Size = size;
drawRect.Position = position;
drawRect.FillColor = color;
sb.Draw(drawRect);
}
示例3: Draw
public void Draw(GameTime time, ISpriteBatch batch)
{
if (!isVisible)
return;
WasDrawn = true;
if (DrawCallback != null)
DrawCallback();
if (batch is SpriteBatchMock)
{
batch.Draw(null, new Rectangle((int)XPosition, (int)YPosition, (int)Width, (int)Height), Color);
}
}
示例4: Draw
public void Draw(ISpriteBatch spriteBatch, Vector offset)
{
var image = this.imageSource as TextureImage;
if (image == null)
{
throw new NotImplementedException("Currently an ImageSource must be an TextureImage");
}
Rect drawRect = !this.rect.IsEmpty ? this.rect : new Rect();
drawRect.Displace(offset);
spriteBatch.Draw(image.Texture, drawRect, Colors.White);
}
示例5: Draw
/// <summary>
/// Draws a line.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="p1">First point of the line.</param>
/// <param name="p2">Second point of the line.</param>
/// <param name="color">Color of the line.</param>
/// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
{
if (sb == null)
{
Debug.Fail("sb is null.");
return;
}
if (sb.IsDisposed)
{
Debug.Fail("sb is disposed.");
return;
}
using (var s = Shape.Line(p1, p2, thickness, color))
{
sb.Draw(s);
}
}
示例6: Draw
/// <summary>
/// Draws a line.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="p1">First point of the line.</param>
/// <param name="p2">Second point of the line.</param>
/// <param name="color">Color of the line.</param>
/// <param name="thickness">The thickness of the line in pixels. Default is 1.</param>
public static void Draw(ISpriteBatch sb, Vector2 p1, Vector2 p2, Color color, float thickness = 1f)
{
if (sb == null)
{
Debug.Fail("sb is null.");
return;
}
if (sb.IsDisposed)
{
Debug.Fail("sb is disposed.");
return;
}
// Common properties set no matter the approach we use below
_drawLineRect.Position = p1;
_drawLineRect.FillColor = color;
// If we have a perfectly vertical or horizontal line, we can avoid using rotation to speed up the calculation, so check for that first.
// This is purely an optimization - the rotation approach works for all points still.
if (p1.X == p2.X)
{
// Perfectly vertical
_drawLineRect.Size = new Vector2(thickness, p2.Y - p1.Y);
_drawLineRect.Rotation = 0;
}
else if (p1.Y == p2.Y)
{
// Perfectly horizontal
_drawLineRect.Size = new Vector2(p2.X - p1.X, thickness);
_drawLineRect.Rotation = 0;
}
else
{
// Treat as horizontal by setting the X as the distance and Y as the thickness, then rotate
_drawLineRect.Size = new Vector2(p2.Distance(p1), thickness);
_drawLineRect.Rotation = MathHelper.ToDegrees((float)Math.Atan2(p2.Y - p1.Y, p2.X - p1.X));
}
sb.Draw(_drawLineRect);
}
示例7: Draw
/// <summary>
/// Draws the <see cref="ISprite"/>.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
/// <param name="position">Position to draw to.</param>
/// <param name="color"><see cref="Color"/> to draw with.</param>
public void Draw(ISpriteBatch sb, Vector2 position, Color color)
{
if (!CanDraw(sb))
return;
sb.Draw(_texture, position, _source, color);
}
示例8: DrawComponent
protected override void DrawComponent(GameTime time, ISpriteBatch batch)
{
batch.Draw(spriteSheet, destinationRectangle:destinationRectangle, sourceRectangle: sourceRectangle, color: Color, effects: SpriteEffects);
}
示例9: Draw
/// <summary>
/// Draws the current frame of the <see cref="Grh"/>.
/// </summary>
/// <param name="sb"><see cref="ISpriteBatch"/> to add the draw to.</param>
/// <param name="dest">Top-left corner pixel of the destination.</param>
/// <param name="color">Color of the sprite (default Color.White).</param>
public void Draw(ISpriteBatch sb, Vector2 dest, Color color)
{
if (!CanDrawGrh(sb))
return;
sb.Draw(Texture, dest, Source, color);
}
示例10: DrawControl
/// <summary>
/// Draws the control.
/// </summary>
/// <param name="spriteBatch"><see cref="ISpriteBatch"/> to draw to.</param>
protected override void DrawControl(ISpriteBatch spriteBatch)
{
// Draw the border
Border.Draw(spriteBatch, this);
// Find the sprite based on the state and value
ISprite sprite;
if (Value)
{
if (_state == CheckBoxState.Pressed)
sprite = _tickedPressed;
else if (_state == CheckBoxState.Over)
sprite = _tickedOver;
else
sprite = _ticked;
if (sprite == null)
sprite = _ticked;
}
else
{
if (_state == CheckBoxState.Pressed)
sprite = _untickedPressed;
else if (_state == CheckBoxState.Over)
sprite = _untickedOver;
else
sprite = _unticked;
if (sprite == null)
sprite = _unticked;
}
// Validate the sprite
if (sprite == null)
return;
// Find the text offset
var textOffset = new Vector2(sprite.Source.Width + _textXAdjust, 0);
// Draw the checkbox
if (sprite.Texture != null)
spriteBatch.Draw(sprite.Texture, ScreenPosition, sprite.Source, Color.White);
// Draw the text
DrawText(spriteBatch, textOffset);
}
示例11: Draw
public void Draw(ISpriteBatch spriteBatch)
{
if (Texture != null)
{
Vector2 origin = Origin;
SpriteEffects effects = SpriteEffects.None;
if (WorldFlipX)
{
effects |= SpriteEffects.FlipHorizontally;
origin.X = Rectangle.Width - origin.X;
}
if (WorldFlipY)
{
effects |= SpriteEffects.FlipVertically;
origin.Y = Rectangle.Height - origin.Y;
}
spriteBatch.Draw(Texture, WorldPosition, Rectangle, Color * WorldOpacity, WorldRotation, origin, new Vector2(WorldScaleX, WorldScaleY), effects, 0.0f);
}
}
示例12: 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();
}
示例13: Draw
internal void Draw(ISpriteBatch spriteBatch)
{
spriteBatch.Draw(myTexture, spritePosition, Color.White);
}
示例14: 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();
}
示例15: DrawComponent
protected override void DrawComponent(GameTime time, ISpriteBatch batch)
{
if (image != null)
batch.Draw(image, Position, null, Color.White, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
}