API | Uses canvas | Graphics libraries | AB framework | Worlds using this API | Starter Worlds |
Canvas (AB) (r2) | Yes | None | Yes | 3 Worlds | Starter Worlds |
This API is for Worlds that use a canvas
to do their own 2D or WebGL rendering.
It does not come with a graphics library.
It comes with an Ancient Brain framework to make writing Worlds easier.
This API has the following features:
ABWorld; // instance of class ABWorldClass - basic functionality for this API
// A canvas that may be drawn on using getContext("2d") or getContext("webgl") ABWorld.canvas; // create canvas: ABWorld.init ( color ); // get drawing context: ABWorld.getContext ( type );
var ctx = ABWorld.getContext ( "2d" ); var ctx = ABWorld.getContext ( "webgl" );
If you want a customised drawing context, call it directly:
var ctx = ABWorld.canvas.getContext ( type, args );
For your World to generate screenshots, you need in canvas.getContext to set preserveDrawingBuffer = true. Like this:
ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: true } );This may lead to lower performance. So you might like to set it to true for "generate image" runs and false for normal runs, which can be done as follows:
if ( AB.isScreenshotRun() ) ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: true } ); else ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: false } );If you use ABWorld.getContext, this is not needed. It is built-in (preserveDrawingBuffer true for screenshot runs, false for normal runs).