SFML community forums

Bindings - other languages => DotNet => Topic started by: Xyro on March 18, 2011, 12:03:35 am

Title: font won't load properly
Post by: Xyro on March 18, 2011, 12:03:35 am
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 :

Code: [Select]
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 :

Code: [Select]
   
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 ?
Title: font won't load properly
Post by: Laurent on March 18, 2011, 07:39:53 am
Can you get more detailed information with the debugger?
Title: font won't load properly
Post by: Xyro on March 18, 2011, 11:14:50 am
How ?

Also this : http://i52.tinypic.com/210x9oz.png

for some reason the lines are not from the left to the right, they only seem to cover half the screen.

Edit :

forgot to add this into my code :

Code: [Select]

            headerText.Font = TidyHandFont;


it now displays properly only I still can't set the center. and the lines are still weird :S

It seems to come specifically from this : Text.Lenght because when I added this :
Code: [Select]

            int lenght = headerText.Text.Length;

it also crashed.[/code]
Title: font won't load properly
Post by: Laurent on March 18, 2011, 01:03:42 pm
Quote
How ?

If you run your application with the debugger (F5) it should stop at the moment of the crash, indicating the source file/line as well as other useful information such as the callstack and local variables.
Title: font won't load properly
Post by: Xyro on March 18, 2011, 01:52:26 pm
I already did that and then it stops on the  

Code: [Select]
int lenght = headerText.Text.Length

and throws the exception, nothing seems wrong with it :S

damm more problems, for some reason this :

Code: [Select]

            headerText.Position = new Vector2(Width / 2, 50);
            headerText.Center = new Vector2((headerText.Size * text.Length) / 2, headerText.Size / 2);


Doesn't put the text in the middle of the screen (on the x axis)

and is there a option too smooth the font because it now looks horrible
Title: font won't load properly
Post by: Laurent on March 18, 2011, 02:16:10 pm
Quote
and is there a option too smooth the font because it now looks horrible

The font must be loaded with the same size as the text characters.
Title: font won't load properly
Post by: Xyro on March 18, 2011, 03:09:22 pm
How would that translate into code if lets say the fonts size is 32
Title: font won't load properly
Post by: Laurent on March 18, 2011, 03:16:15 pm
For Font it's the second argument of the constructor, and for String2D it's the Size property (or CharacterSize, I don't remember). If they match the text should look good.
Title: font won't load properly
Post by: Xyro on March 18, 2011, 07:49:01 pm
Still got the same problems, the I loaded the font with size 30 and set the 2d text to 30 and it looked like shit and the lines that I put on 0 till the width of the screen and it still only draws like half of the screen.