Best way to download new content

Guys,

Currently I am designing a game… currently it has only one level… with all the related assets to that level…

I want the ability to add later levels later on after the game has been released as inapp purchases…

each level might have about 100MB assets

This is what I thought I could do,

  1. Create the game for level 1 without assets only have the logic. So this should be a small download.
  2. Release it on Itunes/Androoid
  3. When the game starts it checks to see if the assets have been downloaded, if it hasn’t it will download the assets from a url
  4. When the new levels are finished. I release an update for the app. Again this is only the logic. No assets. The new levels will appear as Inapp purchases.
  5. When the game starts it will check to see if any inapp purchases have been bought, if so then download the content for those levels…

Sound ok? Is this the best way to do this? The other option was to bundle the assets with the game. But that means the user has to download the game and each time the game will be bigger and bigger…

Few questions regarding the method I propose…

When I download the file from a server I know I can use the network.download api through corona.
It can only download it to the system.DocumentsDirectory or the system.CachesDirectory. Which is the preferred location?

I am thinking of having one file for each level. Zipped up. How can I unzip? I saw a tar helper. But from reading the comments it looked like it could not handle folders. Is there anything I can use for this? As my file will need to support folders inside the archive

do I need to worry about security

Any pointers would be really appreciated

Thanks

[import]uid: 67619 topic_id: 34600 reply_id: 334600[/import]

Hi there,

In my mind the second option you mentioned, including all the assets within an app update, and having the in app purchase simply unlock them (rather than trigger a download) would be easiest. I think it’s a more common model.

But it seems the more fundamental point is that your levels are very large, and you’re trying to figure out how to deal with that. I’m curious why each level is so large? 100mb sounds to me like a whole lot – maybe if there were ways to optimize/reduce that, the option of pre-including all the levels within the app itself would be less of an issue.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137587[/import]

Andrew,

Yeah I would defiantly prefer the second option as well.

But I have a lot of animations, a lot of sprite sheets and since I am trying to get the game on the ipad1, 2 and 3, I need different sprite sheets for all the devices. Once you bundle these up, the assets become quite large.
Vik [import]uid: 67619 topic_id: 34600 reply_id: 137606[/import]

Hi Vik,

I see what you mean. In that case your steps 1-4 seem reasonable to me. The only thought I had is that in step 3, you wouldn’t need to release an app update merely to inform the app that the new products exist. You could use store.loadProducts() (http://docs.coronalabs.com/api/library/store/loadProducts.html) to find out when new levels are ready. Of course, if the new levels require new gameplay logic each time, then I’d agree that you’d need an app update as you said.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137616[/import]

any ideas of how to unzip a file? [import]uid: 67619 topic_id: 34600 reply_id: 137618[/import]

I don’t think Corona itself offers zipping/unzipping as an API, but you might try one of these libraries: http://lua-users.org/wiki/CompressionAndArchiving.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137620[/import]

There is a TAR module available (just google for Corona SDK Tar Module). To be honest you don’t get too much from compressing images and audio, which is the bulk of your download. Using the tar module, you can build your tar file (on a Mac, it’s a standard command line tool:

tar -cvf myarchive.tar foldertopack/  

Upload that to your server.
Use network.download() to download the file to system.CachesDirectory (you will probably need to update the tar module to use the CachesDirectory)
Run it through the tar module to unpack it to system.CachesDirectory
delete the tar file.

[import]uid: 199310 topic_id: 34600 reply_id: 137623[/import]

Thanks for that…

I am not too fussed about the compression… its just about getting only one file to download as opposed to over a dozen

do you know if the tar module can handle folders in the archive?

Thanks again [import]uid: 67619 topic_id: 34600 reply_id: 137655[/import]

If you scroll to the bottom of the file, a community member has fixed it to use folders.

You have to make sure to use the tar command like this though:

tar -cvf archive.tar directory/

and not

tar -cvf archive.tar directory/*

The later format will cause the files to be inserted in the tarball in the wrong order and they won’t unpack correctly. [import]uid: 199310 topic_id: 34600 reply_id: 137658[/import]

Hi there,

In my mind the second option you mentioned, including all the assets within an app update, and having the in app purchase simply unlock them (rather than trigger a download) would be easiest. I think it’s a more common model.

But it seems the more fundamental point is that your levels are very large, and you’re trying to figure out how to deal with that. I’m curious why each level is so large? 100mb sounds to me like a whole lot – maybe if there were ways to optimize/reduce that, the option of pre-including all the levels within the app itself would be less of an issue.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137587[/import]

Andrew,

Yeah I would defiantly prefer the second option as well.

But I have a lot of animations, a lot of sprite sheets and since I am trying to get the game on the ipad1, 2 and 3, I need different sprite sheets for all the devices. Once you bundle these up, the assets become quite large.
Vik [import]uid: 67619 topic_id: 34600 reply_id: 137606[/import]

Hi Vik,

I see what you mean. In that case your steps 1-4 seem reasonable to me. The only thought I had is that in step 3, you wouldn’t need to release an app update merely to inform the app that the new products exist. You could use store.loadProducts() (http://docs.coronalabs.com/api/library/store/loadProducts.html) to find out when new levels are ready. Of course, if the new levels require new gameplay logic each time, then I’d agree that you’d need an app update as you said.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137616[/import]

any ideas of how to unzip a file? [import]uid: 67619 topic_id: 34600 reply_id: 137618[/import]

I don’t think Corona itself offers zipping/unzipping as an API, but you might try one of these libraries: http://lua-users.org/wiki/CompressionAndArchiving.

  • Andrew [import]uid: 109711 topic_id: 34600 reply_id: 137620[/import]

There is a TAR module available (just google for Corona SDK Tar Module). To be honest you don’t get too much from compressing images and audio, which is the bulk of your download. Using the tar module, you can build your tar file (on a Mac, it’s a standard command line tool:

tar -cvf myarchive.tar foldertopack/  

Upload that to your server.
Use network.download() to download the file to system.CachesDirectory (you will probably need to update the tar module to use the CachesDirectory)
Run it through the tar module to unpack it to system.CachesDirectory
delete the tar file.

[import]uid: 199310 topic_id: 34600 reply_id: 137623[/import]

Thanks for that…

I am not too fussed about the compression… its just about getting only one file to download as opposed to over a dozen

do you know if the tar module can handle folders in the archive?

Thanks again [import]uid: 67619 topic_id: 34600 reply_id: 137655[/import]

If you scroll to the bottom of the file, a community member has fixed it to use folders.

You have to make sure to use the tar command like this though:

tar -cvf archive.tar directory/

and not

tar -cvf archive.tar directory/*

The later format will cause the files to be inserted in the tarball in the wrong order and they won’t unpack correctly. [import]uid: 199310 topic_id: 34600 reply_id: 137658[/import]

Hi,

I have created tar file using following command:- 

 

tar cvf story4read.tar story4read/

 

this command generated a tar file, When I try to untar the tar file, I am getting this Error 

 

tar.lua:139: attempt to index local ‘file_handle’ (a nil value)

stack traceback:

…ctionsRR/coronaPractice/TarfileExtractSample/tar.lua:139: in function ‘untar’

…tionsRR/coronaPractice/TarfileExtractSample/main.lua:69: in function ‘unTarAllFiles’

 

 

 

But when I create tar file with BetterZip , it is working properly.

So, Please let me know that, how can we create uncompressed tar file without “BetterZip”. (or I have to buy BetterZip as its trial version already over). 

 

Note:- same problem posted on http://forums.coronalabs.com/topic/19206-tar-module-extract-tar-files-with-corona/page-3 too

 

 

 

Edit:- After above commands, I made tar file from inside the directory

 

ttmacmini001:story4read abhishekkumar.jain$ tar cvf TAR.tar *.*

 

I used this command too 

ttmacmini001:story4read abhishekkumar.jain$ tar -cvf TAR.tar *.*

 

After that also, I’m facing problem but Error type is changed ,now I am getting following Error :- 

 

2014-05-01 11:57:09.255 Corona Simulator[521:707] Invalid header magic 

2014-05-01 11:57:09.255 Corona Simulator[521:707] Runtime error

…ctionsRR/coronaPractice/TarfileExtractSample/tar.lua:120: attempt to index local ‘header’ (a boolean value)

stack traceback:

Hi,

I have created tar file using following command:- 

 

tar cvf story4read.tar story4read/

 

this command generated a tar file, When I try to untar the tar file, I am getting this Error 

 

tar.lua:139: attempt to index local ‘file_handle’ (a nil value)

stack traceback:

…ctionsRR/coronaPractice/TarfileExtractSample/tar.lua:139: in function ‘untar’

…tionsRR/coronaPractice/TarfileExtractSample/main.lua:69: in function ‘unTarAllFiles’

 

 

 

But when I create tar file with BetterZip , it is working properly.

So, Please let me know that, how can we create uncompressed tar file without “BetterZip”. (or I have to buy BetterZip as its trial version already over). 

 

Note:- same problem posted on http://forums.coronalabs.com/topic/19206-tar-module-extract-tar-files-with-corona/page-3 too

 

 

 

Edit:- After above commands, I made tar file from inside the directory

 

ttmacmini001:story4read abhishekkumar.jain$ tar cvf TAR.tar *.*

 

I used this command too 

ttmacmini001:story4read abhishekkumar.jain$ tar -cvf TAR.tar *.*

 

After that also, I’m facing problem but Error type is changed ,now I am getting following Error :- 

 

2014-05-01 11:57:09.255 Corona Simulator[521:707] Invalid header magic 

2014-05-01 11:57:09.255 Corona Simulator[521:707] Runtime error

…ctionsRR/coronaPractice/TarfileExtractSample/tar.lua:120: attempt to index local ‘header’ (a boolean value)

stack traceback: