[Resolved]Ray's cross platform exaple - Method broken in 2.1.3

Greetings,

I followed Ray’s cross platform tutorial (http://www.raywenderlich.com/32970/how-to-make-a-cross-platform-game-with-cocos2d-javascript-tutorial-getting-started).
It works fine using version 2.1.1 of the framework, but as I upgrade to 2.1.3 I get the following error in my main.js in ctor function:
Uncaught TypeError: Object #<Class> has no method 'preload'

This happens when calling the following:
cc.Loader.getInstance().preload(g_ressources);

How should this be written in 2.1.3 please?

Thanks,

I’m not currently using 2.1.3, but looking at CCLoader.js on github ( https://github.com/cocos2d/cocos2d-html5/blob/develop/cocos2d/CCLoader.js )

I’d guess you want to check out initWithResources, looks like selector and target can be null, so give it a shot just replacing preload. If not I’m sure one of the devs will get you an answer :slight_smile:

/***
** init with resources
* `param {Array} resources

  • `param {Function|String} selector
    * @param {Object} target
    */
    initWithResources:function (resources, selector, target)

I am sorry, but we add async preloading function into v2.1.3, and the usage of preloading has been changed.

Please refer to template folder:

//load resources
        cc.LoaderScene.preload(g_ressources, function () {
            director.replaceScene(new this.startScene());
        }, this);

or

//load resources
        cc.Loader.preload(g_ressources, function () {
            director.replaceScene(new this.startScene());
        }, this);

Jem I experienced the same issue as you. It is not very clear when installing that there are changes. I think there are others that are also undocumented.

Hi,

I just discovered that when you use cc.Loader (second recommendation by Shun Lin above), you get a warning to start the director with “runWithScene” instead of the “replaceScene”. However the first recommended code stated by Shun Lin:

//load resources
cc.LoaderScene.preload(g_ressources, function () {
director.replaceScene(new this.startScene());
}, this);

works properly for me.

Be sure you have g_ressources defined.

Hopefully this is helpful for others using 2.1.3.

Thanks

To call “runWithScene” or “replaceScene” depend on you are using Loader.preload or LoaderScene.preload.

If you are using Loader.preload, there is not a previous scene in the director. So you should use runWithScene.
If LoaderScene, you should use replaceScene instead.

Hi,

Thanks for all your help and clarifications!
Problem solved and understood :slight_smile:

A good day to you all,
J.