I’m using objects derived from Ref
in my other Node
s. So in order to use it with autorelease
feature I need to manually retain
and release
them because I can’t and shouldn’t add them as child (addChild
). So, I need to override release
method of my Node
but that is not virtual. I already made release
, retain
and all schedule*
methods virtual in my cocos2d
. I think it should be commited to the repo by default.
Overriding schedule*
methods needed also to make scheduling cascade on each object in class that is not its children
P.S. Not also Ref and Node have non-virtual methods. For example Component
class has non-virtual methods also. const std::string& getName() const { return _name; }
should be virtual to be overriden in derived classes. I’m not sure I’m using Component
class right way but I have that approach
class MyComponent : public cocos2d::Component {
COMPONENT_NAME("MyComponent");
}
where COMPONENT_NAME
is a macro that’s definition is:
#define COMPONENT_NAME(__NAME__)
public:
const std::string& getName() const override {
static std::string name = __NAME__;
return name;
}
static constexpr const char* name = __NAME__;
So in that case I need getName
to be virtual
I use it like so. _myNode->getComponent(MyComponent::name)
returns either Component*
or nullptr
(More safe than using raw strings with the name of the component)