1

I'm porting a simple tetris-like XNA app to Android, using Mono For Android and MonoGame; I have followed the suggested steps in this link and so far, everything compiles well, and no relevant warnings fire up. However, upon loading the contents, a null parameter exception breaks the program at the point below in my program:

protected override void LoadContent() {
    // ...
    _font = Content.Load<Microsoft.Xna.Framework.Graphics.SpriteFont>("SpriteFont1");
    // ... 
}

The content root directory is set in the game constructor class:

public Game2 (){
Content.RootDirectory = "Content";
Content.RootDirectory = "Assets/Content"; // TEST.
//...}

And I have tried several combinations, all to no avail.

I have also tried setting the xnb files as Content as well as Android Assets in the Build Action property; having the linked, copied always, copied only if newer... etc.

Either way, my problem is that I don't really understand WHY and HOW should I do this. I'm rather new to the platform and to XNA as well, so this may very well be a newbie question, but the truth is after several hours banging my head and fists against the monitor/keyboard I feel stuck and need your help.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
user1463169
  • 11
  • 1
  • 2

2 Answers2

0

MonoGame (2.5.1) throws NotImplementedException in ContentManager.Load for SpriteFont type. Have the same not resolved problem. I'm trying not to use DrawString.

For loading textures in Win32 application I use:

Content.RootDirectory = @"../../Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");

You even must not add it to solution.

For Andoind (MonoDroid) application you must add "Content" folder to your solution and set "Andtoid Asset" in "Sample.png" properties.

Content.RootDirectory = "Content";
var sampleTexture = Content.Load<Texture2D>("Sample.png");

See also:

http://monogame.codeplex.com/discussions/360468

http://monogame.codeplex.com/discussions/267900

user1471935
  • 521
  • 5
  • 6
0

I have a library that supports variable-width fonts (generated by BMFont) on MonoGame. Unfortunately it is a renderer and so has other code around it. However, the basic idea is very simple. You can take a look at the loader here and the mesh builder (given a string) here. This builder supports fonts that spread characters across multiple pages, too.

Hope this helps!

Ani
  • 10,826
  • 3
  • 27
  • 46