CocosSharp game on Android startup takes a long time to draw graphics

105 Views Asked by At

We have a somewhat simple game written using CocosSharp. The game is within another Xamarin.Forms app. When the player clicks to play the game, we bring them to a splash screen. On iOS this screen displays immediately but on Android, the screen is just black for about 15 seconds. The music plays pretty much immediately on both platforms.

The following is called from the ViewCreated event of the CocosSharpView.

InitializeAudio();
var scene = new Scenes.SplashScene(GameView);
GameView.RunWithScene(scene);

The hang up seems to be when creating labels. The following take ~10 seconds to complete with 99% of it being in the constructor of the first label. We call our CreateText in the constructor.

    private void CreateText()
    {
        var label = new CCLabel("Text 1", "BD_CARTOON_SHOUT.TTF", 80)
        {
            PositionX = layer.ContentSize.Width / 2.0f,
            PositionY = layer.ContentSize.Height / 1.5f,
            Color = CCColor3B.DarkGray
        };
        layer.AddChild(label);

        label = new CCLabel("Text 2", "BD_CARTOON_SHOUT.TTF", 60)            
        {
            PositionX = layer.ContentSize.Width / 2.0f,
            PositionY = 50f,
            Color = CCColor3B.DarkGray
        };

        layer.AddChild(label);
    }

Keep in mind this only happens on Android. Thanks in advance!

1

There are 1 best solutions below

0
Timo Krajci On

I had the same issue several weeks ago. The problem was CCLabel constructor where it didn't know which type of font are you using and therefore trying all other types before finally trying the last one which is correct. You need to specify font type in CCLabel constructor like this:

    var label = new CCLabel("Text 1", "BD_CARTOON_SHOUT.TTF", 80, CCLabelFormat.SystemFont);


Hope it helps.