Cocos2d-x v3 Cannot override forward function Draw

2019-04-13 05:55发布

问题:

//in my .h file
virtual void draw();

//in .cpp
void GameLayer:draw()
{
   Layer::draw();
   //draw code goes here
}

It shows cannot override forward function node::draw()

As far as I know, it was working on the old versions. Is there any new approach in cocos2d-x 3.0?

Thanks in advance.

回答1:

in v3.0 overriding the draw() method has changed.

try in .h:

virtual void draw(Renderer* renderer, const kmMat4& transform, bool transformUpdated);

try in cpp:

void draw(Renderer* renderer, const kmMat4& transform, bool transformUpdated)
{

}

If you are running the latest version 3.1 from GitHub, this has changed. Replace kmMat4 with Matrix

Edit: maybe you need to namespace it: cocos2d::Renderer