[solved] Can we store a BitmapData inside a FlxSave?



  • Hi,

    I'm trying to save the BitmapData of a user inside a FlxSave so he don't have to re-import his stuff the next time he plays. I'm targeting Flash...
    The problem is that when I trace the BitmapData after adding it to the savefile, everything's fine, but when I load that savefile afterwards, the BitmapData is missing.

    Is that normal? Maybe we can only store Int and String in a savefile?
    If that so, is it possible for me to convert the BitmapData into a String in order to store it inside the savefile? And decode it later on...

    Thanks for your precious help !



  • I think you need to serialize and deserialize the BitmapData to save it.



  • You can store binary data in Base64 format, which is a string



  • Thanks @DleanJeans, that was the perfect hint :)

    I just had to convert the BitmapData to Bytes before serializing it. Here's what I did:

    import flixel.addons.util.PNGEncoder;
    import haxe.Serializer;
    import haxe.Unserializer;
    import flash.display.BitmapData;
    (...)
    	private function serialize(bmpData:BitmapData):String
    	{
    		var bytes:Bytes = Bytes.ofData(PNGEncoder.encode(bmpData));
    		var serializer = new Serializer();
    		serializer.serialize(bytes);
    		return serializer.toString();
    	}
    
    	private function unserialize(str:String):BitmapData
    	{
    		var bytes:Bytes = new Unserializer(str).unserialize();
    		var bmpData:BitmapData = extractPNG(bytes);
    		return bmpData;
    	}
    

    It works fine, but maybe I could do something simplier that that?



  • Hi everyone. I'm back at resurrecting that old project, since SWF games will no longer be supported by browsers by the end of the year... So I expected to simply compile it to cpp. Turns out it's not that simple...

    My project crash exactly on this piece of code I wrote in 2016. BitmapData doesn't seem to exist for cpp target and that's a bit confusing for a first problem after all these years... Does anyone know what should I do to make it work, or what is replacing BitmapData for other targets than Flash?

    Thanks

    EDIT:
    Solved. I just had to replace
    import flash.display.BitmapData;
    by
    import openfl.display.BitmapData;


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.