mirror of
https://github.com/wassname/phaser.git
synced 2026-08-05 13:21:00 +08:00
Loader can now parse both JSON Hash and JSON Array formated texture atlas files.
This commit is contained in:
+46
-1
@@ -65,7 +65,7 @@ Phaser.Animation.Parser = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from json.
|
||||
* Parse frame data from json texture atlas in Array format.
|
||||
* @param json {object} Json data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
@@ -109,6 +109,51 @@ Phaser.Animation.Parser = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from json texture atlas in Hash format.
|
||||
* @param json {object} Json data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
JSONDataHash: function (game, json) {
|
||||
|
||||
// Malformed?
|
||||
if (!json['frames']) {
|
||||
console.log(json);
|
||||
throw new Error("Phaser.AnimationLoader.parseJSONDataHash: Invalid Texture Atlas JSON given, missing 'frames' object");
|
||||
}
|
||||
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.Animation.FrameData();
|
||||
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json['frames'];
|
||||
var newFrame;
|
||||
|
||||
for (var key in frames) {
|
||||
|
||||
newFrame = data.addFrame(new Phaser.Animation.Frame(
|
||||
frames[key].frame.x,
|
||||
frames[key].frame.y,
|
||||
frames[key].frame.w,
|
||||
frames[key].frame.h,
|
||||
key
|
||||
));
|
||||
|
||||
newFrame.setTrim(
|
||||
frames[key].trimmed,
|
||||
frames[key].sourceSize.w,
|
||||
frames[key].sourceSize.h,
|
||||
frames[key].spriteSourceSize.x,
|
||||
frames[key].spriteSourceSize.y,
|
||||
frames[key].spriteSourceSize.w,
|
||||
frames[key].spriteSourceSize.h
|
||||
);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Parse frame data from an XML file.
|
||||
* @param xml {object} XML data you want to parse.
|
||||
|
||||
Reference in New Issue
Block a user