Example single-line level file format for Flash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var VERSION:String = "B"; | |
| function dataToString (tiles:BitmapData):String | |
| { | |
| var i:int; | |
| var j:int; | |
| var tile:uint; | |
| var bytes:ByteArray = new ByteArray; | |
| for (i = 0; i < tiles.width; i++) { | |
| for (j = 0; j < tiles.height; j++) { | |
| tile = tiles.getPixel(i, j); | |
| bytes.writeByte(tile); | |
| } | |
| } | |
| bytes.compress(); | |
| return VERSION + Base64.encode(bytes); | |
| } | |
| function stringToData (data:String):BitmapData | |
| { | |
| var version:String = data.charAt(0); | |
| data = data.substring(1); | |
| var tiles:BitmapData = new BitmapData(10, 10, false, 0x0); | |
| var i:int; | |
| var j:int; | |
| var tile:uint; | |
| var bytes:ByteArray; | |
| bytes = Base64.decode(data); | |
| bytes.writeUTFBytes(data); // I can't remember what this does or if it should be here :) | |
| bytes.uncompress(); | |
| for (i = 0; i < tiles.width; i++) { | |
| for (j = 0; j < tiles.height; j++) { | |
| tile = bytes.readByte(); | |
| tiles.setPixel(i, j, tile); | |
| } | |
| } | |
| return tiles; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment