From ceb5b03458d8d97200a4938335ff6a41d16763d9 Mon Sep 17 00:00:00 2001 From: Rezmason Date: Mon, 30 May 2022 22:01:39 -0700 Subject: [PATCH] "Flattening" the faded images and glyphs into a 2D array of images reduces the number of draw calls per update to one per changed glyph --- playdate/source/main.lua | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/playdate/source/main.lua b/playdate/source/main.lua index 7b8700b..374fdb7 100644 --- a/playdate/source/main.lua +++ b/playdate/source/main.lua @@ -8,18 +8,17 @@ local numRows = math.floor(screenHeight / glyphWidth) local numCells = numColumns * numRows local numGlyphs = 133 +local numFades = 15 +local blackImage = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack) local glyphTable = gfx.imagetable.new('images/matrix') +local ditherType = gfx.image.kDitherTypeAtkinson local glyphs = {} for i = 1, numGlyphs do - glyphs[i] = glyphTable[i] -end - -local ditherType = gfx.image.kDitherTypeAtkinson -local image = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack) -local numFades = 15 -local fades = {} -for i = 1, numFades do - fades[i] = image:fadedImage(i / numFades, ditherType) + glyphs[i] = {} + local glyph = glyphTable[i] + for j = 1, numFades do + glyphs[i][j] = glyph:blendWithImage(blackImage, 1 - j / numFades, ditherType) + end end local minSpeed = 0.15 @@ -91,8 +90,7 @@ function playdate.update() end if mustDraw then - glyphs[cell.glyphIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth) - fades[cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth) + glyphs[cell.glyphIndex][cell.fadeIndex]:draw((cell.x - 1) * glyphWidth, (cell.y - 1) * glyphWidth) end end