for some reason whenever I load the font it acts like it all works as its supposed to work. however when I actually try to set the center of the text this happens :
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
When I remote that center part it draws but it just draws as I think arial but definitely not the font that I am loading in.
Code :
class MainMenu : Scene
{
Font TidyHandFont;
List<Shape> lines = new List<Shape>();
String2D headerText = new String2D();
Color clearColor = new Color(249, 249, 249);
public void Draw(float frameTime)
{
Program.renderWindow.Clear(clearColor);
foreach (Shape shape in lines)
{
Program.renderWindow.Draw(shape);
Program.renderWindow.Draw(headerText);
}
Program.renderWindow.Display();
}
public void Think(float frameTime)
{
Program.renderWindow.DispatchEvents();
}
public void Init()
{
try
{
TidyHandFont = new Font(@"Content/Fonts/TidyHand.ttf");
}
catch
{
}
Color lineColor = new Color(234,234,234);
uint Width = Program.renderWindow.Width;
for (int i = 0; i < Program.renderWindow.Height / 25; i++)
{
Shape shape = new Shape();
shape.AddPoint(new Vector2(0,i * 25),lineColor);
shape.AddPoint(new Vector2(Width, i * 25), lineColor);
shape.AddPoint(new Vector2(0, i * 25 + 2), lineColor);
shape.AddPoint(new Vector2(Width, i * 25 + 2), lineColor);
lines.Add(shape);
}
headerText.Text = "A cup of tea and a bandit, TEA BANDIT";
headerText.Position = new Vector2(Width / 2, 50);
headerText.Center = new Vector2((headerText.Font.CharacterSize * headerText.Text.Length) / 2, headerText.Font.CharacterSize / 2);
headerText.Color = new Color(2, 49, 153);
}
}
Why is this happening ?