Jump to content

Convert coco2d plist to phaser json ?


gotenxds
 Share

Recommended Posts

Hello, I would like to convert the coco2d plist format to a phasers json one

It looks kinda straight forward

where coco2d has :

"frame": "{{2,1914},{148,132}}",

Phaser has:

"frame": {"x":361,"y":121,"w":118,"h":60},

 

so it looks simple enoghe but there are some properties I can find in phaser like:

sourceColorRect
offset
 

Is there some tool to convert the two?
Or can someone tell me what are the missing properties so I can create my own tool ? 

 

I have create this quick script at the office which `seems` to do the job but I still don't know where do I get the trimmed data from for example.

 

var coco = plistTojsonData; // converted via simple plist to json convertor.
var phaser = {frames:{}};

for (var key in coco.frames){
   var val = coco.frames[key];
   var frame = val.frame.replace(/{|}/g , '').split(',').map(function(x){return parseInt(x);});
   frame = {"x":frame[0],"y":frame[1],"w":frame[2],"h":frame[3]}

   var spriteOffset = val.offset.replace(/{|}/g , '').split(',').map(function(x){return parseInt(x);});
   spriteOffset = {"x" : spriteOffset[0], y:spriteOffset[1]};
   
   var rotated = val.rotated;

   var spriteSourceSize = val.sourceColorRect.replace(/{|}/g , '').split(',').map(function(x){return parseInt(x);});
   spriteSourceSize = {"x":spriteSourceSize[0],"y":spriteSourceSize[1],"w":spriteSourceSize[2],"h":spriteSourceSize[3]};

   var sourceSize = val.sourceSize.replace(/{|}/g , '').split(',').map(function(x){return parseInt(x);});
   sourceSize = {"w":sourceSize[0],"h":sourceSize[1]};

   phaser.frames[key] = {frame:frame, spriteOffset:spriteOffset, spriteSourceSize :spriteSourceSize, rotated:rotated, sourceSize:sourceSize }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...