Create LCDBitmapTable without loading file

,

Hello everybody,

I'm currently developing a simple dungeon crawler for Playdate, with C language.
For now, I'm toying around making a tiny engine that will create and display the dungeon.

I've learnt how to use LCDBitmap and LCDBitmapTable in the "Inside Playdate with C" documentation, but halas I'm still missing something.

I did not find any function that can be used to set a LCDBitmap at a given index inside a LCDBitmapTable.
Basically, I would like to be able to create a LCDBitmapTable programmatically, without having to load a file containing my images.
(The idea behind this is just to have kind of a default behaviour for my engine, when there is no imagetable provided for example).
To be simple, I would like to be able to write this:

unsigned int tile_size = 32;
LCDBitmap * walk_bmp = playdate->graphics->newBitmap(tile_size, tile_size, kColorBlack);
LCDBitmap * block_bmp = playdate->graphics->newBitmap(tile_size, tile_size, kColorWhite);
LCDBitmapTable * image_table = playdate->graphics->newBitmapTable(2, tile_size, tile_size);

playdate->graphics->setBitmap_at_BitmapTable_idx(0, walk_bmp);
playdate->graphics->setBitmap_at_BitmapTable_idx(1, block_bmp);

According to the Lua documentation for playdate, there seem to be a function playdate.graphics.imagetable:setImage(n, image). I'm surprised there is no equivalent in C, maybe I missed something, or my approach for this problem is not the right one ?

If it isn't the right approach, what should I do ?

Bye !

I also wanted to do this in Lua but was unable.

This was a while ago so I forget the details (it's probably on here somewhere)

1 Like

Programmatically creating a BitmapTable does not seems to be really doable, even in Lua (see Crash when generating imagetable - #3 by Nic for example).

Something you can do is wrapping an image table in your own type and handle 2 cases: one when the source is an image table and the other one when the source is an array of bitmaps.

For example:

typedef struct {
  LCDBitmapTable *bitmapTable;
  LCDBitmap *images;
  unsigned int count;
} ImageTableWrapper;

ImageTableWrapper *ImageTableWrapperMakeWithBitmapTable(LCDBitmapTable *bitmapTable);
ImageTableWrapper *ImageTableWrapperMakeWithCount(unsigned int count);

LCDBitmap *ImageTableWrapperGetBitmapAtIndex(ImageTableWrapper *self, unsigned int index) {
  if (self->bitmapTable) {
    return playdate->graphics->getTableBitmap(self->bitmapTable, index);
  } else if (index < self->count) {
    return self->images[index];
  } else {
    playdate->system->error("Trying to get bitmap at index %d, but count is %d", index, self->count);
  }
}
LCDBitmap *ImageTableWrapperSetBitmapAtIndex(ImageTableWrapper *self, unsigned int index, LCDBitmap *image) {
  if (self->bitmapTable) {
    playdate->system->error("This ImageTable has been loaded from disk and cannot be modified");
    return;
  }
  if (index >= self->count) {
    playdate->system->error("Trying to set bitmap at index %d, but count is: %d", index, self->count);
  }
  self->images[index] = image;
}
1 Like

Hello Daeke :wink:

Ok, that's what I was fearing indeed.
This issue is not critical. I was already doing something like you are doing in the code you posted (it was just a bit more messy than your code :innocent:).

What should I do with this topic now ?
Should I let it open and unresolved, or should I close it and open a new topic in the SDK Feature Requests category ?

Bye, and thank you both for your answers !

1 Like

I've morphed it into a feature request.

IIRC at the time this was consider a niche use case, but evidently there are at least a handful of us trying to do it :slight_smile:

3 Likes