Context: I have a demo build using nineslice. It works great. But when I copy the same code and paste it into my game build it throws an error.
Error is this here
The code is
-- Replace main.lua with this for list gridview
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
import "CoreLibs/ui"
import "CoreLibs/nineslice"
import "CoreLibs/crank"
local pd <const> = playdate
local gfx <const> = playdate.graphics
local gridview = pd.ui.gridview.new(0, 32)
local fruits = {"apple", "banana", "mango", "kiwi", "pineapple", "cherry", "orange"}
gridview:setNumberOfRows(#fruits)
gridview:setNumberOfColumns(2)
gridview:setCellPadding(2, 2, 2, 2)
gridview.backgroundImage = gfx.nineSlice.new("images/gridBackground", 6, 6, 20, 20)
gridview:setContentInset(5, 5, 5, 5)
local gridviewSprite = gfx.sprite.new()
gridviewSprite:setCenter(0, 0)
gridviewSprite:moveTo(150, 15)
gridviewSprite:add()
local btn = gfx.sprite.new()
btn:moveTo(50,50)
btn:add()
function gridview:drawCell(section, row, column, selected, x, y, width, height)
if selected then
gfx.fillRoundRect(x, y, width, height, 4)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
else
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
local fontHeight = gfx.getSystemFont():getHeight()
gfx.drawTextInRect(fruits[row], x, y + (height/2 - fontHeight/2) + 2, width, height, nil, nil, kTextAlignment.center)
end
local fillbtn = false
function pd.update()
gridInputs()
print(gridview:getSelection())
tstButton()
if gridview.needsDisplay then
local gridviewImage = gfx.image.new(241, 211)
gfx.pushContext(gridviewImage)
gridview:drawInRect(0, 0, 241, 211)
gridview:setCellSize(111,100)
gfx.popContext()
gridviewSprite:setImage(gridviewImage)
end
gfx.sprite.update()
pd.timer.updateTimers()
end
function tstButton()
local fill = 0
if fillbtn == true then
fill = 100
end
local bar_image = gfx.image.new(50,20,gfx.kColorWhite)
print("Button")
local _, fontHeight = playdate.graphics.getTextSize("TEST")
gfx.pushContext(bar_image)
gfx.setLineWidth(2)
gfx.drawRoundRect(1, 1, 50-2, 20-2, 3)
gfx.fillRect(2, 2, fill, 20 - 4)
gfx.setImageDrawMode(gfx.kDrawModeNXOR)
gfx.drawTextAligned("Back", 50/2, (20 - fontHeight)/2 + 2, kTextAlignment.center)
gfx.popContext()
btn:setImage(bar_image)
end
function gridInputs()
if pd.buttonJustPressed(pd.kButtonUp) then
gridview:selectPreviousRow(false)
elseif pd.buttonJustPressed(pd.kButtonDown) then
gridview:selectNextRow(false)
end
if pd.buttonJustPressed(pd.kButtonRight) then
gridview:selectNextColumn(false)
elseif pd.buttonJustPressed(pd.kButtonLeft) then
gridview:selectPreviousColumn(false)
end
if pd.buttonJustPressed(pd.kButtonA) then
if fillbtn == false then
fillbtn = true
print("TEST")
gridview:setSelection(0,0,0)
else
fillbtn = false
end
end
end
I've tried debugging the nineslice.lua but I'm not able to see how it can get 0 x 6...
I'm sending
gridview.backgroundImage = gfx.nineSlice.new("images/bg/gridBackground", 6, 6, 20, 20)
Runs great in a demo build which is the frustrating thing.
Are there any gfx settings I can reset? I only guess is that it's getting thrown off by an earlier procedure. But based off of the logic I see in the nineslice.lua it just takes my arguments and does some math, none of which should come out as 0.
I'm a little lost on what it can be, any ideas?