Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Splash Screen  (Read 8477 times)

0 Members and 1 Guest are viewing this topic.

Kordman916

  • Newbie
  • *
  • Posts: 9
    • View Profile
Splash Screen
« on: February 04, 2011, 04:17:33 am »
Hey Everyone,

So I was just going through all the things games include and I thought of splash screens.

How would one go about making splash screens?

How would I load the images and have them fade in and out in sequence?

This doesn't seem hard to do but I'm an extreme beginner when it comes to programming.

If there is a project that has source code included that features splash screens please leave a link or something so I can download it and solve this little issue.

Thanks in advance,
Kordman916

Kordman916

  • Newbie
  • *
  • Posts: 9
    • View Profile
Splash Screen
« Reply #1 on: February 04, 2011, 05:05:46 am »
Just to show that I can at least load images I'll post my current code and I hope someone can make an addition showing how to clear the screen and load another image.

Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main()
    {
        //Start the SFML display window
        sf::RenderWindow Splash(sf::VideoMode(1024, 768, 32), "Splash Screen Test 0.1");

        //Load the images for each individual screen (only one for now)
        sf::Image SplashOpenAL;
        if(!SplashOpenAL.LoadFromFile("Data/OpenAL.png"))
            return EXIT_FAILURE;
            sf::Sprite OpenALSprite(SplashOpenAL);

            while (Splash.IsOpened())
            {
                sf::Event Event;
                while (Splash.GetEvent(Event))
                {
                     // Close window : exit
            if (Event.Type == sf::Event::Closed)
                Splash.Close();

            if (Event.Type == sf::Event::KeyPressed)
            {
                // Escape key : exit
                if (Event.Key.Code == sf::Key::Escape)
                    Splash.Close();
                }

                Splash.Clear();
                Splash.Draw(OpenALSprite);
                Splash.Display();
                }
            }
            return EXIT_SUCCESS;
    }


Also how do I scale the sprites and images based on the window size?

Thanks in advance,
Kordman916

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Splash Screen
« Reply #2 on: February 04, 2011, 06:46:52 pm »
As you know already, to show an image you load it and then draw it.  To show a different image, just don't draw the first one anymore and draw the second one instead.  Pseudo-code:
Code: [Select]

sf::Image first, second;
first.LoadFromFile();
second.LoadFromFile();
sf::Sprite firstSprite, secondSprite;
firstSprite.SetImage(first);
secondSprite.SetImage(second);

if (firstNeedsDrawing)
{
    window.Draw(firstSprite);
}
else if (secondNeedsDrawing)
{
   window.Draw(secondSprite);
}


If you want to fade them try changing the color.  sf::Color has 4 values, the last of which controls the transparency.  255 means no transparency, 0 means complete.  So you could just set the fourth argument as a variable and decrease it to make the image more transparent.

Code: [Select]
while(firstNeedsDraw){
firstSprite.SetColor(200, 100, 100, alpha);
window.Draw(first);
alpha -= 10;    //change this to change how quickly it fades.
}


sf::Sprite.SetScale to scale the sprite.