diff --git a/cocos/2d/CCCamera.cpp b/cocos/2d/CCCamera.cpp index 72715255c4..f3d3d56861 100644 --- a/cocos/2d/CCCamera.cpp +++ b/cocos/2d/CCCamera.cpp @@ -268,6 +268,7 @@ Vec3 Camera::unproject(const Vec3* src) const CCASSERT(src, "vec3 being projected can not be null"); auto viewport = Director::getInstance()->getWinSize(); + Vec4 screen(src->x / viewport.width, ((viewport.height - src->y)) / viewport.height, src->z, 1.0f); screen.x = screen.x * 2.0f - 1.0f; screen.y = screen.y * 2.0f - 1.0f; diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 89f8d8da82..2f1cc05e49 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1575,7 +1575,7 @@ public: /** get & set camera mask, the node is visible by the camera whose camera flag & node's camera mask is true */ unsigned short getCameraMask() const { return _cameraMask; } - void setCameraMask(unsigned short mask, bool applyChildren = true); + virtual void setCameraMask(unsigned short mask, bool applyChildren = true); CC_CONSTRUCTOR_ACCESS: // Nodes should be created using create(); diff --git a/cocos/2d/CCProtectedNode.cpp b/cocos/2d/CCProtectedNode.cpp index b5f078a394..3acb2cd79a 100644 --- a/cocos/2d/CCProtectedNode.cpp +++ b/cocos/2d/CCProtectedNode.cpp @@ -431,4 +431,17 @@ void ProtectedNode::disableCascadeOpacity() } } +void ProtectedNode::setCameraMask(unsigned short mask, bool applyChildren) +{ + Node::setCameraMask(mask, applyChildren); + if (applyChildren) + { + for (auto& iter: _protectedChildren) + { + iter->setCameraMask(mask); + } + } + +} + NS_CC_END diff --git a/cocos/2d/CCProtectedNode.h b/cocos/2d/CCProtectedNode.h index dff7fae398..6d9bc816de 100644 --- a/cocos/2d/CCProtectedNode.h +++ b/cocos/2d/CCProtectedNode.h @@ -163,6 +163,7 @@ public: virtual void updateDisplayedColor(const Color3B& parentColor) override; virtual void disableCascadeColor() override; virtual void disableCascadeOpacity()override; + virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; CC_CONSTRUCTOR_ACCESS: ProtectedNode(); virtual ~ProtectedNode(); diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 2eb24bca17..32562578aa 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -1335,4 +1335,17 @@ namespace ui { return this->getScaleX(); } + void Scale9Sprite::setCameraMask(unsigned short mask, bool applyChildren) + { + Node::setCameraMask(mask, applyChildren); + + if(_scale9Image) + _scale9Image->setCameraMask(mask,applyChildren); + + for(auto& iter: _protectedChildren) + { + iter->setCameraMask(mask); + } + } + }} diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index c0f0bc2bdf..2fd95c0e93 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -376,6 +376,7 @@ namespace ui { virtual float getScaleY() const override; virtual float getScale() const override; using Node::getScaleZ; + virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; protected: void updateCapInset(); void updatePositions();