Creating a bank of sprites?

BlitzMax Forums/BlitzMax Beginners Area/Creating a bank of sprites?

Rico(Posted 2008) [#1]
Hello. I wrote a program which automatically grabs sprites from a .png file. It takes a while to run so I don't want to do this in my main game. I need to save the sprites somehow, and then load them in my game.
In the 'grabber' program it puts them into an array called image. e.g. image[0]=spaceship, image[2]=spaceship2.
I'd like to save this array to a file. Is this possible?

Thank you very much.

Rico


deps(Posted 2008) [#2]
Something like this maybe?
local pm:TPixmap = Lockimage( image[0] )
SavePixmapPNG( pm, "myfile.png" )
UnlockImage( image[0] )

Will of course only save the first one, so you need to save the others as well.


Volker(Posted 2008) [#3]
You can take a look at Brucey's Persistence mod.
With it you can save nearly all objects, arrays too (1 dimensional only).
Very helpfull.
Perhaps the files get very large, buts it' worth trying.

I cant find the exact link at the moment, got lost in Brucey's websites.
Start here:
http://blitzbasic.com/Community/posts.php?topic=75695


Rico(Posted 2008) [#4]
Thanks deps - I could do that with a different number at the end of each filename. Then I could easily load them in to my program using a loop. Only problem is that I could have a lot of files.

Volker - Yes that does sound useful. Do you think it would be possible to save an array of images?

Thank you both - Rico.


Volker(Posted 2008) [#5]
I've tested it and was not able to save an image.
There is a way but its a bit complicated, by using
metadata to not store the fields which make problems
(TImage in this case) and use methods to prepare the
fields in the array befor saving and to restore them after saving.
I'll post code if you wish, but you need to know the persistence mod first.

By the way, I found brucey has a mod freeimage:
"The FreeImage module adds BlitzMax support for loading and saving of a large number of different formats, using the open source FreeImage library.
And save : BMP, EXR, GIF, HDR, ICO, JPEG, JPEG-2000, PBM, PGM, PNG, PPM, TARGA, TIFF, WBMP and XPM."

http://brucey.net/programming/blitz/#bahfreeimage


Volker(Posted 2008) [#6]
I just found this:

BlitzMax pacimage mod:
http://www.ooeyug.com/texpac/

"Texpac is an application written by David Maziarka that will pack gfx files up into one image. It can be used for sprites, textures, animation strips and bitmap fonts. There are 2 resulting in files, one .png and one .pac file that contains the coordinates of each packed image. "