Skip to content

Instantly share code, notes, and snippets.

@tnlogy
Created January 24, 2014 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tnlogy/8604903 to your computer and use it in GitHub Desktop.
Save tnlogy/8604903 to your computer and use it in GitHub Desktop.
--# Main
-- Infinite Grid
function setup()
displayMode(FULLSCREEN)
g = Grid()
end
function draw()
background(40, 40, 50)
translate(WIDTH/2, HEIGHT/2)
g:draw()
end
function touched(touch)
g:touched(touch)
end
--# Grid
Grid = class()
function Grid:init()
self.pos = vec2(0,0)
self.gs = 256
self.m = mesh()
self.m:addRect(0,0,self.gs,self.gs)
self.tiles = {}
end
function Grid:draw()
checkqueue()
local s = 3
for y=-s,s do
for x=-s,s do
local k = x.."-"..y
local a = self.tiles[k]
if not a then
a = asset(x,y)
self.tiles[k] = a
end
self.m.texture = a
pushMatrix()
translate(self.pos.x+x*self.gs,self.pos.y+y*self.gs)
self.m:draw()
popMatrix()
end
end
end
function Grid:touched(touch)
self.pos = self.pos + vec2(touch.deltaX, touch.deltaY)
end
--# LoadImage
local q = {}
local size = 128
local hs = size/2
function asset(x,y)
local img = image(size,size)
tween.delay(math.random()*2, function ()
table.insert(q,img)
end)
return img
end
function checkqueue()
for i,img in ipairs(q) do
resetMatrix()
setContext(img)
sprite(CAMERA, hs,hs)
setContext()
table.remove(q,i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment