How are scenes working under Cocos Creator?
I’m having big troubles trying to use something else than cc.director.loadScene to start a new scene…
If I call cc.director.runScene (or pushScene), all I get is the following error message:
TypeError: this._runningScene.onEnter is not a function
I tried to add:
onEnter: function() {
},
into the calling and called modules, but it didn’t helped, I always get the same error message.
It looks like only loadScene is working, but runScene and push/popScene are mentioned in Cocos Creator API: http://cocos2d-x.org/docs/api-ref/creator/v0.71/classes/director.html#method_runScene
Is there any way to use runScene and push/popScene, and if yes, how?
(all the exemples I found are using loadScene, none are using runScene nor push/popScene)
If I only use loadScene to switch between scenes, what about memory management, will the scenes be stored only once in memory, even when loaded several times, or do I have to do the cleanup myself?
(any exemple welcome )
Thank you.
–
Daniel
Let us ask @pandamicro to help us with this.
The error I was getting when calling runScene was due to the fact I called it with same parameter than loadScene (a string containing the name of the scene), while runScene and pushScene are expecting a cc.Scene parameter: my fault, sorry for that.
My problem remain: I don’t know how to initialise a cc.Scene object using one of the existing scenes I have in assets, so I’m still unable to use runScene/pushScene…
Can someone please provide examples using those functions, or any other way to manage scenes?
Thanks.
–
Daniel
For v0.7.1, you can only use loadScene, pushScene / popScene are for scene in the scene graph, which should be _ccsg.Scene
type. As for runScene, you must first have the cc.Scene
object to be able to run it, but we haven’t provided loading scene API in cc.loader
.
So in v0.7.1, please use :
cc.director.loadScene('sceneName');
The scene object will be released by garbage collection after it’s no longer used.
Additionally in v1.0, you will be able to do:
cc.loader.load('resources://res/scenes/sceneName', function (sceneAsset) {
cc.director.runScene(sceneAsset);
});
In this API, you will control when to load your scene.
Ok, thanks for the clarification.
–
Daniel
Im not able to find push/popScene on Cocos Creator docs. Are those functions still in the API?