Drawing text begins by loading a font file. The function for this is setFont
which takes a filename. The font needs to be in the yaff format, and the same rules apply as image loading. To keep the script portable, and working on the web, use ra.then
to wait until the font file has finished loading. Once loaded, calling drawText
will draw text onto the scene.
const ra = require('raster');
ra.setZoom(2);
ra.setSize(60, 30)
ra.setFont('font/romulus.yaff');
ra.then(() => {
ra.drawText('hi there', 4, 10);
ra.run();
});
There is a built-in font called 'tiny', loading it will happen immediately and does not need waiting.
const ra = require('raster');
ra.setZoom(2);
ra.setSize(60, 30)
ra.setFont('font:tiny');
ra.drawText('hi there', 4, 10);
ra.run();
Previous: Full fills | Table of Contents | Next: Images |