c# - How to draw every characters with spritefont in monogame -


i'm new monogame, , i'm trying make .spritefont file in order draw string font choose.

strings english characters can show on screen, wish draw strings in multiple languages, japanese , chinese.

so, tried load characters in multi language font "microsoft jhenghei".

the font's first character !(u+0021) , last 1 ○(u+ffee).

but when tried compile program, compiler gave me error:

.../content/myfont.spritefont : error : importer 'fontdescriptionimporter' had unexpected failure!

system.reflection.targetinvocationexception: exception has been thrown target of invocation. ---> system.argumentexception: characterregion.end must greater characterregion.start

at microsoft.xna.framework.content.pipeline.graphics.fontdescription.set_characterregions(characterregion[] value)

and when changed ○ 忮, msbuild stucks , takes forever proceed content.

code in myfont.spritefont below:

<?xml version="1.0" encoding="utf-8"?> <xnacontent xmlns:graphics="microsoft.xna.framework.content.pipeline.graphics">   <asset type="graphics:fontdescription">     <fontname>microsoft jhenghei</fontname>     <size>14</size>     <spacing>0</spacing>     <usekerning>true</usekerning>     <style>regular</style>     <characterregions>       <characterregion>         <start>&#x0021;</start>         <end>&#xffee;</end>       </characterregion>     </characterregions>   </asset> </xnacontent> 

i searched solution few days in vain, appreciated.

since processing 65 thousand characters takes time. should process characters using.

so easiest way make monogame custom content pipeline , load characters using .resx files.

it took me time searching solution. i'll post how did succeed, hope can has same question in future.

step-by-step tutorial

  1. create class library.

  2. reference monogame.framework.content.pipeline.portable package using nuget. (make sure checked include prerelease checkbox )

  3. download localizationsample here , unzip file.

  4. under localizationpipeline\ copy localizedfontdescription.cs , localizedfontprocessor.cs class library

  5. build class library outputs localizationpipeline.dll file.

  6. open myfont.spritefont , change asset type localizationpipeline.localizedfontdescription

  7. then add resources <resourcefiles><resx>..\strings.resx</resx></resourcefiles> (these files should contain string want draw)

  8. open content.mgcb , reference localizationpipeline.dll

  9. set myfont.spritefont's processor localizedfontprocessor

  10. rebuild project.

myfont.spritefont

<?xml version="1.0" encoding="utf-8"?> <xnacontent xmlns:graphics="microsoft.xna.framework.content.pipeline.graphics">   <asset type="localizationpipeline.localizedfontdescription">     <fontname>microsoft jhenghei</fontname>     <size>14</size>     <spacing>0</spacing>     <usekerning>true</usekerning>     <style>regular</style>     <characterregions>       <characterregion>         <start>&#32;</start>         <end>&#126;</end>       </characterregion>     </characterregions>     <resourcefiles>       <resx>..\strings.resx</resx>     </resourcefiles>   </asset> </xnacontent> 

content.mgcb

... #-------------------------------- references --------------------------------#  /reference:..\localizationpipeline.dll  #---------------------------------- content ---------------------------------# ... #begin myfont.spritefont /importer:fontdescriptionimporter /processor:localizedfontprocessor /build:myfont.spritefont ... 

sources

  1. part 1 of creating custom content importers monogame pipeline

  2. how to: create localized game

  3. localizationsample (thanks @groo giving me link.)


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -