help porting GB2ShapeCache.js to v3

Hi mates,

I’m trying to port GB2ShapeCache to v3 but I’m having some problems, my javascript knowledge is very poor so I’m really lost.
My main problem is with this function. I don’t know how to port it successfully. :frowning:
Hope you could help me!

    /**
     * Adds shapes to the shape cache from file created by Physics Editor. 
     * @param {String} plist - name of the plist file to load
     * @example
     * // add Shapes to GB2ShapeCache With File
     * cc.GB2ShapeCache.getInstance().addShapesWithFile(s_shapesPlist);
     */
    addShapesWithFile:function (plist) {
        var dict = cc.FileUtils.getInstance().dictionaryWithContentsOfFileThreadSafe(plist);

        cc.Assert(plist, "plist filename should not be NULL");
        if (!cc.ArrayContainsObject(this._loadedFileNames, plist)) {
            this._addShapesWithDictionary(dict);   
        }
    },

Hi, @kaotiklabs

You can use cc.loader.getValueMapFromFile( fileurl );
In Cocos2d-JS v3.0, we have removed cc.FileUtils, you can find some documentation here: http://www.cocos2d-x.org/docs/manual/framework/html5/v3.0/cc-fileutils/en
and the upgrade guide to v3.0: http://www.cocos2d-x.org/docs/manual/framework/html5/release-notes/v3.0a/upgrade-guide/en

Huabin

but does this work for HTML5??
I’m getting an “undefined is not a function” when using it.

should I import something else?

Holy …

Sorry, I made a mistake, the function name is not correct

cc.loader.loadJson( fileurl );

Sorry, can you elaborate a bit more? I don’t manage to get it working.

When I do this.

var dict = cc.loader.loadJson(plist);

I always get this [Error] SyntaxError: JSON Parse error: Unrecognized token ‘<’ onload (CCBoot.js, line 486)
In plist var I have the path --> res/HD/bodies.plist

Sorry again, @kaotiklabs

I haven’t noticed that you need to load a plist file, so,

// for loading a plist file 
cc.loader.loadAliases( fileurl );

// for loading a json file 
cc.loader.loadJson( fileurl );

You should use the first one

@pandamicro, still not working. Mhh if I try to use loadAliases I get this error:

CCBoot.js:716 
TypeError: 'undefined' is not an object (evaluating 'option.cb = function(err, results){
            if(err) cc.log(err);
            if(cb) cb(results);
        }')

Hi @kaotiklabs

:stuck_out_tongue: Sorry for misleading you around, seems like I was not so familiar with cc.loader. So I have tested this morning myself and get it working finally.

Here is what you can do:

cc.loader.load( filename );

Sorry again, I’m shamed… and here you are a doc for cc.loader: http://www.cocos2d-x.org/docs/manual/framework/html5/v3.0/cc-loader/en

Huabin