Store BitmapData in cache?

69 views
Skip to first unread message

Jimmy JimJim

unread,
May 18, 2015, 1:37:04 AM5/18/15
to haxef...@googlegroups.com
Hi all

I'm very new to HF so I might be going about this completely wrong...

I'm loading up some external data from a file (a 400x400 .psd file which contains all my 32x32 sprites) and storing it as a 'BitmapData' object. I then pass that through to 'loadGraphic' and get the image section I need from the data. That works fine.

What I want to do though is load the file up during the Main.hx file and the commit it to some sort of cache.

I was looking at "BitmapFrontEnd" which lets me pass in a BitmapData object + a cache key, but when I try and get the value back out it always seems to be null. I also looked at Asset.loadBitmapData, but this just seems to take a file, not something that's already a BitmapData object.

Is there some way to store a loaded asset like this somewhere in HF that I can retrieve later?

Cheers!

Gama11

unread,
May 18, 2015, 4:35:02 AM5/18/15
to haxef...@googlegroups.com, laserdi...@gmail.com
HaxeFlixel will cache assets loaded through loadGraphic() automatically.

Jimmy JimJim

unread,
May 18, 2015, 10:51:06 AM5/18/15
to haxef...@googlegroups.com, laserdi...@gmail.com
As far as I understood it, loadGraphic works by taking an image (or data) and caching it, but the cache only works if you pass the same file into it. In my case I don't want to keep passing my bitmap data around my game, I just want to say something like:

loadGraphic(bitmapFrontEnd.get("gamesprites")); //doesn't work, but something like this.

I guess I can just pass a static variable around that references back to bitmapdata, but I was hoping their might be some kind of asset manager built in.

Gama11

unread,
May 18, 2015, 12:45:26 PM5/18/15
to haxef...@googlegroups.com, laserdi...@gmail.com
The CachedGraphics object of sprites has a "key" that is used to store the asset. FlxG.bitmap.get(key); should do the trick.
Reply all
Reply to author
Forward
0 new messages