Cocos2d-x v3 Cannot override forward function Draw
Asked Answered
B

1

2
//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.

Barrettbarrette answered 9/5, 2014 at 5:11 Comment(2)
m c++ is rusty but i think you just need to remove the .h declaration of the method, after all it's already declared in the node's headerAuklet
No boss, removing from .h shows the same error on .cppBarrettbarrette
S
6

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

Shandishandie answered 9/5, 2014 at 16:53 Comment(3)
I recall trying this in my proj and getting Renderer object not recognized as if that object is local to Node in cocos2d and not exposed by importing the cocos2d.hSuborder
Can you somehow show me the errors? Renderer is very core. There should be no reason for it to not be "exposed"Shandishandie
If I try to override this method I just get syntax error: identifier 'Renderer' while having #include cocos2d.h at the top.Suborder

© 2022 - 2024 — McMap. All rights reserved.