How to use .json instead of .plist as the sprite frames define?

I saw there is method:

SpriteFrameCache::addSpriteFramesWithFile

How to use .json instead of .plist as the sprite frames define?

Anybody know? Thanks!

Hello!

I’m not sure you can actually do that. Looking at the API documentation (http://www.cocos2d-x.org/reference/native-cpp/V3.0alpha0/d7/d76/classcocos2d_1_1_sprite_frame_cache.html#a76145a0afd578220bb0973be4e7f5e9d) it states

Adds multiple Sprite Frames from a plist file.

Assuming I’m right (still to be proven!), you can convert (under OSX) from a json to a plist using command line:

plutil -convert json Data.plist -o Data.json

Or you could edit cocos2dx CCSpriteFrameCache.cpp method: addSpriteFramesWithDictionary in order to parse .json maybe.

Let me know if this helps, or if you find a way to load directly from json in a smarter way :slight_smile: I’m also interested in this!

Davide Jones

Side note:
why do you need json instead of plist?

Hi, @davidejones88
Tanks for your hint! I know about converting .plist to .json. My reason of using .json is because .json is a more general data format and it has a half and more size of .plist with the same content. For example, when a 36kb .plist converted to .json, the file size will be 14kb. And i once saw somebody using ‘addSpriteFramesWithJson’ like method on the web.
Yes, i’ll look for that and share with you!

BTW, under MAC
json to plist:
plutil -convert xml1 data.json -o data.plist
plist to json:
plutil -convert json data.plist -o data.json

BTW you can use web version as well
http://json2plist.sinaapp.com/