Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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. –  jubin Jan 13 '12 at 11:46
    
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 –  Gustavo Maciel Jan 13 '12 at 22:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.