Hi,
I added a second layer(SettingLayer) to a scene and hide it like this :
CCScene* MainPageLayer::scene() {
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
MainPageLayer *layer = MainPageLayer::create();
SettingLayer * settingLayer = SettingLayer::create();
settingLayer->runAction(CCHide::create());
// add layer as a child to scene
scene->addChild(layer,0,1);
scene->addChild(settingLayer,900,2);
// return the scene
return scene;
then tried to get that layer by tag and Show it like this:
But it didn’t work, I tried it with setVisible(true/false), didn’t work either.
Please advise what is the best way to show and hide layers in a scene.
Thanks
Hi!
You should not write scene() when you do such call. If your this class is your scene, try this->getChildByTag(2)->runAction(CCShow::create());
instead.
That is how it works now: you call scene() method from this, it construct in memory some new scene (not current scene), in that new scene there is a Settings Layer that hided, after that you call showing of the layer, and it’s shows but on some new scene, that is not displayed now, and after that new scene will be released by Autorelease pool .
Hi Artur,
Thanks for your reply, indeed here (this) is a CCLayer (MainPageLayer)and I want to get the other layer (SettingLayer) with the mutual scene.
Is there any way to get scene from the layer without instantiating a new one?
I tried what you said: