API | Uses canvas | Graphics libraries | AB framework | Worlds using this API | Starter Worlds |
Canvas (AB) (r2) | Yes | None | Yes | 17 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 to customise the drawing context, do this:
var ctx = ABWorld.canvas.getContext ( type, args );
Ancient Brain needs runs to be able to generate a screenshot.
If you are doing WebGL rendering (context "webgl"),
you need in
canvas.getContext
to set "preserveDrawingBuffer" = true.
If you use ABWorld.getContext, this is taken care of for you.
If you use your own custom getContext, then to make sure your run can generate a screenshot, you need to do something like this:
ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: true } );You might set it to true for "generate image" runs and false for normal runs:
if ( AB.isScreenshotRun() ) ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: true } ); else ctx = ABWorld.canvas.getContext ( "webgl", { preserveDrawingBuffer: false } );