启动画面不适用于Cocossharp游戏

时间:2015-09-16 05:22:39

标签: c# xamarin cocos2d-x cocos2d-android cocossharp

我试着在我的第一个cocossharp游戏中写一个启动画面,因为在android应用程序中写了一下。然而,它显示黑屏然后直接转到gameplayscene。那么我应该改变什么呢?非常感谢你!

public class SplashScene : CCScene
{
    CCSprite splashImage1;
    CCSprite splashImage2;
    CCLayer splashLayer;

    public SplashScene (CCWindow mainWindow) : base(mainWindow)
    {
        splashLayer = new CCLayer ();
        this.AddChild (splashLayer);

        splashImage1 = new CCSprite ("Splash1");
        splashImage1.Position = ContentSize.Center;
        splashImage1.IsAntialiased = false;

        splashImage2 = new CCSprite ("Splash2");
        splashImage2.Position = ContentSize.Center;
        splashImage2.IsAntialiased = false;
    }

    public void PerformSplash()
    {
        splashLayer.AddChild (splashImage1);
        Thread.Sleep(3000);
        splashLayer.RemoveChild(splashImage1);

        splashLayer.AddChild (splashImage2);
        Thread.Sleep(2000);
        splashLayer.RemoveChild (splashImage2);

        GameAppDelegate.GoToGameScene ();
    }
}

1 个答案:

答案 0 :(得分:1)

游戏循环必须运行,以及任何要显示和更新的游戏框架。调用Thread.Sleep暂停执行该线程。

如果要在一段时间内显示启动画面,最好的方法是简单地按原样创建启动场景,然后安排一个动作序列

这样的东西会等待2秒,然后移除splashLayer并转到游戏场景。

auto seq = Sequence::create(
  DelayTime::create(2.0),
  CallFunc::create([=](){
    splashLayer->removeFromParent();
    GameAppDelegate.GoToGameScene();
  }),
  nullptr);
runAction(seq);