Tuesday, March 05, 2013

'setIsTouchEnabled' : is not a member of 'HelloWorld'


If you are upgrading from Coocs2dx 1.x to Cocos2dx 2.x you will have a lot of conversion to do.

If you get the error:

'setIsTouchEnabled' : is not a member of 'HelloWorld'

you really want to switch the code to this:

this->setTouchEnabled(true);


You might struggle with how to convert a CCObject to an int. Use this type of cast:

int x = ((CCString *)spawnPoint->objectForKey("x"))->intValue();


You might also struggle with callfunc, which is very simple to use in Objective-C but not so easy in Cocos2dx.

http://stackoverflow.com/questions/11917928/callfunc-in-cocos2d-x

This tutorial was very useful building a demo game in Cocos2dx

http://www.raywenderlich.com/1163/how-to-make-a-tile-based-game-with-cocos2d

I was already familiar with it from using Cocos2d.


This commit is really large, but shows a lot of useful conversion moves from early Coocos2dx to modern. This guy or girl knew what he/she was doing and made quick work of a lot of before/after conversion code that made doing similar work on my side very easy. Just search for the code I had and found what they changed it to.

https://github.com/cocos2d/cocos2d-x/pull/779/files


Often we need to concatenate strings using the + operator. A shortcut way to do this in C++ is as follows:

CCSprite *sprite = CCSprite::spriteWithFile((name+".png").c_str());


This was kinda useful tutorial to introduce Cocos2d vs. Cocos2dx from a memory and reference counting standpoint:

http://www.rengelbert.com/tutorial.php?id=188

No comments: