How to write a World

The basic choice is whether your World is controlled by a Mind or not.

How to write a World that uses no Mind


How to write a World that uses a Mind


Generate a new blank World

Most Worlds will probably be created by taking an existing working World and cloning it and then editing it.

If you want to start with a blank page, use this link:


Generate a new blank World




World screenshot

There is an image or screenshot to represent each World.

If you are the owner of a World:

  • On the World page, you will see an action "Generate image" to generate the image. You can run this any number of times and position the camera until you get the screenshot you want.
  • By default the screenshot is taken at step 50. You can change this by setting a value for the variable: AB.screenshotStep in your World code.



Three.js

At present, our APIs provide support for graphical Worlds based on the Three.js library. To develop new Worlds for APIs based on Three.js, you need to look at Three.js documentation and examples.

There are various Three.js introductions online. There are also some Three.js books.

The official site is here:

  
  

Upload support files

You can upload support files to use in your World:
  • images (e.g. object textures)
  • audio (e.g. music, sound effects)
  • other (e.g. 3D models)

You upload files on your uploads page (see link on your home page). See for example the uploads page for the user Starter user.

Reference your uploads in your code using an absolute path like: '/uploads/user/file'

You can reference other people's uploads (though note there is a risk they will delete them).


Resources

Some resources sites that might be useful:



Audio autoplay on web pages

These Worlds are web pages. Audio automatically playing on web pages can be annoying. As a result, in many browsers (notably Chrome and mobile browsers) audio will not automatically play but requires user interaction to start it.

The Starter Worlds that have background music have "play" and "pause" buttons for manual control if the music does not start.

A better solution is a "splash screen" to get user interaction at the start of the run, and start background music, and set up audio events that can be randomly triggered by the JS later without further user interaction. See Audio for Web games.

Here are some sample Worlds using user interaction (on a splash screen) to start background music and set up audio events for later. See the code to see what they are doing.


Bouncy Balls
176 runs ♦ 2 likes
Starter user
Demo of Physics API. Balls bounce under gravity and collide in low friction world. Splash screen...
Collision World
354 runs ♦ 2 likes
Starter user
Demo of Physics API. Blocks fall under gravity and collide. Can modify gravity, friction, etc. S...
Zombie Death Baby
155 runs ♦ 0 likes
Starter user
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
Castle World
296 runs ♦ 2 likes
Starter user
Demo of how to insert 3d model into World. Mind-controlled agent, actively-pursuing enemy. Splas...



How to make Chrome autoplay audio

You can change Chrome to autoplay audio:
  1. Type in address:
     chrome://flags/ 
  2. Search for "Autoplay policy".
  3. Select "No user gesture is required".
  4. Restart Chrome.
Chrome may later reset this flag, and you may have to do this again!




3D models

Pre-built OBJ 3D models (with pre-built MTL materials) may be uploaded and inserted into Worlds.

The Three.js based APIs on this site include these libraries for loading 3D models:

If there is a library missing you can include it yourself.

Here are sample Worlds containing OBJ models plus MTL materials:


Castle World
296 runs ♦ 2 likes
Starter user
Demo of how to insert 3d model into World. Mind-controlled agent, actively-pursuing enemy. Splas...
Model World
431 runs ♦ 2 likes
Starter user
Demo of how to insert 3d models into World. Mind-controlled agent, actively-pursuing enemy. Skybox.
  

Resources (3D models)

There are sites with 3D models that may be of use.



Human interaction with World - keyboard

On the desktop, you can allow the human interact with the World through the keyboard.

Here is a sample World that reads keyboard input using keycodes. Run on desktop to see:


Touch World
206 runs ♦ 1 likes
Starter user
How to override default touch handling. Mobile: Touch drag moves agent, touch pinch zooms camera...
  
  

Human interaction with World - mouse

On the desktop, in our normal Three.js based APIs, mouse drag and scroll controls the camera.

If you want to use the mouse to do something else, you can override the mouse camera control, and capture Mouse events yourself in your JavaScript.

Here is a sample World showing Mouse drag for moving an agent around the World, and mouse click on an object to change it. Run on desktop to see:


Zombie Death Baby
155 runs ♦ 0 likes
Starter user
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
  
  

Human interaction with World - touch screen

On mobile and tablet, in our normal Three.js based APIs, touch drag and pinch controls the camera.

If you want to use touch to do something else, you can override the touch camera control, and capture Touch events yourself in your JavaScript.

Here are sample Worlds showing touch drag for moving an agent around the World, and touch tap on an object to change it. Run these on mobile to see:


Zombie Death Baby
155 runs ♦ 0 likes
Starter user
How to make a fun touch game for mobile. Touch drag and tap objects. Mouse drag and click object...
Touch World
206 runs ♦ 1 likes
Starter user
How to override default touch handling. Mobile: Touch drag moves agent, touch pinch zooms camera...
  
  

Instructions for human player

If your World is a game or problem for human users to solve, you can write the instructions in various places:
  • Write to the user_span status areas in the run window. ("View Source" on a run to see these.) These stay on the screen. (Although there is a "Less" and "More" option.)

  • Make a splash screen. For example, a div that the user clicks to dismiss.

  • Write detailed comments at the top of the JS code. Each World's home page contains a link to its JS code.


The "tweaker's box"

When writing a World, you might consider users who will want to edit and customise your World. Some will have limited programming ability.

It is recommended (though not enforced) that you mark out a section at the top of the code containing the things that can be easily changed in your World by a non-programmer. We call this the "tweaker's box". What is below the "tweaker's box" will need programming skills to change.

For examples of the "tweaker's box" concept, see the source code for the Starter Worlds.


The background is a program, showing the JavaScript graphics used on this site.
 
Font:

© Ancient Brain Ltd. All rights reserved.

Ancient Brain ™ is a trademark of Ancient Brain Ltd.

Beta      Bug bounty      Contact      Stats      The name      Terms and conditions