选择要运行的CCScene

时间:2014-05-28 09:05:18

标签: c++ ios cocos2d-x

我是Cocos2Dx的新手。我试图制作一款有3-4种模式的游戏。我使用UIKit(iOS特定代码)创建了菜单。现在我需要调用相应的CCScene类。我已经单独实施了它们。但我不知道如何呈现它们。

button1按我执行以下操作:

    // Add the view controller's view to the window and display.
    _window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];

    // Init the EAGLView
    EAGLView *__glView = [EAGLView viewWithFrame: [_window bounds]
                                     pixelFormat: kEAGLColorFormatRGB565
                                     depthFormat: GL_DEPTH24_STENCIL8_OES
                              preserveBackbuffer: NO
                                      sharegroup: nil
                                   multiSampling: NO
                                 numberOfSamples: 0];

    [__glView setMultipleTouchEnabled:YES];

    // Use RootViewController manage EAGLView
    _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    _viewController.wantsFullScreenLayout = YES;
    _viewController.view = __glView;

    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        // warning: addSubView doesn't work on iOS6
        [_window addSubview: _viewController.view];
    }
    else
    {
        // use this method on ios6
        [_window setRootViewController:_viewController];
    }

    [_window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden:true];

    cocos2d::CCApplication::sharedApplication()->run();

此转换调用AppDelegate.cpp并呈现游戏的模式1,如下所示:

    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // turn on display FPS

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    // create a scene. it's an autorelease object
    CCScene *pScene = ClassicModeLayer::scene();

    // run
    pDirector->runWithScene(pScene);

此处模式一被称为ClassicMode。现在如何按button2并为街机模式或其他模式调用另一个CCScene?如何将按钮按下事件传递给AppDelegate.cpp

1 个答案:

答案 0 :(得分:0)

为什么不通过cocos2dx添加模式选择屏幕,即CCScene本身,

首先添加模式选择场景,然后根据所选模式加载场景。