Hi,
is this possible in cocos2d-js now?
i tried this way :
console.log(this.node._parent)
this.node is root node. it returns cc.Scene but node’s name is empty.
http://cocos.sonarlearning.co.uk/docs/nodes
in this page here is the c++ version
nodeName->getScene( );
but in Js part writing:
// no JavaScript equivalent
how do I get scene name in cocos2d-js
cant getting current scene name is a big problem for me.
I tried
cc.director.getScene()
It returns cc.Scene, but there is no “name”. it is null.
are there anyone knows solution?
@nite @pandamicro
I achieved the problem.
getSceneName: function() {
//console.log(cc.game._sceneInfos)
//console.log(cc.director._scene._id)
var sceneName
var _sceneInfos = cc.game._sceneInfos
for (var i = 0; i < _sceneInfos.length; i++) {
if(_sceneInfos[i].uuid == cc.director._scene._id) {
sceneName = _sceneInfos[i].url
sceneName = sceneName.substring(sceneName.lastIndexOf('/')+1).match(/[^\.]+/)[0]
}
}
return sceneName
}
5 Likes
cc.director.getScene().name works on Cocos Creator simulator but not in browser (didn’t test it on native).
Your solution is best, Thanks for sharing!
2 Likes