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>!</start> <end>○</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
create class library.
reference
monogame.framework.content.pipeline.portablepackage usingnuget. (make sure checkedinclude prereleasecheckbox )download
localizationsamplehere , unzip file.under
localizationpipeline\copylocalizedfontdescription.cs,localizedfontprocessor.csclass librarybuild class library outputs
localizationpipeline.dllfile.open
myfont.spritefont, change asset typelocalizationpipeline.localizedfontdescriptionthen add resources
<resourcefiles><resx>..\strings.resx</resx></resourcefiles>(these files should contain string want draw)open
content.mgcb, referencelocalizationpipeline.dllset
myfont.spritefont's processorlocalizedfontprocessorrebuild 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> </start> <end>~</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
part 1 of creating custom content importers monogame pipeline
localizationsample (thanks @groo giving me link.)
Comments
Post a Comment