如何使用typedef enum加载“加载”场景?

时间:2012-05-03 01:34:09

标签: objective-c cocos2d-iphone

我正在读一本书,它向我展示了如何创建一个使用typedef枚举的加载类。

我理解代码并且可以全部阅读。我的问题是我不知道如何实现它。

例如......

接口部分

    typedef enum
                {
                TargetSceneINVALID = 0, 
            TargetSceneFirstScene, 
            TargetSceneOtherScene, 
            TargetSceneMAX,
                } TargetScenes;
                // LoadingScene is derived directly from Scene. We don't need a CCLayer for this scene. 
        @interface LoadingScene : CCScene




           {
            TargetScenes targetScene_;
            }

+(id) sceneWithTargetScene:(TargetScenes)targetScene; 
-(id) initWithTargetScene:(TargetScenes)targetScene;

@end

实施部分

@implementation


    +(id) sceneWithTargetScene:(TargetScenes)targetScene; 
{
    // This creates an autorelease object of the current class
    return [[[self alloc] initWithTargetScene:targetScene] autorelease];
 }
    -(id) initWithTargetScene:(TargetScenes)targetScene 
{
    if ((self = [super init])) 
{
    targetScene_ = targetScene;
    CCLabelTTF* label = [CCLabelTTF labelWithString:@"Loading ..." fontName:@"Marker Felt"
    fontSize:64]; CGSize size = [[CCDirector sharedDirector] winSize];
    label.position = CGPointMake(size.width / 2, size.height / 2); [self addChild:label];
    // Must wait one frame before loading the target scene!
    [self scheduleUpdate]; 
}
    return self;
}


        -(void) update:(ccTime)delta 
    {
        [self unscheduleAllSelectors];
        // Decide which scene to load based on the TargetScenes enum. 
    switch (targetScene_)
        {
        case TargetSceneFirstScene:
        [[CCDirector sharedDirector] replaceScene:[FirstScene scene]]; break;
        case TargetSceneOtherScene:
        [[CCDirector sharedDirector] replaceScene:[OtherScene scene]]; break;
        default:
        // Always warn if an unspecified enum value was used 
NSAssert2(nil, @"%@: unsupported TargetScene %i",

0 个答案:

没有答案