1
\$\begingroup\$

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

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks,For helping me it helped me lot i used the CountDownTimer now it is working for me as a splash screen.Thank you soo much for helping me. \$\endgroup\$
    – jubin
    Commented Jan 13, 2012 at 11:46
  • \$\begingroup\$ glad to see it helped you. If so, please do me a favour? "When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer" gamedev.stackexchange.com/faq#howtoask \$\endgroup\$ Commented Jan 13, 2012 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .