Inside the drawCell function, I draw a roundedREct. It does not appear on screen tough.
Here is my code. main.lua:
import "CoreLibs/timer"
import "lua/util.lua"
import "lua/level.lua"
import "lua/init.lua"
import "lua/gameScreen.lua"
import "lua/level-select/levelSelectScreen.lua"
import "lua/systemMenu.lua"
local gfx <const> = playdate.graphics
local updateBlinkers <const> = gfx.animation.blinker.updateAll
local updateTimers <const> = playdate.timer.updateTimers
local activeScreen = LevelSelectScreen()
function playdate.update()
gfx.pushContext()
local nextScreen = activeScreen:update()
if nextScreen then
activeScreen = nextScreen()
end
gfx.popContext() -- reset any drawing state modifications
playdate.drawFPS(0,0)
updateBlinkers()
updateTimers()
end
levelSelectScreen.lua:
import "CoreLibs/object"
import "../screen.lua"
import "levelSelectView.lua"
class("LevelSelectScreen").extends(Screen)
local levelSelectView
function LevelSelectScreen:init()
levelSelectView = LevelSelectView()
end
function LevelSelectScreen:update()
levelSelectView:render()
end
levelSelectView.lua:
import "CoreLibs/object"
import "CoreLibs/ui"
local gfx <const> = playdate.graphics
local menuOptions = {"Sword", "Shield", "Arrow", "Sling", "Stone", "Longbow", "MorningStar", "Armour", "Dagger", "Rapier", "Skeggox", "War Hammer", "Battering Ram", "Catapult"}
local listView = playdate.ui.gridview.new(0, 10)
listView:setNumberOfRows(#menuOptions)
listView:setCellPadding(0, 0, 13, 10)
listView:setContentInset(24, 24, 13, 11)
listView:setSelectedRow(1)
class("LevelSelectView").extends()
function listView:drawCell(self, section, row, column, selected, x, y, width, height)
gfx.fillRoundRect(100, 100, 50, 50, 4) -- test rect for debugging
print(row, selected, x,y, width, height)
if selected then
gfx.fillRoundRect(x, y, width, 20, 4)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
else
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
gfx.drawTextInRect(menuOptions[row], x, y+2, width, 100, nil, "...", kTextAlignment.center)
end
function LevelSelectView:render()
--gfx.setColor(gfx.kColorBlack)
listView:drawInRect(220, 20, 160, 210)
end
When I move the line gfx.fillRoundRect(100, 100, 50, 50, 4) -- test rect for debugging
from drawCell to LevelSelectView:render(), it is actually getting drawn. But not if I place it inside drawCell. Then I only see the fps counter
drawCell is called on every frame tho, the output of the print statement is
1 244 46 112 10 nil
1 244 79 112 10 nil
1 244 112 112 10 nil
1 244 145 112 10 nil
1 244 178 112 10 nil
1 244 211 112 10 nil
1 244 46 112 10 nil
1 244 79 112 10 nil
1 244 112 112 10 nil
1 244 145 112 10 nil
1 244 178 112 10 nil
1 244 211 112 10 nil
1 244 46 112 10 nil
1 244 79 112 10 nil
Note the height component being nil. I would also expect for all the values to be the same for every frame. I had to replace height
by 100 in gfx.drawTextInRect(menuOptions[row], x, y+2, width, 100, nil, "...", kTextAlignment.center)
to prevent the code from crashing
I took this code from the example in the docs. What am I missing?
Using sdk 1.10.0 on Mac + simulator