Browse Source
add Debug class for displaying rects on-screen
add Debug class for displaying rects on-screen
use it to display bounding boxes of player & obstacles
GitOrigin-RevId: 1354637c8a
master
Colin McMillen
4 years ago
4 changed files with 89 additions and 24 deletions
-
58Jumpy.Shared/Debug.cs
-
1Jumpy.Shared/Jumpy.Shared.projitems
-
35Jumpy.Shared/JumpyGame.cs
-
19Jumpy.Shared/Player.cs
@ -0,0 +1,58 @@ |
|||
using Microsoft.Xna.Framework; |
|||
using Microsoft.Xna.Framework.Graphics; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Jumpy { |
|||
// TODO: add a WriteLine sort of functionality.
|
|||
static class Debug { |
|||
struct DebugRect { |
|||
public Rectangle rect; |
|||
public Color color; |
|||
|
|||
public DebugRect(Rectangle rect, Color color) { |
|||
this.rect = rect; |
|||
this.color = color; |
|||
} |
|||
} |
|||
|
|||
public static bool Enabled; |
|||
static List<DebugRect> rects = new List<DebugRect>(); |
|||
static Texture2D whiteTexture; |
|||
|
|||
|
|||
public static void Initialize(GraphicsDevice graphics) { |
|||
whiteTexture = new Texture2D(graphics, 1, 1); |
|||
whiteTexture.SetData(new Color[] { Color.White }); |
|||
} |
|||
|
|||
public static void Clear() { |
|||
rects.Clear(); |
|||
} |
|||
|
|||
public static void AddRect(Rectangle rect, Color color) { |
|||
rects.Add(new DebugRect(rect, color)); |
|||
} |
|||
|
|||
public static void Draw(SpriteBatch spriteBatch) { |
|||
if (!Enabled) { |
|||
return; |
|||
} |
|||
foreach (var debugRect in rects) { |
|||
var rect = debugRect.rect; |
|||
var color = debugRect.color; |
|||
// top side
|
|||
spriteBatch.Draw( |
|||
whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color); |
|||
// bottom side
|
|||
spriteBatch.Draw( |
|||
whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color); |
|||
// left side
|
|||
spriteBatch.Draw( |
|||
whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color); |
|||
// right side
|
|||
spriteBatch.Draw( |
|||
whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color); |
|||
} |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue