user3621741
user3621741

Reputation: 11

SharpDX Toolkit: Draw Text

I want to draw some text in my Toolkit Game with the following code:

SpriteFont spriteFont;
Vector2 pointStringPosition = new Vector2(5, 5);
int intPoints = 0;
//...
Content.RootDirectory = "Content";
//...
spriteFont = Content.Load<SpriteFont>("Schrift.xml");
//...
spriteBatch.DrawString(spriteFont, intPoints.ToString(), pointStringPosition, Color.DarkOrange);

Schrift.xml is in the Content folder and constitutes this:

<?xml version="1.0" encoding="utf-8" ?>
<TkFont>
  <FontName>Arial</FontName>
  <Size>13</Size>
  <Spacing>0</Spacing>
  <LineSpacing>0</LineSpacing>
  <UseKerning>false</UseKerning>
  <Format>Auto</Format>
  <CharacterRegions>
    <CharacterRegion>
      <Start>32</Start>
      <End>127</End>
    </CharacterRegion>
  </CharacterRegions>
  <DefaultCharacter>32</DefaultCharacter>
  <Style>Regular</Style>
  <NoPremultiply>false</NoPremultiply>
</TkFont>

If the .csproj constitutes this:

<ToolkitFont Include="Content\Schrift.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ToolkitFont>

It throw an AssetNotFoundException.

If the .csproj constitutes this:

<Content Include="Content\Schrift.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

It says:

Registered ContentReader of type [SharpDX.Toolkit.Graphics.SpriteFontContentReader] fails to load content of type [SharpDX.Toolkit.Graphics.SpriteFont] from file [Schrift.xml].

If the .csproj constitutes this:

<ToolkitFont Include="Content\Schrift.xml">
      <Link>Content\Schrift.xml</Link>
</ToolkitFont>

I get an error, because the Link element doesn't work.

What is wrong? Or is there a better / easier oportunity to draw text with SharpDX?

Upvotes: 1

Views: 1983

Answers (2)

Geoffrey
Geoffrey

Reputation: 976

I had the same issue, but it was due to the fact that I had not put the Build Action to "TookitFont"

So in code without .xml extension

and in the file properties:

  • Build Action: ToolkitFont
  • Copy to Output Directory: Copy if newer

Or in the .csproj file:

<ToolkitFont Include="Content\Arial16.xml">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ToolkitFont>

Upvotes: 1

xoofx
xoofx

Reputation: 3762

The SharpDX Toolkit doesn't use XNA file format but a custom YAML format. Check the samples and specifically the SpriteFontApp

Upvotes: 1

Related Questions