Platform
Mac, SDK 1.11.1
Issue
In a project I try to generate my own image table but it leads to a lot of unexpected behaviours. In the worst case the simulator crashes.
What I try to do is to create a new image table with playdate.graphics.imagetable.new()
and after to set the different indexes with setImage()
. I encountered the following issues:
playdate.graphics.imagetable:getSize()
doesn't take into account the cellsWide argument.- It seems the first index has to have an image.
- If I try to set an image to multiples indexes, the Simulator will crash.
Code
import("CoreLibs/graphics")
import("CoreLibs/sprites")
local tile = playdate.graphics.image.new( "box" )
local iw, ih = tile:getSize()
local cw, ch = 2, 2
local tileset = playdate.graphics.imagetable.new( cw*ch, cw )
-- Issue #1: return the wrong size, [4, 1] instead of [2,2]
print( "Tileset size", tileset:getSize() )
-- Issue #2
-- if the first index is set, it is rendering but getImage() doesn't return nil for indexes that are not set, size can be incorrect
tileset:setImage(1, tile)
-- Issue #3
-- if the first index is not set, getImage() always returns nil
-- tileset:setImage(2, tile)
-- tileset:setImage(3, tile)
-- tileset:setImage(4, tile)
-- Issue #4, if the first index is set and another one is also set, crash might happens
-- tileset:setImage(1, tile)
-- tileset:setImage(2, tile)
function playdate.update()
playdate.graphics.clear()
for cx = 1, cw do
for cy = 1, ch do
local tile = tileset:getImage(cx, cy)
print("tileset coordinates:", cx, cy)
if tile then
print("image size:", tile:getSize())
tile:draw( cx*iw, cy*ih )
end
end
end
end