Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Parsing JSON Sprite Sheet #56

Open
jjsev opened this issue Dec 24, 2012 · 4 comments
Open

Problem Parsing JSON Sprite Sheet #56

jjsev opened this issue Dec 24, 2012 · 4 comments

Comments

@jjsev
Copy link

jjsev commented Dec 24, 2012

Hi,

I'm trying to teach myself LimeJS to make a game with sprites, and since I'm not on a Mac, I decided to use TexturePacker and JSON instead of Zwoptex. As my first project I decided to recreate lime/demos/tests/frame4.js which is the game with the blue monsters.

I recreated the sprite sheet and published it as JSON (array), made it an asset with gensoy and updated, but when I tried the game, I got the error message (in Opera Dragonfly) that it couldn't find the frames. I did some snooping around, and it turned out the JS file generated by gensoy had this structure:

{ // Level 1
 "frames":
   [ // Level 2
      {associative array of sprite information including file name}, // Level 3
   ],
 "meta": ...
}

The file lime/src/helper/parser/json.js however says:

var dict = {};
    var root = data['frames'];
    for(var i in root){
        var frame = root[i];
...
        dict[i] = [new  goog.math.Rect(frame['frame']['x'],frame['frame']['y'],w,h),
...
            ];
    }
    return dict;

I.e., it's expecting the value of the "frames" key to be an associative array wherein the keys are filenames, but level 2 of the structure is actually a list. I changed dict[i] to dict[frame['filename']] on line 25 of json.js, and that solved the problem, and I was able to recreate the game with the blue monsters.

Now my question is whether this is a problem with how TexturePacker generates JSON files, how gensoy makes the assets, or how json.js parses the assets (in which case my solution would appear to be the correct fix).

Or did I just miss some vital step somewhere?

@simianarmy
Copy link
Contributor

What version of TP? v3 might have changed the json format

Sent from my iPad

On Dec 24, 2012, at 7:27 AM, jjsev [email protected] wrote:

Hi,

I'm trying to teach myself LimeJS to make a game with sprites, and since I'm not on a Mac, I decided to use TexturePacker and JSON instead of Zwoptex. As my first project I decided to recreate lime/demos/tests/frame4.js which is the game with the blue monsters.

I recreated the sprite sheet and published it as JSON (array), but I got the error message (in Opera Dragonfly) that it couldn't find the frames. I did some snooping around, and it turned out the JS file generated by gensoy had this structure:

{ // Level 1
"frames":
[ // Level 2
{associative array of sprite information including file name}, // Level 3
],
"meta": ...
}
The file lime/src/helper/parser/json.js however says:

var dict = {};
var root = data['frames'];
for(var i in root){
var frame = root[i];
...
dict[i] = [new goog.math.Rect(frame['frame']['x'],frame['frame']['y'],w,h),
...
];
}
return dict;
I.e., it's expecting the value of the "frames" key to be an associative array wherein the keys are filenames, but level 2 of the structure is actually a list. I changed dict[i] to dict[frame['filename']] on line 25 of json.js, and that solved the problem, and I was able to recreate the game with the blue monsters.

Now my question is whether this is a problem with how TexturePacker generates JSON files, how gensoy makes the assets, or how json.js parses the assets (in which case my solution would appear to be the correct fix).

Or did I just miss some vital step somewhere?


Reply to this email directly or view it on GitHub.

@jjsev
Copy link
Author

jjsev commented Dec 24, 2012

Help --> About says "TexturePacker(Pro) 3.0.4" but I'm using the essential (lite) version.

The generated json file itself says '"version": "1.0",' in the meta section. I put the whole json on pastebin at http://pastebin.com/zjNiiwQu

@itsMikey
Copy link

Did you ever figure this out? I am having the same exact trouble.

@simianarmy
Copy link
Contributor

It looks like it's still outputting the old format where frames property is an array. It is now an object. I'm definitely using TP 3 but using the paid version - maybe there is a diff there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants