MonoGame inside your web browser

Btw, when building fonts with mgcb 3.8, these doesnt work with mgweb (mg3.7) (and these fonts doesnt work with FNA either). Luckily I have some builded fonts from 3.7.

I added my game files to Platformer2D as you suggested and it almost builds :slight_smile:

I have 2 issue:
It does not like the Directory class (Its .Net Core only I think) so my load/save code will not compile.
I can rip that out as probably don’t want that anyway in the browser version.

The other problem is the fonts. I am using the monogame.extended.BitmapFonts.BitmapFont class and there are 2 problems.

  1. The content builder won’t build the fonts:
    Error: Couldn’t find a default importer for font. I think I will have to revert back to the MGCB 3.7 version.

  2. The code does not compile any of the font.MeasureString() calls. Each line gives these 2 errors:
    The type ‘ValueType’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.
    The type ‘Object’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

I can possibly revert to the ordinary font code to get around this. Was just wondering if this is the same problem you mention above.

Well if anyone is interested I got the game to compile by reverting to SpriteFonts and removing my Load/Save code.

It runs in Chrome too … sort of.

Unfortunately, it’s really really slow - far too slow to be usable.
I think this may be because I have some very large textures - my main background is 1606x1685.

I’ve found the webgl2 version to be way faster.

MG Web uses only webgl2. (edit: uses webgl1 as harry-cpp mentions below)

“I think this may be because I have some very large textures - my main background is 1606x1685.”
Test it with some test-bg 128x128 if it makes a difference, but I doubt it (webgl can use larger textures if I understood webgl2 spec right).
Slowdowns will come if you use lots of spriteBatch.Begin() and spriteBatch.End(), the more render calls (which that .End() puts, renders batched sprites), the slower program is.

Use big bg and sprite atlas for other graphis and fonts, then there are 3 drawcalls and should be fast.

There’s an older version that uses webgl1. I support this too so my games can be played on iPad.

The newest Bridge.NET version of MonoGame uses WebGL 1, I have not updated the nuget (nor will I as wasm version is in the works).

The demo at https://www.monogame.net/webdemo/ is compiled against it, you can, and I have tested it, run it inside Microsoft Edge on Windows Phone… also Safari.

Ah that’s it. It’s the other one I use for webgl2.

Is there any way I can contribute to the web project? Including financially.

Thanks for the information.
I draw everything in a single spriteBatch.Begin() in Game1.cs Draw().

There is a lot of scaling of sprites including the very large texture as I have a zoom in/out capability, so that is another candidate for the slow performance.
It has other problems also such as my Button class which draws a Filled Rectangle, Rectangle Border and Some text, only shows the text.

This is a really neat idea, and I have only myself to blame for waiting until project completion before attempting to hook it in.

I’ll take a look at the wasm version when it comes along.

Hello everyone! Important question: I have my Asp.Net Mvc site, in which I would like to insert my game, how do I somehow convert bridge into asp.net mvc, because bridge generates an index file for me that I can open, but I don’t know how to join it to my asp.net mvc project, which by doing the build opens the site directly to me locally

Hello all,

I’m trying to compile and run the platformer example.
First of all, I had to comment out this line
//[assembly: System.Reflection.AssemblyMetadataAttribute(“RepositoryUrl”, “https://github.com/cra0zy/MonoGame/tree/bridge”)]

in the generated Debug\net47\MonoGame.Framework.Bridge.AssemblyInfo.cs file, because it doesn’t recognize ‘AssemblyMetadataAttribute’. Once I do it, I can compile (as long as I don’t clean or change the project file), but when I try to run it in any browser, I only see this:

And that’s it, it never progresses.
Any ideas what’s going wrong?

Thanks

@Lajbert
You need to access it via a server. You can’t just launch it from your hard drive by clicking the index.html.

The simplest you can do: Install python3. Run python -m http.server in the root directory where your index.html is and then go to localhost:8000 (or whatever port the console tells you to go) and then you can play it :slight_smile:

I hope this helped.

1 Like

It workdet, thanks!

A question for those in the know (like @harry-cpp ), how far are we from a nativeAOT wasm based monogame deployment in the browser?

Anyone know if there’s a way to download to someone’s local browser a compressed version of a texture and then converting it to the uncompressed format it supports? Load times are slow.

I also noticed they’re much slower with the webgl1 version from the source tree than with the webgl2 version that nuget pulls in.

Where are we at to have a webassembly version? I really need it, I know how complicated development can be but we have been waiting for years now.

I’ve been asking about the same thing too!

I am using the - GitHub - harry-cpp/MonoGame at bridge - and it is great.
I get the html + javascript, and it generates a canvas -
but how to use the Monogame.Extended library in a project like this?

I want to be able to do things like drawing basic graphic elements like circles ect., but when trying to do spriteBatch.DrawCircle() - is gives this error:

Could not find file ‘C:\Users\mkjer\source\repos\monogameGrammatonWeb\bin\Debug\net47\System.dll’. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)…ect.

  • any ideas?

Does this support thirdparty software such as monogame extended?

It should be fine, but you’d have to recompile it.