I’ve been looking for documentation for cocos2d-x but it seems to be really really poor beyond the very basics. I understand that my own classes should inherit from CCObject to be able to use (originally cocoa’s) retain/release mechanism, but I’m still confused about what happens when you new something. init is not called automatically. is it OK to call it from inside the constructor? does that alone guarantee that my object will start with a reference count of 1? what is CC_SAFE_DELETE and when should I use it? do release and autorelease work exactly like in cocoa? what about CC_SYNTHESIZE? I just need to see a properly coded class example (and it’s instantiation/destruction) to understand what I’m supposed to do so as not to screw and leave memory leaks.
thank you.
I’ve been looking for documentation for cocos2d-x but it seems to be really really
Share
If you will look to the code of CCObject class, you will see that in it’s constructor reference count is set to 1 there. So, object creation with
newis correct. Init is not called because CCObject class has no such a method. Usually I prefer to create objects using static constructor. Smth likeAbout all macroses like CC_SAFE_DELETE – you can find them in the code of cocos2dx. This macros just check if object is NULL to prevent crash on trying to call release method.