MonoGame for Web (Alpha Release)

Please read the following topic before commenting/asking questions on this one: MonoGame inside your web browser

This is an alpha release of MonoGames web version, there are several parts unimplemented, as such, do not expect everything to work out of the box. Feel free to report any issues you find on the MonoGame GitHub issue tracker, I’ll prioritize implementing stuff that you request.

How to use:

# install template
dotnet new -i MonoGame.Template.Bridge.CSharp

# create project
dotnet new mgbridge

# build project (or just open the project file in your preferred IDE and build it from there)
dotnet restore
msbuild

# Open up index.html in your bin folder using Firefox to launch the game

FAQ:

Where should I run those commands from on Windows?

It should be called something along the lines of Visual Studio console. Make sure that you change your current directory before creating your project tho.

Can you make templates for Visual Studio

Once we get to a beta stage I’ll look into making the templates available from the GUI.

Rider IDE on the other hand will automatically pick up these templates so you can use it for creating your project.

Why can’t I run my game from Chrome/Opera/Vivaldi?

You actually can, but you have to start a web server before hand. This is because chrome does not allow resource loading from “file://”, while Firefox allows it as long as the original web page is also under “file://”.

Why can’t I run the game from Edge/Safari

They do not support WebGL 2.

Content loading freezes the page and takes a long time

Ah yes, this is a bit of a pickle and will require some new API. For now use the FromURL functions, like Texture2D.FromURL and make async methods for your content loading. They are implemented for more problematic types.

Can I modify index.html?

Yes, you can disable its generation in bridge.json file. Look at MonoGames example web game for an example on how to do it.

Any examples?

Yes, https://github.com/MonoGame/MonoGame.WebDemo

9 Likes

What is the tech behind this? Blazer or anything like that?

       

Sorry, was scanning and reading fast. When you put FAQ and bold sub sections my eyes are drawn there.

Is it compatible with Electron or Electron.NET? I am really looking forward to it :open_mouth:

does it support 3d rendering?

It does, however I did not fix the model reader as I am tinkering with getting content pipeline fixed up.

1 Like

Does Model reader work yet?

I think it does, if it does not just report it and I’ll see if I can get it fixed.

Did some tests and unfortunately it will not load Model.
Tried different uncompressed models, textured and no-textured, converted with mg3.6 and mg3.7 but program always stops somewhere in Model reader.

Just checked, content loading works fine for me. Did you run the game in Chrome, Chrome does not support loading content from file:// urls so you need to use Firefox for local testing, or you have to setup a local web server.

PS. Use TextureCompression.Color, I keep forgetting to setup DXT to work, its not even difficult, literally 10 lines of code…

Thanks for checking.
Using firefox. Platformer2D sample works and used it as test.

But when I add these lines to GameContent.cs:

public static Model tempmod;

Init() function:
tempmod=await content.LoadASync< Model >(“models/mymodel”);
Counter+=100; // just to show it goes here

program stops somewhere when loading model. It does not ever go to that Counter+=100; line.

Tried several models (ie box, plane, boxes), textured and untextured, compiled them different version of mgcb.exe but no luck.

Any ideas?

I still would like to use wait content.LoadASync < Model > (“some3dmodel”);
because I cant get it to work (tested with windows and linux).

Texture2D and sounds works but cant get LoadASync < Model > to work.

edited: I meant LoadASync(), not Load()

Ah, I see, I forgot to push one class that was needed for it… I feel dumb now.

1 Like

I’m using a reference that works fine of DesktopGL, but when converting my project to your webGL, the references no longer work, Saying that
Severity Code Description Project File Line Suppression State
Error CS7069 Reference to type ‘DrawableGameComponent’ claims it is defined in ‘MonoGame.Framework’, but it could not be found Interstellar Rescue C:\Users\Bulat Malikov\Desktop\web\Interstellar Rescue\Game1.cs 78 Active

How would I fix this?