Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2014 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/10011170 to your computer and use it in GitHub Desktop.
Save anonymous/10011170 to your computer and use it in GitHub Desktop.
Corona Grid Layout
centerX = display.contentCenterX
centerY = display.contentCenterY
cWidth = display.contentWidth
cHeight = display.contentHeight
display.setStatusBar(display.HiddenStatusBar)
numCol = 20
numRow = 13
col = 1
row = 1
local rects = {}
local rect =
{
x=cWidth/15-10,
y=cWidth/15-10,
width=cWidth/15-10,
height=cWidth/15-10,
}
createBounds = function()
leftWall = display.newRect(0, centerY, 10, cHeight)
rightWall = display.newRect(cWidth, centerY, 10, cHeight)
topWall = display.newRect(centerX, 0, cWidth, 10)
bottomWall = display.newRect(centerX, cHeight, cWidth, 10)
end
createObjects = function()
for i=col, numCol do
for k=row, numRow do
rects[i] = display.newRect(rect.x, rect.y, rect.width, rect.height)
rects[i]:setFillColor(math.random(), math.random(), math.random())
rect.x = rect.x + rect.width+1
if(rect.x >= cWidth)then
rect.y = rect.y + rect.height+1
rect.x = cWidth/15-10
end
end
end
end
createBounds()
createObjects()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment