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:
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 ?
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;
}
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 ).
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 ?