cocos2d-x CCScrollView vs cocos2d-iphone CCScrollLayer

cocos2d-x CCScrollView vs cocos2d-iphone CCScrollLayer
0.0 0


Hey all,

I’m in the middle of porting a recent iPhone app built with cocos2d to cocos2d-x and for the most part things are going surprisingly well with the translation, but there’s one particular area that’s problematic, and I can’t seem to find a workable solution. Hopefully someone here can make a suggestion, or even tell me I need to create my own solution.

In my iPhone version, the user is asked to select a particular item to use in the game from a list of available items. I’ve set up a CCScrollLayer that contains an array of CCLayers. As the player swipes through, the CCScrollLayer stops at each selectable item, and using the CCScrollLayerDelegate I can get the index of the currently shown CCLayer, which I pass into the game. My code goes something like this:

NSMutableArray imagesArray = init];
for {
itemLayer = [[CCLayer alloc] init];
CCSprite itemSprite = ];
itemSprite.position = ccp;
scroller = [[CCScrollLayer alloc] initWithLayers:imagesArray widthOffset:130];
[self addChild:scroller];
scroller.showPagesIndicator = NO;
[scroller setDelegate:self];
[scroller setMinimumTouchLengthToChangePage:30.0f];

…pretty easy! A separate button is then used to select the item and the scene changes to the game itself.

The problem with porting to cocos2d-x is that there doesn’t seem to be an obvious equivalent. CCScrollView would seem to be the obvious choice, but it doesn’t seem to have the same functionality, and the syntax is very different, to the point of making me think I’m looking in the wrong direction. Can someone suggest an option for duplicating the functionality I’m looking for? Searches have turned up little beyond very specific question with few actual examples. From its delegate methods, it looks like CCListView might be what I need, but it sounds from the class itself that it might be an equivalent to a UITableView. I’m happy to wrestle with the code, I just don’t want to spend an entire day trying to adapt my code to a solution that ultimately doesn’t meet my needs. Anyone have any thoughts or experience with this kind of thing?

EDIT: As an aside, a total noob question: how the heck to you implement a delegate protocol in cocos2d-x? CCLayer implements several protocols like so:

class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public {

…but when I try doing something like:

class SelectLayer : public cocos2d::CCLayer, public cocos2d::extension::CCScrollViewDelegate{

…I get an error at LAYER_CREATE_FUNC(SelectLayer); that says “Allocating an object of abstract class ‘SelectLayer’”. Any pointers? I suspect it’s just something dumb.



I meet the same problem.What’s your solution? Can you share with us;:slight_smile: :slight_smile: