Game Development Reference
In-Depth Information
Note If you were to uncheck the Scroll View 's Paging enabled property,
numPages will be 0 . Hence, you conduct the test to ensure numPages is
greater than 0 . This prevents a division-by-zero error with paging disabled.
The MIN macro ensures that worldPage is always in the range 0 to numPages - 1
because highestUnlockedLevel may be set to 10 after completing the ninth level.
The resulting worldPage index is then assigned to the Scroll View 's horizont-
alPage index property to have the Scroll View show that particular page. Now if you
have a couple levels and you unlocked the first six levels, you'll immediately see the
second page of the Scroll View as shown in Figure 8-10 .
Figure 8-10 . The level-selection Scroll View in action and showing the second page
Implementing Scroll View Delegate Meth-
ods
There's one last bit to understanding the CCScrollView class. It provides a
CCScrollViewDelegate protocol defining callback methods sent to a delegate if it
implements the protocol methods. There's no real use for it at the moment, but it can't
hurt to implement the protocol methods to see what Scroll View events you can react to.
Still in MainScene.m , you should add the highlighted code of Listing 8-24 to the
didLoadFromCCB method.
Search WWH ::




Custom Search