As far as I know, the fastest way to draw is to use scene.createRenderable
combined with Image.setRows
. That’s what I use in Space Rocks 3D.
Here’s an older discussion about the topic: Is it possible to write directly to screen (pixels) on the Arcade?
scene.createRenderable
takes a function as its second argument, that function gets called each time the screen content is refreshed on updates. The called function gets an Image
as its first argument which is a reference to the screen buffer, you can modify that image to draw directly onto the screen.
The image.getRows
and image.setRows
methods copy pixels from the screen into a byte buffer and back.
Something like this (untested):
const buf = Buffer.create(120)
const zLayer = 0
scene.createRenderable(zLayer, (target: Image, camera: scene.Camera) => {
for (let x = 0; x < 160; +=x) {
// Read the current screen content for modification
image.getRows(x, buf)
// Now "buf" contains a color value for the current pixel row
// (it's actually a vertical column onscreen) where it can be modified.
buf[12] = 15
// Write the modified pixels back to the screen.
image.setRows(x, buf)
}
})