将plist转成json,提升加载速度

https://forum.cocos.com/t/2d-mmo/46479
这篇帖子提到将plist转化成json提升加载速度。我们公司最近也在做一款rpg游戏,有很多怪物是用TP打包成合图。在调试模式下,加载几张合图要加载好几秒。将plist转成json后,感觉加载速度明显提升。

这里附上plist转json的python3代码

from biplist import *
import json
import os

def toIntList(ss):
    ss = ss.replace('{', '')
    ss = ss.replace('}', '')
    numAtrArr = ss.split(',')
    return [int(e) for e in numAtrArr]

def parser(frames):
    jsonObj = {}
    for frameName in frames:
        # rect
        textureRect = frames[frameName]['textureRect']
        # offset
        spriteOffset = frames[frameName]['spriteOffset']
        # originalSize
        spriteSourceSize = frames[frameName]['spriteSourceSize']
        # rotated
        textureRotated = frames[frameName]['textureRotated']

        frameName = frameName.replace('/', '-')
        jsonObj[frameName] = {
            'rect' : toIntList(textureRect),
            'offset' : toIntList(spriteOffset),
            'originalSize' : toIntList(spriteSourceSize),
            'rotated' : 1 if textureRotated else 0
        }
    return jsonObj

def save(fileName, jsonObj):
    with open('{}.json'.format(fileName), 'w', encoding='utf-8') as file:
        file.write(json.dumps(jsonObj))


def piple(filepath, fileName):
    plist = readPlist(filepath)
    frames = plist['frames']
    jsonObj = parser(frames)
    save(fileName, jsonObj)

if __name__ == "__main__":
    for root, dirs, files in os.walk('.'):
        for fileName in files:
            if fileName.endswith('plist'):
                piple(os.path.join(root, fileName), fileName[:-len('.plist')])
                # print(fileName)

实际使用是利用了cc.SpriteFrame的setTexture方法。

正式发布的时候creator会自动将plist配置转化成一个json(一个plist对应一个json)。
看来这个没什么卵用,真是瞎折腾!

1赞

棒棒棒