1

I'm using Spritebuilder to make my game, and CCScrollView usually saves me quite a bit of time. I'm trying to implement the scroll view much in the same way as the home screen on an iphone uses the UIScrollView. I want the page indicators to be visible and change as you scroll through the pages (the little white dots for iOS 7).

In Spritebuilder I set up the CCScrollView as a child of a CCNode. Then I set the content node to another one of my ccbi files, EasyPackpage1. When I run my project, everything works pretty well. I currently have a content node that is large enough so that it has three different pages, so if I scroll to the right it locks onto the next page, scroll to the right again, it locks onto the next page. The only problem is that the page indicators are non-existent. How can I get these page indicators?

If someone knows the solution for doing this using purely code, that would also be greatly appreciated. Cocos2d v3 still has very little documentation and I haven't been able to find much on how to use CCScrollView, since it looks like CCScrollLayer is deprecated in v3.

enter image description here

Thanks for the help!

spaderdabomb
  • 942
  • 12
  • 28

1 Answers1

0

You need to create your own custom page indicators. What I did is add little images for all the pages that will be shown, and I swap out between a selected and unselected dot image when the scroll view ends decelerating.

- (void)scrollViewDidEndDecelerating:(CCScrollView *)scrollView {
    NSInteger page = scrollView.scrollPosition.x / 320;
    for (int i = 0; i < self.dotArray.count; i++) {
        if (i == page) {
            [[self.dotArray objectAtIndex:i] setSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"ccbResources/nav-dot-active.png"]];
        } else {
            [[self.dotArray objectAtIndex:i] setSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"ccbResources/nav-dot.png"]];
        }
    }
}

Make sure to set your scene as a CCScrollViewDelegate and set:

self.scrollView.delegate = self;

The self.dotArray I'm using is just initialized in didLoadFromCCB with all of the images I added in spriteBuilder.

CodyMace
  • 646
  • 1
  • 8
  • 19