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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
nick.meharry
Prole
Posts: 2
Joined: Sun Feb 19, 2012 10:04 pm

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

Post by nick.meharry » Sun Feb 19, 2012 10:20 pm

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?

User avatar
Taehl
Dreaming in associative arrays
Posts: 1024
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

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

Post by Taehl » Sun Feb 19, 2012 10:59 pm

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 "\").
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.

User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

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

Post by Ellohir » Sun Feb 19, 2012 11:06 pm

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...

User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

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

Post by MarekkPie » Sun Feb 19, 2012 11:13 pm

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?

nick.meharry
Prole
Posts: 2
Joined: Sun Feb 19, 2012 10:04 pm

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

Post by nick.meharry » Sun Feb 19, 2012 11:17 pm

@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.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post by Robin » Mon Feb 20, 2012 9:49 am

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.
Help us help you: attach a .love.

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito » Mon Feb 20, 2012 10:58 am

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?
When I write def I mean function.

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests