Add hitbox outline utility method

This commit is contained in:
Thimo 2020-11-08 14:12:08 +01:00
parent d6713c3a96
commit decb8b855d
2 changed files with 22 additions and 3 deletions

View File

@ -12,7 +12,7 @@ namespace Strawberry.Sample
public this(Point pos)
: base(pos)
{
Hitbox = Rect(-4, -8, 8, 8);
Hitbox = Rect(-4, -8, 16, 16);
Add(tJumpGrace = new Timer());
Add(tVarJump = new Timer());
@ -102,8 +102,8 @@ namespace Strawberry.Sample
{
base.Draw();
DrawHitbox(.Green);
//Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8);
DrawHitboxOutline(.Green);
Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8);
}
}
}

View File

@ -238,6 +238,20 @@ namespace Strawberry
}
}
public Rect SceneHitboxOutline
{
[Inline]
get
{
Rect hb = Hitbox + Position;
hb.X -= 1;
hb.Y -= 1;
hb.Width += 2;
hb.Height += 2;
return hb;
}
}
public int Left
{
[Inline]
@ -463,6 +477,11 @@ namespace Strawberry
Game.Batcher.Rect(SceneHitbox, color);
}
public void DrawHitboxOutline(Color color)
{
Game.Batcher.Rect(SceneHitboxOutline, color);
}
public T SceneAs<T>() where T : Scene
{
Runtime.Assert(Scene is T, "Scene type mismatch!");