So I just recently got this device, and I have to say I absolutely love it. That said, I’m still learning about how to develop for it.
I’m trying to build a simple tile-based game, which of course involves a sprite for each tile. During preliminary testing I wanted to draw all the current tiles. There weren’t many, so I just drew them one at a time.
For the record, I used @Dreamer3’s wonderful image converter here, and so my bitmaps are currently defined like so, notably with the first two bytes being width and height:
// bm_sheet_0.png
// 16x16
PROGMEM const byte bm_sheet_0[] = {
// width, height
16, 16,
0xE0, 0xF8, 0x1C, ...
};
and I’m using a custom method to draw them that simply calls arduboy.drawBitmap()
with some pre-defined parameters:
void drawBitmap(int x, int y, const byte* bitmap)
{
arduboy.drawBitmap(x, y, &bitmap[2], bitmap[0], bitmap[1], WHITE);
}
the problem is when I actually go to draw them. That custom function seems fine, because it works for any of the bitmaps individually; and I know that the actual data of the bitmaps isn’t corrupted either for the same reason. I can call that function any number of times on the same bitmap, but as soon as I try to draw four different bitmaps in the same frame, none of them draw correctly, and appear horribly corrupted:
{
//this works:
drawBitmap(0 * 16, 0, bm_sheet_0);
drawBitmap(1 * 16, 0, bm_sheet_1);
drawBitmap(2 * 16, 0, bm_sheet_2);
//drawBitmap(3 * 16, 0, bm_sheet_3);
}
{
//this draws garbage, or sometimes nothing:
drawBitmap(0 * 16, 0, bm_sheet_0);
drawBitmap(1 * 16, 0, bm_sheet_1);
drawBitmap(2 * 16, 0, bm_sheet_2);
drawBitmap(3 * 16, 0, bm_sheet_3);
}
I don’t have any idea what’s going on, except that somehow the wrong values of width and height are being passed to arduboy.drawBitmap();
since all the sprites are 16x16, when I simply replace the width and height in the custom drawBitmap
with 16’s everything seems to work fine. I don’t understand how that’s possible though, because the first two bytes are always 16’s, and I have no idea why 4 seems to be the magic number that destroys everything.
Also, I can edit this post and attach pictures if it could help.
Thanks!