Game Development Reference
In-Depth Information
equal to highestUnlockedLevel . You'll also want to launch the GameScene and
load the button's corresponding level file.
Add the highlighted code in Listing 8-8 to MainMenuLevelSelect.m . The code in
didLoadFromCCB will enumerate all buttons to compare each button's level number
with the current highestUnlockedLevel . If the button's level should be unlocked,
the button's parent sprite gets its color set to white, removing the dimming effect caused
by applying a gray color to it in SpriteBuilder.
Listing 8-8 . Level buttons whose level is unlocked should not be grayed out
#import "MainMenuLevelSelect.h"
#import "MainMenuButtons.h"
#import "SceneManager.h"
#import "GameState.h"
@implementation MainMenuLevelSelect
-(void) didLoadFromCCB
{
int count = 1;
int highest = [GameState
sharedGameState].highestUnlockedLevel;
CCNode* button;
while ((button = [self
getChildByName:@(count).stringValue
recursively:YES]))
{
if (button.name.intValue <= highest)
{
CCSprite* sprite = (CCSprite*)button.parent;
sprite.color = [CCColor whiteColor];
}
count++;
}
}
@end
The assignment to the button variable occurs within the while condition. This is legal
and safe to do, but it requires you to use double brackets to prevent the compiler from
complaining—after all, it's a common mistake to use the assignment operator = instead of
Search WWH ::




Custom Search