![HEBitmap logo](assets/logo-light-512.png)
This is just a slight modification of the original HEBitmap build process that will produce static library (libhebitmap.a) files instead of a full game. If you are programming in C, you might also just include the original C files in your project. If you are programming in another language such as Nim (see below), this lib might help.
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$PLAYDATE_SDK_PATH/C_API/buildsupport/arm.cmake -DCMAKE_BUILD_TYPE=Release ..
make
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
When using Nim, you can use the bindings in the nim folder to use the lib from your project
Note that this is in the Proof of Concept stage. It is usable, but I haven't tested it for memory leaks. Pull requests are welcome.
Make sure to call the initializer once at the start of your program
import playdate/api
import hebitmap
proc handler(event: PDSystemEvent, keycode: uint) {.raises: [].} =
if event == kEventInit:
heBitmapSetPlaydateAPI(playdate)
# ... other setup code
Then
import playdate/api
import hebitmap
# from file
let heCoinImage = gfx.newHeBitmap("images/coin")
heCoinImage.draw(100, 100)
# custom image
let customImage = gfx.newBitmap(20, 20, kColorBlack)
## manipulate customImage however you want
gfx.pushContext(customImage)
# gfx.fillRectangle etc
gfx.popContext()
# this copies the image data, further changes to customImage won't be reflected
let heCustomImage = newHeBitmap(customImage)
heCustomImage.draw(50,50)
HEBitmap (High Efficiency Bitmap) is a custom implementation of the drawBitmap function (Playdate SDK).
This implementation is up to 4x faster than the SDK drawBitmap function, but native features (clipRect, flip, stencil) are not supported.
Bitmap info: 48x22 (masked)
N Bitmaps | HEBitmap | drawBitmap | Faster |
---|---|---|---|
2000 | 30 ms | 120 ms | 4x |
1000 | 20 ms | 63 ms | 3x |
500 | 19 ms | 33 ms | 1.7x |
#include "hebitmap.h"
// Set Playdate API pointer
HEBitmapSetPlaydateAPI(pd);
// Load a LCDBitmap
LCDBitmap *lcd_bitmap = playdate->graphics->loadBitmap("test", NULL);
// New HEBitmap from LCDBitmap
HEBitmap *he_bitmap = HEBitmapNew(lcd_bitmap);
// Draw
HEBitmapDraw(he_bitmap, 0, 0);
// Free
HEBitmapFree(he_bitmap);
// Free original LCDBitmap
playdate->graphics->freeBitmap(lcd_bitmap);
You can get the compiled PDX demo here. Press A to switch between custom / SDK implementation.