Hey all… I was trying to use the example near the top of the post to see a simple hex grid for a board game. I will also review that supper hex doc that @simeon posted.
With the example code in this post, when I run it I just have a blank screen without errors. I tried the code as listed above with the background draw. I also got a hex sprite from the web to use.
I also tried the code as below. Again this one didn’t draw anything. Any ideas what I am missing.
-- hex2
-- Use this function to perform your initial setup
function setup()
Board = class()
local LI = 13
local CO = 16
-- movements table declared at the end of file
local _board = { {1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1},
{1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1} }
function Board:init()
-- advise
--self.objectList = {{li=5, co=5}=[objectExample]}
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
function Board:draw(pw, ph)
local size = #_board
local w = pw/16.5
local h = ph/10
for li=1,#_board do
for co=1,#_board[li] do
if _board[li][co] == 0 then
pushMatrix()
local x,y
-- Mode Center
if li % 2 == 1 then
x = w/2 + ((co-1)*w)
else
x = co * w
end
y = h/2 + ((li-1)*h/1.5)
translate(x, y)
sprite("Dropbox:Photo Jul 22, 12 38 42 PM", 1, 1, w, h)
popMatrix()
end
end
end
end
-- UTILS
function Board:contain(li, co)
return li >= 1 and li <= LI and co >= 1 and co <= CO and _board[li][co] == 0
end
strokeWidth(5)
end
Thanks in advance for all the assistance.