mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
Add support for TiledJSON with base64 encoding
Tiled 0.13.0 added support for layer data compression when exporting as LUA or JSON. This means that any .tmx stored unsing base64 encoding will start exporting layer data as a base64 encoded string rather than a native array. Phaser would try to load the level anyway without emitting any errors, resulting in a corrupted level while playing. This PR adds detection and support for base64 encoded levels as long as they don't use compression.
This commit is contained in:
parent
816bcaca75
commit
308ce6b57c
1 changed files with 13 additions and 0 deletions
|
@ -233,6 +233,19 @@ Phaser.TilemapParser = {
|
|||
|
||||
var curl = json.layers[i];
|
||||
|
||||
// Base64 decode data if necessary
|
||||
// NOTE: uncompressed base64 only.
|
||||
if (!curl.compression && curl.encoding && curl.encoding === "base64") {
|
||||
var binary_string = window.atob(curl.data);
|
||||
var len = binary_string.length;
|
||||
var bytes = new Array( len );
|
||||
for (var i = 0; i < len; i+=4) {
|
||||
bytes[i/4] = binary_string.charCodeAt(i);
|
||||
}
|
||||
curl.data = bytes;
|
||||
}
|
||||
|
||||
|
||||
var layer = {
|
||||
|
||||
name: curl.name,
|
||||
|
|
Loading…
Reference in a new issue