Skip to content

A custom implementation of the drawBitmap function (Playdate SDK)

License

Notifications You must be signed in to change notification settings

risolvipro/HEBitmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HEBitmap logo

HEBitmap (Playdate)

HEBitmap (High Efficiency Bitmap) is a custom implementation of the drawBitmap function (Playdate SDK).

This implementation is up to 2x faster than the SDK drawBitmap function, but native features (flip, stencil) are not supported.

The library also provides an optional sprite system to efficiently move sprites and check collisions.

Benchmark

Bitmap info: 96x96 (masked)

Bitmap count HEBitmap drawBitmap Faster
1000 22 ms 42 ms 1.9x

C Example

#include "he_api.h"

// Initialize with PlaydateAPI pointer
// Pass 1 to enable Lua support
he_library_init(pd, 0);

// Load HEBitmap from a Playdate image file
HEBitmap *bitmap = HEBitmap_load("catbus");

// Draw
HEBitmap_draw(bitmap, 0, 0);

// Free
HEBitmap_free(bitmap);

C Docs

C API Documentation

Lua

#include "he_api.h"

// Initialize in kEventInitLua
// Pass 1 to enable Lua support
he_library_init(pd, 1);
import "he/bitmap"

-- Load HEBitmap from a Playdate image file
local bitmap = he.bitmap.new("catbus")

function playdate.update()
    -- Draw
    bitmap:draw(100, 100)
end

Create a C-Lua project on macOS

  • Install CMake (run brew install cmake from the terminal)
  • In the lua folder of the repo you can find a minimal template to create a C-Lua project
  • Copy all the files beginning with "he_" from src into lua/src
  • Navigate into the lua folder and create a build folder
  • Open the terminal and navigate into it

Simulator build

  • Run cd <your_build_folder>
  • Run cmake ..
  • Run make

Device build

  • Before building again, delete all the files in the build folder
  • Run cmake -DCMAKE_TOOLCHAIN_FILE=<path to SDK>/PlaydateSDK/C_API/buildsupport/arm.cmake -DCMAKE_BUILD_TYPE=Release ..
  • Note: replace <path to SDK> with your SDK path
  • Run make

You can now build and run it as a Lua project.

Lua Docs

Lua API Documentation

Sprite system

The sprite system allows to efficiently move, check collisions and draw sprites. You can find two Lua examples in the repo.

Source/dino

Dino demo

Source/survival

Survival demo

Encoder

You can use the Python encoder to create heb/hebt files, supported inputs are:

  • Image
  • Animated GIF (saved as bitmap table)
  • Folder containing a Playdate image table (name-table-1.png, name-table-2.png, ...)

Parameters

  • -i --input input file or folder
  • -r --raw save as raw data (no compression)

Usage

python encoder.py -i <file_or_folder>

About

A custom implementation of the drawBitmap function (Playdate SDK)

Topics

Resources

License

Stars

Watchers

Forks