Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
bool Node::addComponent(Component *component)
{
// lazy alloc
if (!_componentContainer)
_componentContainer = new (std::nothrow) ComponentContainer(this);
// should enable schedule update, then all components can receive this call back
scheduleUpdate();
return _componentContainer->add(component);
}
The scheduleUpdate should be called once only, subsequent calling it would lead to a warning from Scheduler. So the snippet should be corrected as:
bool Node::addComponent(Component *component)
{
// lazy alloc
if (!_componentContainer)
{
_componentContainer = new (std::nothrow) ComponentContainer(this);
// should enable schedule update, then all components can receive this call back
scheduleUpdate();
}
return _componentContainer->add(component);
}
The
scheduleUpdate
should be called once only, subsequent calling it would lead to a warning fromScheduler
. So the snippet should be corrected as: