I'm using cocos2d-x v3.0 and in some test project I'm doing some custom drawing by overriding Node
's draw
method, but in the DrawPrimitives example provided they do something like this:
void DrawPrimitivesTest::draw()
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(DrawPrimitivesTest::onDraw, this);
Director::getInstance()->getRenderer()->addCommand(&_customCommand);
}
void DrawPrimitivesTest::onDraw()
{
// drawing code here, why?
}
From reading the header and source files it seems like this may be some way of sending render commands straight to the renderer, is that correct?
Should I be using this method to do custom drawing? What's the difference between draw
an onDraw
?
EDIT:
As @Pedro Soares mentioned, since Cocos2D-X 3.0 you can't override draw()
anymore. you have to use draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated)
instead.
MyLayer::onDraw
toMyLayer::onDrawPrimitives
. – Tut