Page 1 of 1

Load an image from inside a zip (inside the .love)?

Posted: Sun Feb 19, 2012 10:20 pm
by nick.meharry
I'm working on a custom animated sprite format that involves several PNGs zipped up with a control file. I can't seem to open the image however. love.graphics.newImage has a version that takes a file handle, but it refuses to take it from LuaZip. I get the following error:

Code: Select all

Error: [string "loaders/animatedSprite.lua"]:18: Incorrect parameter type: expected ImageData
stack traceback:
        [C]: in function 'newImage'
        [string "loaders/animatedSprite.lua"]:18: in function 'addImage'
        [string "loaders/animatedSprite.lua"]:45: in function 'fromFile'
        [string "main.lua"]:13: in function 'load'
        [string "boot.lua"]:310: in function <[string "boot.lua"]:308>
        [C]: in function 'xpcall'
animatedSprite.lua

While it doesn't seem to be a standard file handle, it supports :read(), :seek(), :lines(), and :close() methods. Is there another method I can accomplish this, or should I rework the format to not use a zip file?

Re: Load an image from inside a zip (inside the .love)?

Posted: Sun Feb 19, 2012 10:59 pm
by Taehl
You can do this with no problem, just make sure your filepaths are UNIX-compliant (99% of the time, your problem will just be that you used "/" instead of "\").

Re: Load an image from inside a zip (inside the .love)?

Posted: Sun Feb 19, 2012 11:06 pm
by Ellohir
If the .love is a zip, why put a zip inside a zip? The loading will be slower but the size won't change that much...

Re: Load an image from inside a zip (inside the .love)?

Posted: Sun Feb 19, 2012 11:13 pm
by MarekkPie
I assume it's going to be like an animated GIF or something. Why all the why's? Can't he just have fun making some crazy concoction?

Re: Load an image from inside a zip (inside the .love)?

Posted: Sun Feb 19, 2012 11:17 pm
by nick.meharry
@Taehl: To be clear, I'm embedding another zip file inside the .love.

@Ellohir: It's not so much about the size savings as it is about being able to move multiple files around in a cohesive piece. For example, you can't send a folder through the network; it has to be bound within an archive.

My current workaround is to copy the zipfile to a temp file, then unzip that into a temp directory, and load the files from there. It's really hacky, and involves more os.execute and disk activity than I'd like, but it'll work until I get around to reimplementing that part in C. I'm open to more elegant solutions.

Re: Load an image from inside a zip (inside the .love)?

Posted: Mon Feb 20, 2012 9:49 am
by Robin
With LovelyBigPlanet, we had a similar problem as you, which we solved by making resources shared, and letting each level describe what resources it needed, so the game could download all the resources it didn't already have.

Re: Load an image from inside a zip (inside the .love)?

Posted: Mon Feb 20, 2012 10:58 am
by kikito
nick.meharry wrote:@Ellohir: It's not so much about the size savings as it is about being able to move multiple files around in a cohesive piece. For example, you can't send a folder through the network; it has to be bound within an archive.
No one has mentioned quads yet, so I'll do: Why not use quads then? You need files that aren't images, maybe?