1

I try to write a splash screen in my first cocossharp game as write splash in android application. However, it show a black screen and then directly goto gameplayscene. So what should I change? Thank you very much!

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 ();
    }
}
Coroner_Rex
  • 323
  • 4
  • 17

1 Answers1

1

The game loop must be running for, well, any game framework to display and update. Calls to Thread.Sleep pause the execution of the thread.

If you want to display a splash screen for an interval the best way would be to simply create the splash scene as you are, and then schedule an action sequence

Something like this will wait for 2s, then remove the splashLayer and go to the game scene.

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