There is the Corona project which were generated by Kwik Photoshop plugin.
Project includes a lot of large image files. The size of all images is near 1Gb. I decided it would better to download images from server for the first time and then use local (downloaded) images.
I think it should be something like this:
- Create new *.lua file, for example image.lua
- In this image.lua write a function which will first check if file already exist in documents directory. If file exist then return it else download file from server and then return.
- Require image module in main.lua
- Create some BAT script which will replace display.newImageRect( to Image:newImageRect(
Please correct my decision if there something wrong!
Here is example of generated by Kwik code:
la = display.newImageRect( imgDir.. "00001.jpg", 550, 514 ); la.x = 992; la.y = 290; la.alpha = 1; la.oldAlpha = 1 la.oriX = la.x; la.oriY = la.y la.name = "la" menuGroup:insert(la); menuGroup.la = la
-
Creating file
-
Function
Image = {} local function doesFileExist( fname ) local results = false if ( fname ) then fname = io.open( fname, “r” ) end if ( fname ) then fname:close() results = true end return results end function Image:newImageRect(imageName, _w, _h) local path = system.pathForFile( imageName, system.DocumentsDirectory ) print("Search path: "…path) if doesFileExist(path) == true then print(“Local image found”) return display.newImageRect(path, _w, _h); else print(“Local image NOT found”) local function networkListener( event ) if ( event.isError ) then print ( “Network error - download failed” ) elseif (event.phase == “ended”) then print(“Downloading phase: Ended”) return display.newImageRect(system.pathForFile( event.response.filename, event.response.baseDirectory ), _w, _h ) end end local params = {} params.progress = true network.download( “http://www.site.com/images/”…imageName, “GET”, networkListener, params, imageName, system.DocumentsDirectory ) end end
3. In mail.lua
image = require("image")
4. Replace display.newImageRect( to Image:newImageRect(
It doesn’t work!
Function display.newImageRect in image.lua returns nil:
Local image found
2014-01-18 09:49:48.345 Corona Simulator[12080:d03] WARNING: Failed to find image(/Users/Apple/Library/Application Support/Corona Simulator/build-86EF8579300B17FDAB40BCC2BB019CAB/Documents/00001.jpg)
Need help!!!