API | Uses canvas | Graphics libraries | AB framework | Worlds using this API | Starter Worlds |
Canvas (r1) | Yes | None | No | 7 Worlds | None |
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
or with any Ancient Brain framework.
Anything written in JS for a canvas should run using this API without change.
This API has the following features:
AB.mind.getAction ( state );
ABWorld; // instance of class ABWorldClass ABWorld.canvas; // a variable to point to the canvas // When making a screenshot, Ancient Brain will search for the canvas. // If it cannot find the canvas, set this variable to point to it. ABWorld.fullwidth(); // return full width of window on desktop / screen on mobile ABWorld.fullheight(); // return full height of window on desktop / screen on mobile
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.
You need something like:
ctx = canvas.getContext ( "webgl", { preserveDrawingBuffer: true } );You might set it to true for "generate image" runs and false for normal runs:
if ( AB.isScreenshotRun() ) ctx = canvas.getContext ( "webgl", { preserveDrawingBuffer: true } ); else ctx = canvas.getContext ( "webgl", { preserveDrawingBuffer: false } );