0

我不确定如何在线程中正确显示代码,对此我深表歉意。所以我有我的 App Delegate 调用

[director_pushScene:[IntroLayer场景]];

然后我的 introLayer 这样做:

-(void) makeTransition:(ccTime)dt
{
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[MainMenu scene] withColor:ccBLUE]];
}

然后我有 MainMenu.h 和 .m 但它们几乎是空的,除了 .m 有:

@implementation MainMenu

// Helper class method that creates a Scene with the GamePlay as the only child.
+(CCScene *) scene
{
    // 'scene' is an autorelease object.
    CCScene *scene = [CCScene node];

    // 'layer' is an autorelease object.
    MainMenu *layer = [MainMenu node];

    // add layer as a child to scene
    [scene addChild: layer];

    // return the scene
    return scene;
}
@end

然后我有一个使用导航控制器的故事板,当我调用“makeTransition”函数时,我希望开场场景成为主菜单。在我的故事板中,这个主菜单上有一个播放按钮。这个播放按钮被推到另一个“CCViewController”类的视图控制器上。我有 CCViewController.m 和 .h,然后我从中创建了一个名为 cocos2dViewController.m 和 .h 的子类。在我的 cocos2dViewController.m 我调用:

if(director.runningScene)

    [director replaceScene:[GamePlay scene]];

else

    [director pushScene:[GamePlay scene]];

GamePlay.m 和 .h 是我定义我的整个游戏的地方。

因此,当我运行它时,我会看到启动屏幕,然后它会从蓝色过渡到黑色屏幕。这是因为 MainMenu.m 中没有任何内容吗?另外,(我认为)我不应该在 MainMenu.m 中需要任何东西。我只需要某种方式使 MainMenu 场景成为情节提要的初始(主菜单)场景。我觉得我已经很接近让这个工作了,您在这一点上必须提供的任何建议/知识,或者如果您需要更多信息来诊断问题,我们将再次不胜感激。谢谢!

4

1 回答 1

0

当 cocos2d 中没有运行场景时,你应该通过调用来启动一个runScene,而不是replaceScene.

这是你应该尝试改变的第一件事。

另一方面,在我看来,您正试图在 UIKit 视图控制器中显示 cocos2d 场景。这也需要一些小心才能工作。如果您使用的是 cocos2d 2.0,请查看这篇文章以获取一些提示。

于 2012-08-01T17:46:58.147 回答