Cart API
A Beep8 cart (or cassette) is a png image that also contains the game data within it. This allows you to share your game as a single image file. Currently the only way to create a cart is to export it from the Beep8 Editor.
beep8.Cart.load(pngBlobOrUrl) async
Loads a PNG file with a custom trailer (set of game data) and extracts the appended data.
The PNG file should be created using the beep8.Cart.save function which appends the required trailer data.
Parameters
- pngBlobOrUrl (Blob|string): The PNG file as a Blob or a URL.
Returns
- (Promise<Object>): - A promise that resolves to the extracted data object.
beep8.Cart.save(canvas, data [,filename]) async
Saves the current canvas as a PNG file with a custom trailer.
The trailer includes metadata (e.g., game data) appended to the PNG file. This metadata is stored as a JSON object and can be extracted later using the load
function.
Parameters
- canvas (HTMLCanvasElement): The canvas element to save as a PNG file.
- data (Object|String): The metadata object to append as a trailer. This object will be serialized as JSON.
- [filename] (string): The name of the file to save. Defaults to “cart.png”. (default: “cart.png”)
Returns
- (Promise<void>): - A promise that resolves when the file is saved.