Importing Graphical Assets


BitMasher itself does not have any functionality for drawing sprites or backgrounds on-device. They must be drawn on a separate program and then exported as a bmp or png file.

Assets Import Workflow


Converting Images to Bytes

BitMasher does not accept an image file directly. The file must be converted into a raw stream of bytes that is copied into an assets source file. The script does this conversion for us. Note that running the script requires Python 3, the imageio and Numpy modules.

To convert the image, execute the script:

$ python -f <path/to/cat.png> -s

The -s flag indicates that we are converting a sprite image as opposed to a background or sprite mask. The script should output the image in byte format as well as its dimensions. We are now ready to integrate the sprite into the scene.

Importing the Cat

Create a header file called BM_Assets_CatPad.h and add it into the Assets folder. Create the following declarations in the file:

//  BM_Assets_CatPad.h 
#pragma once

#include "arm_math.h"           //  Contains type definitions (uint8_t, int32_t etc)

extern uint8_t BM_Assets_CatPad_cat[];      //  Array that will store the cat's bitmap byte data
extern int32_t BM_Assets_CatPad_catWidth;   //  Cat's width in pixels
extern int32_t BM_Assets_CatPad_catHeight;  //  Cat's height in pixels

Then, define the variables in the corresponding source file. This is where you will copy the byte output from the python script into the BM_Assets_CatPad_cat array:

//  BM_Assets_CatPad.c
#include "BM_Assets_CatPad.h"

uint8_t BM_Assets_CatPad_cat[] = 
    0x30, 0x0, 0xc, 0x0,
    0x78, 0x0, 0xde, 0x3,
    0xd8, 0x7e, 0xdb, 0x7,
    0xc8, 0xff, 0x53, 0xc,
    0x88, 0x81, 0xf1, 0xc,
    0xc, 0x0, 0xe0, 0x19,
    0xc6, 0x0, 0xa3, 0x19,
    0xc6, 0x0, 0xe3, 0x19,
    0x6, 0x0, 0xe0, 0x19,
    0xf6, 0x99, 0xef, 0x19,
    0x3, 0x0, 0xc0, 0x1c,
    0xf3, 0x0, 0xcf, 0x8,
    0x3, 0x0, 0xc0, 0xc,
    0x3, 0x0, 0xc0, 0xe,
    0x43, 0x0, 0xc2, 0x7,
    0x63, 0x2c, 0xc6, 0x3,
    0x63, 0x34, 0xc6, 0x0,
    0x63, 0x2c, 0xc6, 0x0,
    0x63, 0x34, 0xc6, 0x0,
    0x63, 0x2c, 0xc6, 0x0,
    0x6e, 0x34, 0x76, 0x0,
    0xfc, 0x3c, 0x3f, 0x0,
    0xf0, 0xff, 0xf, 0x0

int32_t BM_Assets_CatPad_catWidth = 29;
int32_t BM_Assets_CatPad_catHeight = 23;

Now that we have imported our cat, let's move onto initializing the scene.