Problems opening from Build Folder

bonajkukoj

New Member
Joined
May 21, 2020
Hello,

I'm having a problem concerning the HTML5 Target.
When I launch my game from the Cerberus Editor pressing F5, it works normally.
But if I try to open the CerberusGame.html from my build folder, I only get a black screen.

What could I have possibly messed up?

Any help is appreciated.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Html5 Target is technically Javascript code running within a html file. So you need an environment that can run Javascript. When you run it with F5 the IDE is starting cerberus server to run the app.
Other ways to run your app is to upload it on a webspace or to locally install a server on your machine (like Xampp, Mamp) and run it from there.
 

bonajkukoj

New Member
Joined
May 21, 2020
Thanks for your replies.

The thing is, that apparently this seems to be connected to mojo2.
When I use mojo, it works normally, also just clicking on the html in the build folder.

I'm just testing a basic game setup, loading a jpg as a background and moving around with the arrow keys.
Could it be the Canvas Object creating this? Because apart from that I don't see big differences.

My OnRender()-Method looks like this in mojo (no problem opening the game outside the IDE):

DrawImage(Background,X,Y)

While in the mojo2-Version I use this (after declaring a Field GameCanvas:Canvas):

GameCanvas.DrawImage(Background, X,Y)
GameCanvas.Flush()

But I'll try using the WebServer for Chrome, maybe it helps.
Edit: It helps:)
 
Last edited:

Holzchopf

Moderator
3rd Party Module Dev
Joined
Jul 31, 2017
Location
Bern, Switzerland
The solution (using XAMPP, MAMP, Web Server for Chrome...) already has been stated. But I'd just like to clarify:

It's only particularly connected to mojo2. Actually, it's connected to how some resources are loaded. When you open your cerberusgame.html file from explorer, it's loaded with the file:// protocol. Then, the javascript will try to load resources via XMLHttpRequest with the same protocol (file://) which - for very valid security reasons - will be blocked by the browser.

Now, why does it work with mojo? Apparently, images are loaded differently (if I understand the generated JS correctly, it simply creates an image element, sets the resource path and then the browser handles the image loading on its own). But other resources are loaded using the XMLHttpRequest - other resources like the mojo2_program.glsl shader which mojo2 depends on. But you'd run into the same problem with mojo when trying to load something different that image files (strings/data for levels, audio...).
 
Top Bottom