mono / CocosSharp

CocosSharp is a C# implementation of the Cocos2D and Cocos3D APIs that runs on any platform where MonoGame runs.
492 stars 159 forks source link

Creating CCLabel for the first time on Android takes 10 seconds #417

Open Jbonavita opened 7 years ago

Jbonavita commented 7 years ago

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.8% 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!