diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 93cb2e2a7d..4a521f81c7 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -769,6 +769,17 @@ public: * Please use `getChildByName()` instead. */ virtual Node * getChildByTag(int tag) const; + + /** + * Gets a child from the container with its tag that can be cast to Type T. + * + * @param tag An identifier to find the child node. + * + * @return a Node with the given tag that can be cast to Type T. + */ + template + inline T getChildByTag(int tag) const { return static_cast(getChildByTag(tag)); } + /** * Gets a child from the container with its name. *