CCParallaxNode extension



Ray Wenderlich, in his SpaceGame tutorial, provided an extension of the CCParallaxNode class, in the form of an objective-c adapter (

My question is: is there any way of doing the same thing in c++ (he used an objc adapter to extend the class, before he wants to access private members of the statically defined CCPointObject class, which is not possible when sub-classing the CCParallaxNode class).

If not, is it possible to include the attached patch in cocos-x, or will it be very difficult to maintain when sync’ing with cocos-iphone?

Any other solution is welcome :smiley:

Chris (0.7 KB)


You can push this patch into repo :slight_smile:


I’m sorry but I don’t quite understand what you want me to do.

I couldn’t find a way to extend (or subclass) the existing CCParallaxNode class (because I don’t know if it’s possible, nor how), so I had to directly modify the base class.
I understood the cocos2d-x-extension repo to be a repo where we can push new files to be added to cocos-x distribution, but not files altering base classes.
I don’t know how you merge cocos-iphone changes into cocos-x, so I don’t know how to proceed with this kind of modifications.

Like I asked, is there a way to do what Ray Wenderlich did, but in c++ (using objc adapter to extend a base class definition)?


Oh, so c++ has no feature of extending an existed class, It’s a problem.
I can not read code on my iPad now, can we inherit the CCParallaxNode to a new class, add new methods in it, then use the child class?


No, and that’s exactly the issue.
Modifying the base class means that is will be hard to maintain when merging cocos2d-iphone changes (well the class is not so big, but still).

The problem is:
CCParallaxNode.cpp defines a local internal class (not exported, not visible from the outside of the file).
This internal class is needed by the extension code, and inheriting the CCParallaxNode does not expose this class.

One solution would be to duplicate and rename the CCParallaxNode.cpp file in third_party extension folder, add the new code, and people who want to use it, use this new defined class. But any change to the base class (in cocos2d-iphone) would need to be merge in the new file too… which might not be easier than merging the changes directly.

The extension code I added is very simple, it’s just a new method to the class, easy to maintain, but it depends on how you merge code from cocos2d-iphone.

On a side note, I don’t fully master c++ language, so maybe there is a way to extend a class without inheritting it, I don’t know (I search and couldn’t find a way, but maybe).


Another solution, would be to inherit the CCParallaxNode class, and copy/paste the definition of the private class CCPointObject from CCParallaxNode to the new class.
That way, if any change would be made to the official CCParallaxNode class, it will be easier to update cocosx. The only thing to check is any internal change to CCPointObject.

Attached are the 2 files to be added to the project if this solution is considered (and don’t forget to add the files to the templates, and add a #include “CCParallaxNodeExtras.h” into cocos2d.h)


issue #650 created.


错误 1 error LNK2019: 无法解析的外部符号 “*declspec public:*thiscall cocos2d::CCParallaxNodeExtras::CCParallaxNodeExtras(void)” (_imp??0CCParallaxNodeExtras@cocos2d@QAEXZ),该符号在函数 “public: static class cocos2d::CCParallaxNodeExtras * __cdecl cocos2d::CCParallaxNodeExtras::node(void)” (?node@CCParallaxNodeExtras@cocos2d@SAPAV12XZ) 中被引用 E:2d-x\SpaceGame\CCParallaxNodeExtras.obj SpaceGame.win32


how to fix this error?



i used above extension to scroll background , i got issue.plz chekc this link:-

Thanks in advance