Help hello world scene class arguments

Help hello world scene class arguments
0.0 0


I’m playing around with the framework, it looks good! :slight_smile:

Now I’m just trying to modify the HelloWorld app and create a re-usable class (eg init level by name), to do this I’m trying to pass the name to init().
This is what I have so far:

class StarJumpScene : public cocos2d::CCLayer
// Originally this was init()
virtual bool init(const char* levelName);

static cocos2d::CCScene* scene();

// Original comment by cocos: implement the “static node()” method manually

I’m getting a compilation error at line with CREATE_FUNC:
The error is: Error 1 error C2660: ‘StarJumpScene::init’ : function does not take 0 arguments

As init expects now an argument (which I do not know at compile time), I don’t want to hard code it here…
Am I supposed to override the node() method? (just reading the comment there)



I’ve looked inside the cocos macros and found this is what it does:

** define a create function for a specific type, such as CCLayer
* @TYPE class type to add create(), such as CCLayer
#define CREATE_FUNC static TYPE
create() { TYPE *pRet = new TYPE(); if (pRet && pRet~~>init) { pRet~~>autorelease(); return pRet; } else { delete pRet; pRet = NULL; return NULL; } }

So do I do the auto-release process myself to overcome this?
I see init by default does not take arguments…


Ok I think I got it… I just pasted the code of CREATE_FUNC in my class file and gave init() an argument…


CREATE_FUNC are only for those create functions that takes no argument. For everything else, you need to write your own create() method.