If your game has say 20 levels, it is okay to have one single level selection scene to display all the level buttons; but what if you have more? In this section, we will modify the previous section's code, create a node, and customize the class to create a scrollable level selection scene.
We will create a new class called LevelSelectionLayer
, inherit from CCNode
, and move all the content we added to LevelSelectionScene
to it. This is done so that we can have a separate class and instantiate it as many times as we want in the game.
In the LevelSelectionLayer.m
file, we will change the code to the following:
#import "CCNode.h" @interface LevelSelectionLayer : CCNode { NSMutableArray *buttonSpritesArray; } -(id)initLayerWith:(NSString *)filename StartlevelNumber:(int)lvlNum widthCount:(int)widthCount heightCount:(int)heightCount spacing:(float)spacing; @end
We changed the init
function so that instead of hardcoding the...