Hello,
On Android, during startup, I have black screen instead of my splash graphic (reproduce rate about 80%).
I set up my splash screen "regular" way, just with style:
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash_background</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
I load all assets in Game.LoadContent() method synchronous way. A piece of code:
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
AudioManager.LoadContent(Content);
SceneManager.LoadScenesContent(Content);
}
So, usually, just for a moment (like a half second) I can see my splash graphic, then black screen (for about 4 seconds), and then my main menu.
I'm fighting with this issue really long time, started digging in Monogame source code but could not help myself. This is critical issue for me. What could lead to such a behavior ? Can I expect cool Monogame team to fix this ?
Verified on Nexus 5 with Android 6
EDIT:
In logcat I can see: Skipped 127 frames ! The application may be doing too much work on its main thread.
Even when I cutted off loading almost of all the assets - left only loading for main menu (some background, buttons, sounds and fonts) ..
I also suffered this issue in my own game but ended up finding a workaround by adding an ImageView set to the same image as the splash, over the top of the game view, which can be removed once the game has begun running/loading.
It's worked really well so far. Using the Android example/template as a base here, I changed:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var g = new Game1();
SetContentView((View)g.Services.GetService(typeof(View)));
g.Run();
}
To:
FrameLayout layout;
View splashView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var g = new Game1();
g.OnLoadingContent += G_OnLoadingContent;
layout = new FrameLayout(this.ApplicationContext);
layout.AddView((View)g.Services.GetService(typeof(View)));
// Use the splash screen image to cover up the black/blank screen while Android/MonoGame finish initializing.
// "splash" should be set to the name of your splash screen image
int id = Resources.GetIdentifier("splash", "drawable", PackageName);
splashView = new ImageView(this.ApplicationContext);
splashView.SetBackgroundResource(id);
layout.AddView(splashView);
SetContentView(layout);
g.Run();
}
private void G_OnLoadingContent(object sender, System.EventArgs e)
{
layout.RemoveView(splashView);
}
I also added an event to fire off when the game starts loading its content so it can signal back to the activity that it's safe to remove the extra splash image, which was added during OnCreate, otherwise it'll continue to hide the game behind it.
``csharp
/// <summary>Something to subscribe to in our main activity. </summary>
public event EventHandler OnLoadingContent;
` ///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
OnLoadingContent?.Invoke(this, new EventArgs());
}
````
I'm unsure if its actually a MonoGame issue and more along the lines of Xamarin taking its time to fully initialize before MonoGame starts running.
Perhaps something based on the above code can somehow be integrated into the AndroidGameActivity so that it doesn't need to be done for every new Android game, even if its only temporary to get rid of the black screen until something better comes along.
If anyone has a better way of masking the black screen, I'd be interested to hear it!
Thank you so much, this issue has been bothering me for so long!
Most helpful comment
I also suffered this issue in my own game but ended up finding a workaround by adding an ImageView set to the same image as the splash, over the top of the game view, which can be removed once the game has begun running/loading.
It's worked really well so far. Using the Android example/template as a base here, I changed:
To:
I also added an event to fire off when the game starts loading its content so it can signal back to the activity that it's safe to remove the extra splash image, which was added during OnCreate, otherwise it'll continue to hide the game behind it.
``
csharp /// <summary>Something to subscribe to in our main activity. </summary> public event EventHandler OnLoadingContent;` ///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
````
I'm unsure if its actually a MonoGame issue and more along the lines of Xamarin taking its time to fully initialize before MonoGame starts running.
Perhaps something based on the above code can somehow be integrated into the AndroidGameActivity so that it doesn't need to be done for every new Android game, even if its only temporary to get rid of the black screen until something better comes along.
If anyone has a better way of masking the black screen, I'd be interested to hear it!