In this tutorial we will run Digger game in Node.js and save game screenshot to the image.
Let's start with creating empty project:
In node environment you can only use emulators package, because
emulators-ui is made for browser integrations. For creating screenshot we will use
jimp library. So let's install them.
Next we need to download Digger js-dos bundle:
Let's create source file
digger.js. We can run it with this command
Use require to import all libraries
emulators package does not use exports system. It injects itself into global object.
pathPrefix is used to locate wasm files it relative to
Now we need to read contents of
jsdos bundle and start emulation
When dos emulation starts, we will receive Command Interface, we can use it to subscribe on frame updates and to send key/mouse events.
onFrame method have two arguments
rgba image data. One of them is always null whilte other is UInt8ClampedArray. It depends on used emulator which data it uses rgb or rgba. js-dos for browsers return rgba data
with transparent alpha channel.
In browser we have frame in RGBA format with transparent alpha, let's fix this and save screenshot:
If you execute
node digger.js it will save the screenshot to
Full code of