RSS

e) Intro

I’d consider an intro to be a start up splash screen (or screens), a little welcome animation or message, or anything really that just plays once at the start of the game.

Let’s look at the module flow diagram from the docs:

We’ve already defined AppModules for the main menu and the game, but as you can see that’s just two from a possible six.  Now it’s time to define one for the intro…

Download Part 3 of the project code and see file “1 - intro.bmx”

Our new type

This should be familiar by now..  A create function to create an object and initialise it with the framework and Update, Draw and FadeOutComplete methods.  Let’s go over it in detail:

Type intro Extends AppModule
    Field drawCaption:Int = false
    Field anim:Animator

First some fields to handle our animations.  The plan is to bounce the main logo onto the screen with a “tada” sound.  When the bounce is complete we’ll add the caption image in a burst of particles and play a “ding” sound.  Well, that’s the plan..

A standard create function that defines the object as an APP_INTRO:

    Function Create ( resourceFile:String )
        Local i:intro = New intro
        i.Initialise( resourceFile, APP_INTRO )
    End Function

A start method where, as usual, we can initialise our stuff:

    Method Start()
        Super.Start()
        ‘ create an animator that will bounce our logo
        anim = Animator.CreateBounce( -60, 0, 240, 0.35, 25.0, True )
        ‘ pause for a second here, not in the main menu
        Delay(1000)
        ‘ play the tada sound
        PlaySoundByName( “tada” )
    End Method

Here we’ve created a bounce animator to attach to our logo and we’ve moved the delay from the main menu type to this intro and played the “tada” sound.  The delay of 1 second may be a little excessive, especially in windowed mode, but in fullscreen it often takes monitors to adjust to the change in screen resoultion and without it, you may find most of the intro is played before the monitor wakes up!

The FadeOutComplete method is the same as before where we just end the module.

    Method FadeOutComplete()
        EndModule()
    End Method 

The update function has some simple logic to process:

  • While the animator has not expired, continue to update it and assign it’s current value to the Y position of the logo image.
  • As soon as the animator does expire, play a “ding” sound, allow the caption sprite to be drawn, and do a particle burst at the caption position.
  • Once the caption is on screen and all the particles have died away, we can fade out this module.  We can also fade it out if the user presses escape.

Here’s the method in full.

    Method Update( timeMS:Int )
        Super.Update( timeMS )
        ‘ Update the bounce
        If ( Not anim.HasExpired() )
            anim.Update( timeMS )
            GetSprite( “logo” ).SetPosition( 200, anim.Value() )
            If ( anim.HasExpired() )
                ‘ now the bounce has expired, lets spawn the caption image
                ‘ with some particles…
                PlaySoundByName( “ding” )
                GetSprite( “caption” ).SetPosition( 450, 235 )
                GetEmitter( “burst” ).DoBurst( 520, 240 )
                drawCaption = True 
            End If 
        End If             
        ‘ check if the module should start fading away..
        If ( Not IsFading() ) ‘ (not already fading!)
            If ( ( GetEmitter( “burst” ).liveCount() = 0 And drawCaption = True ) Or KeyHit( KEY_ESCAPE ) )
                ‘ basically we wait for all the particles to die or if the player hits escape
                StartFadeOut()
            End If 
        End If 
    End Method

And finally a Draw method.  It just draws the logo sprite, the caption sprite if it’s allowed and it draws the particle emitters.

    Method Draw()
        GetSprite( “logo” ).Draw()
        If ( drawCaption ) GetSprite( “caption” ).Draw()
        DrawParticleEmitters()
        Super.Draw()    
    End Method

And that’s it for the intro type!  We need to create an intro object during our application init code (around the point where we create the main menu), so we’ll add a create call;

intro.Create( “Media/introResources.txt” )

If you care to look in Main/introResources.txt you’ll see the SPRITE’s, SOUND’s and particle EMITTER defined that we’ve just used:

(sounds are courtesy of www.freesound.org)

SOUND tada = Media/sounds/60443__jobro__tada1-ed.wav
SOUND ding = Media/sounds/26874__cfork__cf_FX_batch_jingle_glock_N_kling.wav

SPRITE logo = Media/images/logo.png
SPRITE caption = Media/images/caption.png

EMITTER burst = Media/Emitters/littleburst.txt

And that’s it!  Check out and run the sample.

The order the modules are created at startup doesn’t affect the flow of the application.  When creating a module very little action is taken, other than remembering what the module type is for, and the filename of its list of resources.  It’s only when the application passes control to the module that it does it any resource loading.

On to the final step: Adding an exit screen

Comments are closed.