Converting Cocos2d-iphone to Cocos2d-x

Hi everybody,

I have a code that I get from the book “Learn Cocos2d Game Development with iOS5” by Steffen Itterheim | Rob Low

I use the idea for the LoadingScene, I like so much and nw want to use it in Cocos2d-x.

But I’m new to C++ and want a help to convert the following code:


#import 
#import "cocos2d.h"

typedef enum
{
    TargetSceneINVALID = 0,
    TargetSceneMainMenuScene,
    TargetSceneGameScene,
    TargetSceneTestScene,
    TargetSceneRecordScene,
    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

---------------------------------------------------------------------------------------------

@interface LoadingScene (PrivateMethods)
-(void) update:(ccTime)delta;
@end

@implementation LoadingScene

+(id) sceneWithTargetScene:(TargetScenes)targetScene;
{
    return [[[self alloc] initWithTargetScene:targetScene] autorelease];
}


-(id) initWithTargetScene:(TargetScenes)targetScene
{
    if ((self = [super init]))
    {
        targetScene_ = targetScene;

        [self scheduleUpdate];
    }

    return self;
}

-(void) update:(ccTime)delta
{
    [self unscheduleAllSelectors];
    switch (targetScene_)
    {
        case TargetSceneMainMenuScene:
            [[CCDirector sharedDirector] replaceScene:[MainMenuScene scene]];
            break;

        case TargetSceneGameScene:
            [[CCDirector sharedDirector] replaceScene:[GameScene scene]];
            break;

        case TargetSceneTestScene:
            [[CCDirector sharedDirector] replaceScene:[TestScene scene]];
            break;

        case TargetSceneRecordScene:
            [[CCDirector sharedDirector] replaceScene:[RecordsScene scene]];
            break;

        default:
            NSAssert2(nil, @"%@: unsupported TargetScene %i", NSStringFromSelector(_cmd), targetScene_);
            break;
    }   
}

If you just want to convert, you can have a look at Stella SDK

Or you can try script, which I wrote while translating “cocos2d cookbook receipts” book: