My HTML5 game contains several subsections that are initially inaccessible to the user.
I would not like to download these inaccessible files (images, music, etc.) until the user gains access to this subsection. This will have a positive effect on the productivity of the application (so the game will obviously load/start much faster).
Or at least make it so that the files are not downloaded to the phone again if they were already downloaded the previous time the game was logged in.
The fact is that Solar2D puts all the assets in the archive during assembly and until this archive swings, the game \ application will not start and in order to do what you want, you will need to place the necessary assets next to the application after exporting and download them separately.
local myImage
local function networkListener( event )
if ( event.phase == "ended" ) then
myImage = display.newImage( "file.png", system.TemporaryDirectory, 0, 0 )
myImage.x = display.contentWidth/2
myImage.y = display.contentHeight/2
end
end
network.download( "https://docs.coronalabs.com/images/simulator/image-mask-base2.png", "GET", networkListener, "file.png", system.TemporaryDirectory )
I’m not sure if anyone shared a working code regarding this but I believe it can be done. There’s a solution to download and execute Lua files so I believe the same approach can be applied to assets as well. Can you check this out?
If you want to implement your own solution, you might want to check out network.download()(docs) and system.pathForFile()(docs) and maybe BinaryArchive.