Change the android black screen on start?

I’m using cocos2d-x v3.6 and when I run my game on android it shows a black screen for 3 to 4 seconds before starting the game.

I made a splash class to show a splash screen on start -

Splash.h:

#pragma once
#include "cocos2d.h"
#include "SplitMain.h"
class Splash : public cocos2d::Scene
{
public:
    virtual bool init();
    CREATE_FUNC(Splash);
    virtual void onEnter();
};

Splash.cpp:

#include "Splash.h"
USING_NS_CC;

bool Splash::init()
{
    if ( !Scene::init() ){
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    auto splashScreen=Sprite::create("splash.png");
    splashScreen->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height/2));
    this->addChild(splashScreen);
    return true;
}
void Splash::onEnter(){
    auto scene = SplitMain::create();
    Director::getInstance()->replaceScene(TransitionCrossFade::create(1,scene));
}

But it still shows the black screen for 3-4 seconds, followed by the splash which is immediately transitioned.

I tried removing the onEnter function so that it would just load the splash scene but it still showed the black screen first.

Is there anyway to display my splash screen in place of the black screen?

1 Like

What device are you using?

The device is Samsung Galaxy GT-S5570 and I am getting the same problem on bluestacks as well.

I have made a custom style for android and added the line

 <item name="android:windowBackground">@drawable/splash</item>

to it and it loads the splash image upon starting but it still has two problems -

  • The image gets stretched due to resizing.
  • Even after the image is shown, the screen goes black for two seconds before the game is started.
1 Like

@i__d__k Hey, did you find a solution for this? I am exactly stuck with the same problem (and same android device, although it happens on every android device I’ve tested, but S-5570 is especially slow and annoying). I’ve been all the day looking for information and I am surprised that this simple problem isn’t solved anywhere.

I could not find any solution and I ended up removing the custom style as it was not helpful at all.

The app starts up much much quicker on faster devices like Note 2 or Moto G. Also, every other app takes that much time to load on my Galaxy GT-S5570 so I think it’s just a processor thing and we can’t do anything about it.

The only thing you can do is change the colour that shows while the app is loading (some apps like Duolingo have it white) by using a custom style. If you use an image it will be distorted on different devices.

That is sad to hear. And to think how easy it is on iOS (just drag an image to a Xcode property). At least did you manage to maintain the style or colour until the game loads? Because all I could achieve is to change the colour at the beginning, but it quickly changes to black again, and after some seconds the game starts.

Anyway, thank you very much for responding :smile:

I’ve never worked with iOS so I can’t say, but I guess it’s easier on iOS because of the limited number of devices as compared to android.

I did not change the colour for my game, it’s just something that I noticed that other apps do.
How did you do the colour change?

I have a styles.xml file in the res/values folder with these contents:

<?xml version="1.0" encoding="utf-8"?>
<resources>
	<color name="custom_theme_color">#ffffff</color>
	<style name="CustomTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
	    <item name="android:windowBackground">@color/custom_theme_color</item>
	    <item name="android:colorBackground">@color/custom_theme_color</item>
	</style>
</resources>

Then, on the manifest:

<application android:label="@string/app_name"
	     android:theme="@style/CustomTheme" <- This line
             android:icon="@drawable/icon">

... (the rest of the manifest file)

But the problem is that the color is displayed a very short period of time, and then it turns into black, and some seconds after the game appears.

I still can’t believe there is no “official” or easy way of doing a simple initial splash. All the examples I saw on this or other forums and webpages consist of a splash which then turns into the infamous black screen and then the game loads. All I want is to load the game while the splash image is on screen :pensive:

I found this, it might help.

I think making a Java activity for splash is the only solution.

Thanks! I saw that post some time ago, but I found it quite complex… I suppose that I’ll take a look if there is no other option.

You can check out @Fradow’s splash class and main activity. It doesn’t look too hard, and I don’t really know any Java.

Hi, what solution did you end up going with?

Check out this article:

Basically, it makes the GLSurfaceView transparent, and the Android theme background stays visible until the first scene is loaded.

I tested it on My OnePlus One with Lollipop:
The only caveat I can see is a gray row that shows on top of the splash screen after a second.

1 Like

Is there a way to resolve this

1 Like