How to create a splash (loading) screen in cocos2d for Android?
I need a loading screen that shows my app name and after that the next scene will show automatically.
Thanks
Well, for cocos i have no idea. But I've done this with pure OpenGL-ES, I cant tell exactly how, since it depends in your implementation of Scene, your states, your sprite drawing, etc. But here's a pseudo code of how mine looks like:
SplashScreen::load()
{
SetScreenClearColor(White);
LoadTexture(R.drawable.GameLogo);
StaticSprite sprite = new Sprite(R.drawable.GameLogo);
sprite.setPosition(Screen.width / 2 - sprite.width / 2, Screen.height / 2 - sprite.height / 2);
drawables.addToDraw(sprite);
ScreenFader fader = new ScreenFader(White, 2);
fader.setRectangle(0, 0, Screen.width, Screen.height);
drawables.addToDraw(fader);
}
This will load your texture, put the logo in the center of the screen, register it to draw, create a ScreenFader(explain later) with a white color that would take 2 seconds to finsih, make the ScreenFader take the whole screen and register the ScreenFader to draw also.
The ScreenFader look like:
class ScreenFader
{
float curTime;
float endTime;
boolean finished;
Color color;
ScreenFader(Color color, float endTime)
{
//some code to initialize vertices of a quad here
//some code to attach color to vertices
curTime = 0;
this.endTime = endTime;
this.color = color;
}
SetRectangle(int x, int y, int width, int height)
{
//set vertices to match the rectangle that was pass here
}
Update(float deltaTime)
{
if(!finished)
{
curTime += deltaTime;
if(curTime >= endTime)
{
finished = true;
curTime = endTime;
}
color.alpha = curTime / endTime;
}
}
Draw()
{
DrawQuad(vertices, color);
}
}
Thats it. And in your scene update, do this:
SplashScreen::Update(float deltatime)
{
fader.Update(deltatime);
if(fader.finished)
ChangeScene(MainMenu); //Or something like
}
Hope it helps you to think in a way to do this.