cocos2d-x-3.0绘制vs onDraw [英] cocos2d-x-3.0 draw vs onDraw
问题描述
我使用的是cocos2d-x v3.0,在某些测试项目中,我通过覆盖 Node
的 draw
方法来进行一些自定义绘制,但是在DrawPrimitives示例提供了以下功能:
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?
我应该使用这种方法进行自定义绘制吗? draw
和 onDraw
之间有什么区别?
Should I be using this method to do custom drawing? What's the difference between draw
an onDraw
?
正如@Pedro Soares所述,由于Cocos2D-X 3.0,您不能再覆盖 draw()
.您必须使用 draw(Renderer * renderer,const kmMat4& transform,bool transformUpdated)
.
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.
推荐答案
将来,cocos2d-x 3.x渲染器将与命令池一起使用多线程.
In future, cocos2d-x 3.x renderer will be multithreaded with command pool.
draw
方法,以创建新命令.当命令池执行命令时,将调用 onDraw
.目前,命令是在单线程中执行的,但是您应该假定在重载的 onDraw
方法中,它将在另一个线程中调用以简化将来的迁移.
draw
method called by visit
method, to create new command. When command is performed by command pool, onDraw
is called. At this moment, commands are performed in single thread, but in overloaded onDraw
method you should assume, that it will be called in another thread to simplify future migration.
这篇关于cocos2d-x-3.0绘制vs onDraw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!