[Imagetable] Add Method on imagetable to get the tile size

It seems that, if I load an imagetable, the method getSize() of it will return the number of cells in width and height, but there are no methods to get the actual size of a cell directly.

So, for that, I am forced to get the first image using getImage(1).

I would like to get the size of the cell in the image table (16x16) without needing to incur in the overhead of getting an actual sample of an image.

Example: pizza-table-16-16.png

Size of Image: 128x128

pizza-table-16-16

pizza = gfx.imagetable.new('assets/images/pizza')

---@diagnostic disable-next-line: duplicate-set-field

function playdate.update()

print(pizza:getSize())

print(pizza:getImage(1):getSize())

end

Results:

image

1 Like

It's an understandable concern, but in your code it's only receiving a address of/reference to the image and it's very quick.

Similarly when you request the size it's just a property/attribute access so very quick.

The usual Lua optimisation tricks apply, local/const/doing it once on load etc.

2 Likes

ok thenn thank youuu

I have a slightly different issue. I'm displaying playing cards that need some grid layout calculations before I start loading the images. Is there a way to get the tile size of an imagetable without loading the image? I initially used .getSize() on a single image for this, but now i'm switching over to imagetable, I'm stumped. TIA

Why do you need to do this before loading the image? Iā€™m curious.

You could just hard code the image table dimensions. If you have a build process or make file you could generate that code.

1 Like

My Deck class can dynamically lay out a grid of cards with varying numbers of both rows and columns. Getting the grid centered requires some math which involves the finished size of the card, but display and lookup in the imagetable is now handled by the Card class. My first pass at the code used a single sample image and it was very convenient and scalable to use mySingleImage.getSize().

I am confused and disappointed by the fact that the myImagetable.getSize() returns different data than it's identically named counterpart for a single image. If it's valuable to get the size of a single image without loading it, why not have the same functionality available for an imagetable? We are required to hardcode the tile size into the file name, it seems like it would be fairly straightforward to implement.

Maybe I'll add the full filename for the imagetable into my config, and do some string manipulation to get the HxW of the tile. Curious about the process you mention involving an automated build process.

Thanks for your reply.

1 Like