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 on mobile

These Worlds are web pages. Audio on web pages on mobile devices can be difficult. Since the mobile web started in the days of expensive data plans, most mobile browsers do not allow a page automatically load audio. Audio must be launched by user interaction.

There are various workarounds. See Audio for Web games.

Here is a sample World that has user interaction to start mobile audio. Run on mobile to see:


Keyboard and Touch
163 runs ♦ 1 likes
Starter user



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
253 runs ♦ 2 likes
Starter user
Model World
389 runs ♦ 2 likes
Starter user
  

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:


Keyboard and Touch
163 runs ♦ 1 likes
Starter user
  
  

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:


Mouse objects and Tou...
152 runs ♦ 1 likes
Starter user
  
  

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:


Keyboard and Touch
163 runs ♦ 1 likes
Starter user
Mouse objects and Tou...
152 runs ♦ 1 likes
Starter user
  
  

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.
Customise background:  
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