Publishing to the Web

A Blitz3D+ program can run in a web browser, so anyone can play it from a link without installing anything. Blitz3D+ compiles the program to WebAssembly, draws with WebGPU, and writes a web build: one web page that holds the whole program, which any web host can serve.

Trying a program in the browser

  1. Open the main source file in the IDE.
  2. Open the Program menu and choose Run in browser.

The IDE compiles the program for the web and opens it in your default browser. Click the page to start it: browsers only start sound, full screen and mouse capture after a click. Close the tab, or end the program as usual, to stop it. The IDE serves the program to your browser from this computer until you run another program in the browser or close the IDE.

Creating a web build

  1. Choose Program > Create web build....
  2. Choose where to save it. The IDE suggests a page named after your program, such as castle.html, writes it, and offers to open it in the browser.
  3. Upload that one file to a web host, and link to it from your site. Any static host works, such as GitHub Pages or Netlify. For itch.io, save the page as index.html and upload it in a zip file as an HTML5 game.

The page contains everything the program needs, compressed: the Blitz3D+ web runtime, your compiled program, and every file in your program's folder, such as models, images and sounds. Keep a program's files in its folder, or in folders below it, as you would for an executable. Your .bb source files are left out, so publishing a game does not publish its code. Several games' pages can share a folder on your site, and Chrome and Edge also open a page straight from your computer, without a web host.

For a very large game, tick Create a folder instead in the save dialog. The IDE then writes a folder of separate files, named after your program, which needs less memory while it loads and starts sooner: its page downloads first the files your program loads by name and what the worlds it loads need at the start, and the rest while the game runs. A single page cannot, since everything in it arrives at once. Upload the folder's contents; for itch.io, zip them with index.html at the top. The folder's page fetches each file as a part of program.b3dpak, which most web hosts allow; on one that does not, it downloads the whole file first, as before.

To update a published game, create its web build again and upload it over the old one. Players who come back get the new version without refreshing the page themselves, on any web host. Browsers keep a game's files between visits, and unless the web host says otherwise, they guess from each file's date how long it stays current. So a folder's program.json names a version of each of its other files, which changes whenever the file does; the page asks the host for program.json on every visit, and loads the web runtime, your program and the rest by those versions. A returning player therefore never gets your new program with a web runtime the browser kept from the old one, and a page kept from the old version opens the new one. A single-file page is one file, which browsers keep whole, so a returning player may see the old version of it for a while.

If you can change your host's settings, have it send Cache-Control: no-cache with a single-file page, and with a folder's index.html and program.b3dpak: browsers then check them on every visit, and download them only when they have changed. A folder's page asks for the web runtime, your program and each part of program.b3dpak at addresses of their own, ending in ?v= or ?file= and a code that changes whenever the file does, so the host can let browsers keep those for good with Cache-Control: public, max-age=31536000, immutable. On nginx, for a game in the folder /play/game/:

map $arg_file$arg_v $game_cache_control {
    ""      "no-cache";
    default "public, max-age=31536000, immutable";
}

server {
    ...
    location /play/game/ {
        add_header Cache-Control $game_cache_control;
    }
}

From the command line, blitzcc --target web -o game.html game.bb writes the page game.html, and blitzcc --target web -o site game.bb writes the folder site; add --run to open either one too. blitzcc --serve game.html or blitzcc --serve site opens a web build created earlier.

What players need

Players need a browser with WebGPU and WebAssembly JavaScript Promise Integration: Chrome or Edge 137 or later, Firefox 153 or later on Windows or an Apple-silicon Mac, or Safari 27. The page explains what is missing on other browsers. Browsers only allow WebGPU on pages served over HTTPS, which web hosts provide.

Showing 3D over your own page

In the browser, 3D graphics are see-through wherever your program draws nothing, so the 3D can float over a web page of your own. Turn off the camera's background with CameraClsMode camera,False,True, and draw no 2D before RenderWorld. See-through entities let the page show through them, and added ones (EntityBlend 3) light it up. Then put the web build in your page in an iframe, adding ?transparent=1 to its address, which leaves out the build's own black background and title bar:

<iframe src="game.html?transparent=1&autostart=1" width="640" height="480"
        style="border: 0"></iframe>

Without ?transparent=1, the page shows black there, as Windows does. The iframe still takes the mouse clicks over its whole area. Reading the screen (ReadPixel, CopyRect, screenshots) gives black where the page shows through.

Differences in the browser

Back to Guides