Skip to content

Instantly share code, notes, and snippets.

@interactivenyc
Last active April 20, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interactivenyc/96d4fb41b24e9b6d82eb2931851df3cb to your computer and use it in GitHub Desktop.
Save interactivenyc/96d4fb41b24e9b6d82eb2931851df3cb to your computer and use it in GitHub Desktop.
function setup()
LoadImages() --do this first, on its own
sprite();
end
function setup2()
print("setup2");
end
function LoadImages()
imageStatus='Ready' --tells draw it's ok to draw the scene (will be turned off if we have to download images)
output.clear()
--pass through Codea name of image and internet url
--not in Codea, will be downloaded and saved
img = {}
for var=0,23,1 do
img[var] = LoadImage('Project:gyrobot'..var..'-a','https://raw.githubusercontent.com/interactivenyc/CodeaJoystick/master/gyrobot'..var..'-a.png')
end
--img1=LoadImage('Dropbox:3D-tree','http://i1303.photobucket.com/albums/ag142/ignatz_mouse/map-tree27c_zpsd56f4f5f.png')
--img2=LoadImage('SpaceCute:Background')
--img3=LoadImage('Dropbox:3D-wall','http://i1303.photobucket.com/albums/ag142/ignatz_mouse/map-stonewall1_zps875ba0f0.png')
if imageStatus=='Ready' then setup2() end
end
--downloads images one by one
function LoadImage(fileName,url)
print("url:"..url)
local i=readImage(fileName)
if i~=nil then return i end
--not found, we need to download, add to queue (ie table)
if imageTable==nil then
imageTable={}
end
imageTable[#imageTable+1]={name=fileName,url=url}
print('Queueing fileName: ',fileName)
imageStatus='Loading'
--if the first one, go ahead and download
if #imageTable==1 then
http.request(imageTable[1].url,ImageDownloaded)
print('loading',imageTable[1].url)
end
end
--saves downloaded images
function ImageDownloaded(img)
print(imageTable[1].name,'loaded')
saveImage(imageTable[1].name,img) --save
table.remove(imageTable,1)
--load next one if we have any more to do
if #imageTable>0 then
http.request(imageTable[1].url,ImageDownloaded)
print('loading',imageTable[1].name)
else
LoadImages()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment