本文整理汇总了C#中Canvas.FillRect方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.FillRect方法的具体用法?C# Canvas.FillRect怎么用?C# Canvas.FillRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.FillRect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(Canvas canvas)
{
canvas.State.ColorTint = Theme.ForegroundColour;
canvas.DrawRect(X, Y, w, h);
canvas.FillRect(X, Y, w, topWidth);
canvas.State.ColorTint = Theme.BackgroundColour;
canvas.FillRect(X + 1, Y + topWidth + 1, W - 2, h - topWidth - 2);
base.Draw(canvas);
}
示例2: Draw
public override void Draw(Canvas canvas)
{
text.Draw(canvas);
Vector2 realCaretPosition = text.getPositionFromCaret(caretPosition);
Vector2 characterSize = canvas.MeasureText("A");
canvas.State.ColorTint = Theme.ForegroundColour;
canvas.DrawRect(X, Y, W, H);
canvas.FillRect(realCaretPosition.X, realCaretPosition.Y, characterSize.X, characterSize.Y);
}
示例3: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Profile.BeginMeasure(@"ProfileRenderer");
Canvas canvas = new Canvas(device);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null));
bool anyTextReport = this.textReportPerf || this.textReportStat;
bool anyGraph = this.drawGraphs && this.counterGraphs.Count > 0;
// Determine geometry
int areaWidth = (int)device.TargetSize.X - 20;
if (anyGraph && anyTextReport)
areaWidth = (areaWidth - 10) / 2;
Rect textReportRect = new Rect(
10,
10,
anyTextReport ? areaWidth : 0,
(int)device.TargetSize.Y - 20);
Rect graphRect = new Rect(
anyTextReport ? (textReportRect.MaximumX + 10) : 10,
10,
anyGraph ? areaWidth : 0,
(int)device.TargetSize.Y - 20);
// Text Reports
if (anyTextReport)
{
// Update Report
IEnumerable<ProfileCounter> counters = Profile.GetUsedCounters();
if (!this.textReportPerf) counters = counters.Where(c => !(c is TimeCounter));
if (!this.textReportStat) counters = counters.Where(c => !(c is StatCounter));
if (this.textReport == null || (Time.MainTimer - this.textReportLast).TotalMilliseconds > this.updateInterval)
{
string report = Profile.GetTextReport(counters, this.textReportOptions | ReportOptions.FormattedText);
if (this.textReport == null)
{
this.textReport = new FormattedText();
this.textReport.Fonts = new[] { Font.GenericMonospace8 };
}
this.textReport.MaxWidth = (int)textReportRect.W;
this.textReport.SourceText = report;
this.textReportLast = Time.MainTimer;
}
// Draw Report
canvas.DrawTextBackground(textReport, textReportRect.X, textReportRect.Y);
canvas.DrawText(textReport, ref textReportTextVert, ref textReportIconVert, textReportRect.X, textReportRect.Y);
}
// Counter Graphs
if (anyGraph)
{
// Mark graph cache as unused
foreach (GraphCacheEntry entry in this.graphCache.Values)
{
entry.WasUsed = false;
}
int space = 5;
int graphY = (int)graphRect.Y;
int graphH = MathF.Min((int)(graphRect.H / this.counterGraphs.Count) - space, (int)graphRect.W / 2);
foreach (string counterName in this.counterGraphs)
{
ProfileCounter counter = Profile.GetCounter<ProfileCounter>(counterName);
if (counter == null) return;
// Create or retrieve graph cache entry
GraphCacheEntry cache = null;
if (!this.graphCache.TryGetValue(counterName, out cache))
{
cache = new GraphCacheEntry();
cache.GraphValues = new float[ProfileCounter.ValueHistoryLen];
cache.GraphColors = new ColorRgba[ProfileCounter.ValueHistoryLen];
this.graphCache[counterName] = cache;
}
cache.WasUsed = true;
float cursorRatio = 0.0f;
if (counter is TimeCounter)
{
TimeCounter timeCounter = counter as TimeCounter;
for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
{
float factor = timeCounter.ValueGraph[i] / Time.MsPFMult;
cache.GraphValues[i] = factor * 0.75f;
cache.GraphColors[i] = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, factor);
}
canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
canvas.CurrentState.ColorTint = ColorRgba.White;
canvas.DrawHorizontalGraph(cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
cursorRatio = (float)timeCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
}
else if (counter is StatCounter)
{
StatCounter statCounter = counter as StatCounter;
for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
{
cache.GraphValues[i] = (float)(statCounter.ValueGraph[i] - statCounter.MinValue) / statCounter.MaxValue;
//.........这里部分代码省略.........
示例4: DrawTestImageRow
private void DrawTestImageRow(Canvas c, int baseX, int baseY)
{
Vector2[] polygon = new Vector2[]
{
new Vector2(0.0f, 0.0f),
new Vector2(50.0f, 0.0f),
new Vector2(50.0f, 45.0f),
new Vector2(5.0f, 50.0f),
};
int x = baseX;
int y = baseY;
// Outline Shapes
c.PushState();
{
c.DrawCircle(x, y, 25);
x += 100;
c.DrawCircleSegment(x, y, 25, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawLine(x, y , x + 50, y + 25);
c.DrawDashLine(x, y + 25, x + 50, y + 50);
c.DrawThickLine(x, y + 50, x + 50, y + 75, 3);
x += 100;
c.DrawOval(x, y, 50, 50);
x += 100;
c.DrawOvalSegment(x, y, 50, 50, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawPolygon(polygon, x, y);
x += 100;
c.DrawRect(x, y, 50, 50);
x += 100;
c.DrawText("Hello World", x, y, drawBackground: true);
x = baseX;
y += 100;
}
c.PopState();
// Filled Shapes
c.PushState();
{
c.FillCircle(x, y, 25);
x += 100;
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillThickLine(x, y + 25, x + 50, y + 50, 3);
x += 100;
c.FillOval(x, y, 50, 50);
x += 100;
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillPolygon(polygon, x, y);
x += 100;
c.FillRect(x, y, 50, 50);
x = baseX;
y += 100;
}
c.PopState();
}
示例5: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
// Create a buffer to cache and re-use vertices. Not required, but will boost performance.
if (this.buffer == null) this.buffer = new CanvasBuffer();
// Create a Canvas to auto-generate vertices from high-level drawing commands.
Canvas canvas = new Canvas(device, this.buffer);
canvas.State.TextFont = this.font;
// If the game is over or won, display "game over" screen
if (this.gameOver || this.gameWin)
{
// Various animation timing variables.
float animOffset = this.gameWin ? 0.0f : 2500.0f;
float animTime = this.gameWin ? 10000.0f : 4500.0f;
float blendDurationRatio = this.gameWin ? 0.6f : 0.5f;
float textOffsetRatio = this.gameWin ? 0.2f : 0.0f;
float timeSinceGameOver = (float)Time.MainTimer.TotalMilliseconds - this.lastTimeAnyAlive;
float gameOverAnimProgress = MathF.Clamp((timeSinceGameOver - animOffset) / animTime, 0.0f, 1.0f);
float controlInfoAnimProgress = MathF.Clamp(((timeSinceGameOver - animOffset) - animTime - 2000.0f) / 2000.0f, 0.0f, 1.0f);
float blendAnimProgress = MathF.Clamp(gameOverAnimProgress / blendDurationRatio, 0.0f, 1.0f);
float textAnimProgress = MathF.Clamp((gameOverAnimProgress - blendDurationRatio - textOffsetRatio) / (1.0f - blendDurationRatio - textOffsetRatio), 0.0f, 1.0f);
if (this.blendMaterial != null && blendAnimProgress > 0.0f)
{
canvas.PushState();
if (this.gameOver)
{
// Set up our special blending Material and specify the threshold to blend to
this.blendMaterial.SetUniform("threshold", 1.0f - blendAnimProgress);
canvas.State.SetMaterial(this.blendMaterial);
canvas.State.ColorTint = ColorRgba.Black;
// Specify a texture coordinate rect so it spans the entire screen repeating itself, instead of being stretched
if (this.blendMaterial.MainTexture != null)
{
Random rnd = new Random((int)this.lastTimeAnyAlive);
Vector2 randomTranslate = rnd.NextVector2(0.0f, 0.0f, canvas.State.TextureBaseSize.X, canvas.State.TextureBaseSize.Y);
canvas.State.TextureCoordinateRect = new Rect(
randomTranslate.X,
randomTranslate.Y,
device.TargetSize.X / canvas.State.TextureBaseSize.X,
device.TargetSize.Y / canvas.State.TextureBaseSize.Y);
}
}
else
{
// If we won, simply fade to white
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Add, ColorRgba.White));
canvas.State.ColorTint = ColorRgba.White.WithAlpha(blendAnimProgress);
}
// Fill the screen with a rect of our Material
canvas.FillRect(0, 0, device.TargetSize.X, device.TargetSize.Y);
canvas.PopState();
}
if (this.font != null && textAnimProgress > 0.0f)
{
canvas.PushState();
// Determine which text to draw to screen and where to draw it
string gameOverText = this.gameWin ? "is it over..?" : "darkness...";
Vector2 fullTextSize = canvas.MeasureText(gameOverText);
Vector2 textPos = device.TargetSize * 0.5f - fullTextSize * 0.5f;
gameOverText = gameOverText.Substring(0, MathF.RoundToInt(gameOverText.Length * textAnimProgress));
// Make sure not to draw inbetween pixels, so the text is perfectly sharp.
textPos.X = MathF.Round(textPos.X);
textPos.Y = MathF.Round(textPos.Y);
// Draw the text to screen
canvas.State.ColorTint = this.gameWin ? ColorRgba.Black : ColorRgba.White;
canvas.DrawText(gameOverText, textPos.X, textPos.Y);
canvas.PopState();
}
if (controlInfoAnimProgress > 0.0f)
{
Vector2 infoBasePos = device.TargetSize * 0.5f + new Vector2(0.0f, device.TargetSize.Y * 0.25f);
if (this.controlInfoMouseKeyboard != null)
{
canvas.PushState();
Vector2 texSize = this.controlInfoMouseKeyboard.Res.MainTexture.Res.Size * 0.5f;
canvas.State.SetMaterial(this.controlInfoMouseKeyboard);
canvas.State.ColorTint = ColorRgba.White.WithAlpha(controlInfoAnimProgress);
canvas.FillRect(
infoBasePos.X - texSize.X * 0.5f,
infoBasePos.Y - texSize.Y - 10,
texSize.X,
texSize.Y);
canvas.PopState();
}
//.........这里部分代码省略.........
示例6: OnCollectBackgroundDrawcalls
protected internal override void OnCollectBackgroundDrawcalls(Canvas canvas)
{
base.OnCollectBackgroundDrawcalls(canvas);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, this.BgColor.WithAlpha(0.75f)));
canvas.FillRect(0, 0, canvas.DrawDevice.TargetSize.X, canvas.DrawDevice.TargetSize.Y);
}
示例7: DrawTileHighlights
private static void DrawTileHighlights(Canvas canvas, ICmpTilemapRenderer renderer, Point2 origin, IReadOnlyGrid<bool> highlight, ColorRgba fillTint, ColorRgba outlineTint, TileHighlightMode mode, List<Vector2[]> outlineCache = null)
{
if (highlight.Width == 0 || highlight.Height == 0) return;
// Generate strippled line texture if not available yet
if (strippledLineTex == null)
{
PixelData pixels = new PixelData(8, 1);
for (int i = 0; i < pixels.Width / 2; i++)
pixels[i, 0] = ColorRgba.White;
for (int i = pixels.Width / 2; i < pixels.Width; i++)
pixels[i, 0] = ColorRgba.TransparentWhite;
using (Pixmap pixmap = new Pixmap(pixels))
{
strippledLineTex = new Texture(pixmap,
TextureSizeMode.Default,
TextureMagFilter.Nearest,
TextureMinFilter.Nearest,
TextureWrapMode.Repeat,
TextureWrapMode.Repeat,
TexturePixelFormat.Rgba);
}
}
BatchInfo defaultMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor);
BatchInfo strippleMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor, strippledLineTex);
bool uncertain = (mode & TileHighlightMode.Uncertain) != 0;
bool selection = (mode & TileHighlightMode.Selection) != 0;
Component component = renderer as Component;
Transform transform = component.GameObj.Transform;
Tilemap tilemap = renderer.ActiveTilemap;
Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null;
Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize;
Rect localRect = renderer.LocalTilemapRect;
// Determine the object's local coordinate system (rotated, scaled) in world space
Vector2 worldAxisX = Vector2.UnitX;
Vector2 worldAxisY = Vector2.UnitY;
MathF.TransformCoord(ref worldAxisX.X, ref worldAxisX.Y, transform.Angle, transform.Scale);
MathF.TransformCoord(ref worldAxisY.X, ref worldAxisY.Y, transform.Angle, transform.Scale);
Vector2 localOriginPos = tileSize * origin;
Vector2 worldOriginPos = localOriginPos.X * worldAxisX + localOriginPos.Y * worldAxisY;
canvas.PushState();
{
// Configure the canvas so our shapes are properly rotated and scaled
canvas.State.TransformHandle = -localRect.TopLeft;
canvas.State.TransformAngle = transform.Angle;
canvas.State.TransformScale = new Vector2(transform.Scale);
// Fill all highlighted tiles that are currently visible
{
canvas.State.SetMaterial(defaultMaterial);
canvas.State.ColorTint = fillTint * ColorRgba.White.WithAlpha(selection ? 0.2f : 0.375f);
// Determine tile visibility
Vector2 worldTilemapOriginPos = localRect.TopLeft;
MathF.TransformCoord(ref worldTilemapOriginPos.X, ref worldTilemapOriginPos.Y, transform.Angle, transform.Scale);
TilemapCulling.TileInput cullingIn = new TilemapCulling.TileInput
{
// Remember: All these transform values are in world space
TilemapPos = transform.Pos + new Vector3(worldTilemapOriginPos) + new Vector3(worldOriginPos),
TilemapScale = transform.Scale,
TilemapAngle = transform.Angle,
TileCount = new Point2(highlight.Width, highlight.Height),
TileSize = tileSize
};
TilemapCulling.TileOutput cullingOut = TilemapCulling.GetVisibleTileRect(canvas.DrawDevice, cullingIn);
int renderedTileCount = cullingOut.VisibleTileCount.X * cullingOut.VisibleTileCount.Y;
// Draw all visible highlighted tiles
{
Point2 tileGridPos = cullingOut.VisibleTileStart;
Vector2 renderStartPos = worldOriginPos + tileGridPos.X * tileSize.X * worldAxisX + tileGridPos.Y * tileSize.Y * worldAxisY;;
Vector2 renderPos = renderStartPos;
Vector2 tileXStep = worldAxisX * tileSize.X;
Vector2 tileYStep = worldAxisY * tileSize.Y;
int lineMergeCount = 0;
int totalRects = 0;
for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++)
{
bool current = highlight[tileGridPos.X, tileGridPos.Y];
if (current)
{
// Try to merge consecutive rects in the same line to reduce drawcalls / CPU load
bool hasNext = (tileGridPos.X + 1 < highlight.Width) && ((tileGridPos.X + 1 - cullingOut.VisibleTileStart.X) < cullingOut.VisibleTileCount.X);
bool next = hasNext ? highlight[tileGridPos.X + 1, tileGridPos.Y] : false;
if (next)
{
lineMergeCount++;
}
else
{
totalRects++;
canvas.FillRect(
transform.Pos.X + renderPos.X - lineMergeCount * tileXStep.X,
transform.Pos.Y + renderPos.Y - lineMergeCount * tileXStep.Y,
//.........这里部分代码省略.........
示例8: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
if (device.IsScreenOverlay)
{
// Testbed text
Vector2 nameSize = this.name.Measure().Size;
Vector2 descSize = this.desc.Measure().Size;
Vector2 ctrlSize = this.controls.Measure().Size;
Vector2 statsSize = this.stats.Measure().Size;
canvas.PushState();
// Text background
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(10, 10, MathF.Max(nameSize.X, descSize.X, ctrlSize.X) + 20, nameSize.Y + descSize.Y + 10 + ctrlSize.Y + 10);
canvas.FillRect(10, DualityApp.TargetResolution.Y - 20 - statsSize.Y, statsSize.X + 20, statsSize.Y + 10);
// Caption / Name
canvas.CurrentState.ColorTint = ColorRgba.White.WithAlpha(0.85f);
canvas.DrawText(this.name, 20, 15);
// Description, Controls, Stats
canvas.CurrentState.ColorTint = ColorRgba.White.WithAlpha(0.65f);
canvas.DrawText(this.desc, 20, 15 + nameSize.Y);
canvas.DrawText(this.controls, 20, 15 + nameSize.Y + descSize.Y + 10);
canvas.DrawText(this.stats, 20, DualityApp.TargetResolution.Y - 15 - statsSize.Y);
canvas.PopState();
// Mouse cursor
canvas.DrawCross(DualityApp.Mouse.X, DualityApp.Mouse.Y, 5.0f);
}
else
{
// Mouse joint, if existing
if (this.mouseJoint != null)
{
Vector3 jointBegin = this.mouseJoint.BodyA.GameObj.Transform.GetWorldPoint(new Vector3(this.mouseJoint.LocalAnchor, -0.01f));
Vector3 jointEnd = new Vector3(this.mouseJoint.WorldAnchor, -0.01f);
canvas.CurrentState.ColorTint = ColorRgba.Red.WithAlpha(0.5f);
canvas.DrawLine(jointBegin.X, jointBegin.Y, jointBegin.Z, jointEnd.X, jointEnd.Y, jointEnd.Z);
}
}
}
示例9: DrawVertexHandles
private void DrawVertexHandles(Canvas canvas, Vector2[] polyVert, float colliderAlpha,Transform bodyTransform)
{
foreach (Vector2 vertex in polyVert)
{
bool vertexSelected = IsSelected(v => (v.ActualObject as Vector2?) == vertex);
float vertexAlpha = colliderAlpha*(vertexSelected ? 1.0f : 0.5f);
ColorRgba color = this.VertexColor.WithAlpha(vertexAlpha);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, color));
float z = bodyTransform.Pos.Z;
float size = VertexSize/GetScaleAtZ(z);
Vector2 position = bodyTransform.GetWorldPoint(vertex);
canvas.FillRect(position.X - size/2, position.Y - size/2, z, size, size);
canvas.DrawRect(position.X - size/2, position.Y - size/2, z, size, size);
}
}
示例10: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
// Create a buffer to cache and re-use vertices. Not required, but will boost performance.
if (this.buffer == null) this.buffer = new CanvasBuffer();
// Create a Canvas to auto-generate vertices from high-level drawing commands.
Canvas canvas = new Canvas(device, this.buffer);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
canvas.State.TextFont = this.font;
// Retrieve players
if (this.playerOne == null)
this.playerOne = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerOne).FirstOrDefault();
if (this.playerTwo == null)
this.playerTwo = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerTwo).FirstOrDefault();
// Is someone playing using mouse / keyboard? Display a mouse cursor then
if (Player.AlivePlayers.Any(p => p.InputMethod == InputMethod.MouseAndKeyboard))
{
canvas.FillCircle(DualityApp.Mouse.X, DualityApp.Mouse.Y, 2.0f);
}
// Is any player alive? Keep that value in mind, won't change here anyway.
bool isAnyPlayerAlive = Player.IsAnyPlayerAlive;
// Draw health and info of player one
if (this.IsPlayerActive(this.playerOne))
{
Ship playerShip = this.playerOne.ControlObject;
if (playerShip.Active)
{
// Draw a health bar when alive
float health = playerShip.Hitpoints;
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(12 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);
canvas.State.ColorTint = this.playerOne.Color;
canvas.DrawRect(10, device.TargetSize.Y - 10 - 200, 20, 200);
canvas.FillRect(12, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
}
else if (isAnyPlayerAlive && !this.playerOne.HasReachedGoal)
{
// Draw a respawn timer when dead
float respawnPercentage = this.playerOne.RespawnTime / Player.RespawnDelay;
string respawnText = string.Format("Respawn in {0:F1}", (Player.RespawnDelay - this.playerOne.RespawnTime) / 1000.0f);
Vector2 textSize = canvas.MeasureText(string.Format("Respawn in {0:F1}", 0.0f));
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(10 - 1, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 5, textSize.Y + 8);
canvas.State.ColorTint = this.playerOne.Color;
canvas.DrawText(respawnText, 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomLeft);
canvas.FillRect(10, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
canvas.FillRect(10, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
}
}
// Draw health and info of player two
if (this.IsPlayerActive(this.playerTwo))
{
Ship playerShip = this.playerTwo.ControlObject;
if (playerShip.Active)
{
// Draw a health bar when alive
float health = playerShip.Hitpoints;
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(device.TargetSize.X - 12 - 16 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);
canvas.State.ColorTint = this.playerTwo.Color;
canvas.DrawRect(device.TargetSize.X - 10 - 20, device.TargetSize.Y - 10 - 200, 20, 200);
canvas.FillRect(device.TargetSize.X - 12 - 16, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
}
else if (isAnyPlayerAlive && !this.playerTwo.HasReachedGoal)
{
// Draw a respawn timer when dead
float respawnPercentage = this.playerTwo.RespawnTime / Player.RespawnDelay;
string respawnText = string.Format("{0:F1} to Respawn", (Player.RespawnDelay - this.playerTwo.RespawnTime) / 1000.0f);
Vector2 textSize = canvas.MeasureText(string.Format("{0:F1} to Respawn", 0.0f));
canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X - 3, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 2, textSize.Y + 10);
canvas.State.ColorTint = this.playerTwo.Color;
canvas.DrawText(respawnText, device.TargetSize.X - 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomRight);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
}
}
}