Childs of layer inherits camera mask?

Does childs of layer inherits the camera mask that i set on layer?

is there an order to do it?

m_layer = Layer::create();
auto camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
camera->setCameraFlag(CameraFlag::USER3);
m_layer->addChild(camera);
m_layer->setCameraMask(static_cast<int>(CameraFlag::USER3));
addChild(m_layer);

auto spr = Sprite::create("someSpriteName");
m_layer->addChild(spr);

what camera mask should be on spr?

Yes, the parent-child relationship. https://github.com/cocos2d/cocos2d-x/blob/v3/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp

No, only is applied on childs when you apply the mask to the layer.

If you create a sprite after, then the mask is the default one. even if you add that sprite as child of that layer.

m_layer->setCameraMask(static_cast<int>(CameraFlag::USER3));

will also set cameramask of current childs (not the ones added later)

you can also pass a bool in this function if you don’t want the childs to be in this mask like this

m_layer->setCameraMask(static_cast<int>(CameraFlag::USER3),false);

since your sprite is added later you also have to put the same camera mask on the sprite.

1 Like

yes, i could find out what was happening but thank you for the time. i ll mark your answer as solution. :grinning:

In the cpp-tests the layers mask are always set at the end, that is how i realized about my bugs.

i think it would be a good practice to inherit the current mask set on parent and not to set a default one.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.